Skip to content

Commit 54f75ca

Browse files
committed
Use "rhs" terminology instead of "body"
1 parent 1e02824 commit 54f75ca

File tree

9 files changed

+41
-56
lines changed

9 files changed

+41
-56
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3746,7 +3746,7 @@ pub struct ConstItem {
37463746
pub ident: Ident,
37473747
pub generics: Generics,
37483748
pub ty: Box<Ty>,
3749-
pub body: Option<ConstItemRhs>,
3749+
pub rhs: Option<ConstItemRhs>,
37503750
pub define_opaque: Option<ThinVec<(NodeId, Path)>>,
37513751
}
37523752

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
184184
hir::ItemKind::Static(*m, ident, ty, body_id)
185185
}
186186
ItemKind::Const(box ast::ConstItem {
187-
ident,
188-
generics,
189-
ty,
190-
body,
191-
define_opaque,
192-
..
187+
ident, generics, ty, rhs, define_opaque, ..
193188
}) => {
194189
let ident = self.lower_ident(*ident);
195190
let (generics, (ty, body)) = self.lower_generics(
@@ -199,8 +194,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
199194
|this| {
200195
let ty = this
201196
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
202-
let body = this.lower_const_item_rhs(attrs, body.as_ref(), span);
203-
(ty, body)
197+
let rhs = this.lower_const_item_rhs(attrs, rhs.as_ref(), span);
198+
(ty, rhs)
204199
},
205200
);
206201
self.lower_define_opaque(hir_id, &define_opaque);
@@ -797,12 +792,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
797792

798793
let (ident, generics, kind, has_default) = match &i.kind {
799794
AssocItemKind::Const(box ConstItem {
800-
ident,
801-
generics,
802-
ty,
803-
body,
804-
define_opaque,
805-
..
795+
ident, generics, ty, rhs, define_opaque, ..
806796
}) => {
807797
let (generics, kind) = self.lower_generics(
808798
generics,
@@ -811,15 +801,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
811801
|this| {
812802
let ty = this
813803
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
814-
let body = body
804+
let rhs = rhs
815805
.as_ref()
816806
.map(|body| this.lower_const_item_rhs(attrs, Some(body), i.span));
817-
hir::TraitItemKind::Const(ty, body)
807+
hir::TraitItemKind::Const(ty, rhs)
818808
},
819809
);
820810

821811
if define_opaque.is_some() {
822-
if body.is_some() {
812+
if rhs.is_some() {
823813
self.lower_define_opaque(hir_id, &define_opaque);
824814
} else {
825815
self.dcx().span_err(
@@ -829,7 +819,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
829819
}
830820
}
831821

832-
(*ident, generics, kind, body.is_some())
822+
(*ident, generics, kind, rhs.is_some())
833823
}
834824
AssocItemKind::Fn(box Fn {
835825
sig, ident, generics, body: None, define_opaque, ..
@@ -1016,12 +1006,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10161006

10171007
let (ident, (generics, kind)) = match &i.kind {
10181008
AssocItemKind::Const(box ConstItem {
1019-
ident,
1020-
generics,
1021-
ty,
1022-
body,
1023-
define_opaque,
1024-
..
1009+
ident, generics, ty, rhs, define_opaque, ..
10251010
}) => (
10261011
*ident,
10271012
self.lower_generics(
@@ -1032,7 +1017,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10321017
let ty = this
10331018
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
10341019
this.lower_define_opaque(hir_id, &define_opaque);
1035-
let body = this.lower_const_item_rhs(attrs, body.as_ref(), i.span);
1020+
let body = this.lower_const_item_rhs(attrs, rhs.as_ref(), i.span);
10361021
hir::ImplItemKind::Const(ty, body)
10371022
},
10381023
),

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,9 +1239,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12391239
}
12401240
});
12411241
}
1242-
ItemKind::Const(box ConstItem { defaultness, body, .. }) => {
1242+
ItemKind::Const(box ConstItem { defaultness, rhs, .. }) => {
12431243
self.check_defaultness(item.span, *defaultness);
1244-
if body.is_none() {
1244+
if rhs.is_none() {
12451245
self.dcx().emit_err(errors::ConstWithoutBody {
12461246
span: item.span,
12471247
replace_span: self.ending_semi_or_hi(item.span),
@@ -1581,7 +1581,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15811581

15821582
if let AssocCtxt::Impl { .. } = ctxt {
15831583
match &item.kind {
1584-
AssocItemKind::Const(box ConstItem { body: None, .. }) => {
1584+
AssocItemKind::Const(box ConstItem { rhs: None, .. }) => {
15851585
self.dcx().emit_err(errors::AssocConstWithoutBody {
15861586
span: item.span,
15871587
replace_span: self.ending_semi_or_hi(item.span),

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ impl<'a> State<'a> {
210210
ident,
211211
generics,
212212
ty,
213-
body,
213+
rhs,
214214
define_opaque,
215215
}) => {
216216
self.print_item_const(
217217
*ident,
218218
None,
219219
generics,
220220
ty,
221-
body.as_ref().map(|ct| ct.expr()),
221+
rhs.as_ref().map(|ct| ct.expr()),
222222
&item.vis,
223223
ast::Safety::Default,
224224
*defaultness,
@@ -566,15 +566,15 @@ impl<'a> State<'a> {
566566
ident,
567567
generics,
568568
ty,
569-
body,
569+
rhs,
570570
define_opaque,
571571
}) => {
572572
self.print_item_const(
573573
*ident,
574574
None,
575575
generics,
576576
ty,
577-
body.as_ref().map(|ct| ct.expr()),
577+
rhs.as_ref().map(|ct| ct.expr()),
578578
vis,
579579
ast::Safety::Default,
580580
*defaultness,

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub(crate) fn expand_test_or_bench(
289289
ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
290290
define_opaque: None,
291291
// test::TestDescAndFn {
292-
body: Some(ast::ConstItemRhs::Body(
292+
rhs: Some(ast::ConstItemRhs::Body(
293293
cx.expr_struct(
294294
sp,
295295
test_path("TestDescAndFn"),

compiler/rustc_expand/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ impl<'a> ExtCtxt<'a> {
726726
span: Span,
727727
ident: Ident,
728728
ty: Box<ast::Ty>,
729-
body: ast::ConstItemRhs,
729+
rhs: ast::ConstItemRhs,
730730
) -> Box<ast::Item> {
731731
let defaultness = ast::Defaultness::Final;
732732
self.item(
@@ -739,7 +739,7 @@ impl<'a> ExtCtxt<'a> {
739739
// FIXME(generic_const_items): Pass the generics as a parameter.
740740
generics: ast::Generics::default(),
741741
ty,
742-
body: Some(body),
742+
rhs: Some(rhs),
743743
define_opaque: None,
744744
}
745745
.into(),

compiler/rustc_lint/src/unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,8 @@ trait UnusedDelimLint {
10321032
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
10331033
use ast::ItemKind::*;
10341034

1035-
let expr = if let Const(box ast::ConstItem { body: Some(body), .. }) = &item.kind {
1036-
body.expr()
1035+
let expr = if let Const(box ast::ConstItem { rhs: Some(rhs), .. }) = &item.kind {
1036+
rhs.expr()
10371037
} else if let Static(box ast::StaticItem { expr: Some(expr), .. }) = &item.kind {
10381038
expr
10391039
} else {

compiler/rustc_parse/src/parser/item.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ impl<'a> Parser<'a> {
257257
} else {
258258
self.recover_const_mut(const_span);
259259
self.recover_missing_kw_before_item()?;
260-
let (ident, generics, ty, body) = self.parse_const_item(attrs)?;
260+
let (ident, generics, ty, rhs) = self.parse_const_item(attrs)?;
261261
ItemKind::Const(Box::new(ConstItem {
262262
defaultness: def_(),
263263
ident,
264264
generics,
265265
ty,
266-
body,
266+
rhs,
267267
define_opaque: None,
268268
}))
269269
}
@@ -1012,13 +1012,13 @@ impl<'a> Parser<'a> {
10121012
define_opaque,
10131013
}) => {
10141014
self.dcx().emit_err(errors::AssociatedStaticItemNotAllowed { span });
1015-
let body = expr.map(ConstItemRhs::Body);
1015+
let rhs = expr.map(ConstItemRhs::Body);
10161016
AssocItemKind::Const(Box::new(ConstItem {
10171017
defaultness: Defaultness::Final,
10181018
ident,
10191019
generics: Generics::default(),
10201020
ty,
1021-
body,
1021+
rhs,
10221022
define_opaque,
10231023
}))
10241024
}
@@ -1252,7 +1252,7 @@ impl<'a> Parser<'a> {
12521252
let kind = match ForeignItemKind::try_from(kind) {
12531253
Ok(kind) => kind,
12541254
Err(kind) => match kind {
1255-
ItemKind::Const(box ConstItem { ident, ty, body, .. }) => {
1255+
ItemKind::Const(box ConstItem { ident, ty, rhs, .. }) => {
12561256
let const_span = Some(span.with_hi(ident.span.lo()))
12571257
.filter(|span| span.can_be_used_for_suggestions());
12581258
self.dcx().emit_err(errors::ExternItemCannotBeConst {
@@ -1263,7 +1263,7 @@ impl<'a> Parser<'a> {
12631263
ident,
12641264
ty,
12651265
mutability: Mutability::Not,
1266-
expr: body.map(|b| match b {
1266+
expr: rhs.map(|b| match b {
12671267
ConstItemRhs::TypeConst(anon_const) => anon_const.value,
12681268
ConstItemRhs::Body(expr) => expr,
12691269
}),
@@ -1465,7 +1465,7 @@ impl<'a> Parser<'a> {
14651465
let before_where_clause =
14661466
if self.may_recover() { self.parse_where_clause()? } else { WhereClause::default() };
14671467

1468-
let body = if self.eat(exp!(Eq)) {
1468+
let rhs = if self.eat(exp!(Eq)) {
14691469
if attr::contains_name(attrs, sym::type_const) {
14701470
Some(ConstItemRhs::TypeConst(self.parse_expr_anon_const()?))
14711471
} else {
@@ -1481,18 +1481,18 @@ impl<'a> Parser<'a> {
14811481
// Users may be tempted to write such code if they are still used to the deprecated
14821482
// where-clause location on type aliases and associated types. See also #89122.
14831483
if before_where_clause.has_where_token
1484-
&& let Some(body) = &body
1484+
&& let Some(rhs) = &rhs
14851485
{
14861486
self.dcx().emit_err(errors::WhereClauseBeforeConstBody {
14871487
span: before_where_clause.span,
14881488
name: ident.span,
1489-
body: body.span(),
1489+
body: rhs.span(),
14901490
sugg: if !after_where_clause.has_where_token {
1491-
self.psess.source_map().span_to_snippet(body.span()).ok().map(|body_s| {
1491+
self.psess.source_map().span_to_snippet(rhs.span()).ok().map(|body_s| {
14921492
errors::WhereClauseBeforeConstBodySugg {
14931493
left: before_where_clause.span.shrink_to_lo(),
14941494
snippet: body_s,
1495-
right: before_where_clause.span.shrink_to_hi().to(body.span()),
1495+
right: before_where_clause.span.shrink_to_hi().to(rhs.span()),
14961496
}
14971497
})
14981498
} else {
@@ -1530,7 +1530,7 @@ impl<'a> Parser<'a> {
15301530

15311531
self.expect_semi()?;
15321532

1533-
Ok((ident, generics, ty, body))
1533+
Ok((ident, generics, ty, rhs))
15341534
}
15351535

15361536
/// We were supposed to parse `":" $ty` but the `:` or the type was missing.

compiler/rustc_resolve/src/late.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
27092709
ident,
27102710
ref generics,
27112711
ref ty,
2712-
ref body,
2712+
ref rhs,
27132713
ref define_opaque,
27142714
..
27152715
}) => {
@@ -2734,7 +2734,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
27342734
|this| this.visit_ty(ty),
27352735
);
27362736

2737-
if let Some(body) = body {
2737+
if let Some(body) = rhs {
27382738
this.resolve_const_item_rhs(
27392739
body,
27402740
Some((ident, ConstantItemKind::Const)),
@@ -3056,7 +3056,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
30563056
AssocItemKind::Const(box ast::ConstItem {
30573057
generics,
30583058
ty,
3059-
body,
3059+
rhs,
30603060
define_opaque,
30613061
..
30623062
}) => {
@@ -3078,7 +3078,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
30783078

30793079
// Only impose the restrictions of `ConstRibKind` for an
30803080
// actual constant expression in a provided default.
3081-
if let Some(body) = body {
3081+
if let Some(body) = rhs {
30823082
// We allow arbitrary const expressions inside of associated consts,
30833083
// even if they are potentially not const evaluatable.
30843084
//
@@ -3261,7 +3261,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32613261
ident,
32623262
generics,
32633263
ty,
3264-
body,
3264+
rhs,
32653265
define_opaque,
32663266
..
32673267
}) => {
@@ -3303,7 +3303,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
33033303

33043304
this.visit_generics(generics);
33053305
this.visit_ty(ty);
3306-
if let Some(body) = body {
3306+
if let Some(body) = rhs {
33073307
// We allow arbitrary const expressions inside of associated consts,
33083308
// even if they are potentially not const evaluatable.
33093309
//

0 commit comments

Comments
 (0)