Skip to content

Commit 4dc46f7

Browse files
committed
put hir::AnonConst on the hir arena
1 parent e7da0fa commit 4dc46f7

File tree

11 files changed

+47
-41
lines changed

11 files changed

+47
-41
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
375375
}
376376
}
377377

378-
fn visit_array_length(&mut self, len: &'hir ArrayLen) {
378+
fn visit_array_length(&mut self, len: &'hir ArrayLen<'hir>) {
379379
match len {
380380
ArrayLen::Infer(inf) => self.insert(inf.span, inf.hir_id, Node::ArrayLenInfer(inf)),
381381
ArrayLen::Body(..) => intravisit::walk_array_len(self, len),

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,11 +1588,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
15881588
}),
15891589
)),
15901590
)),
1591-
default: Some(hir::AnonConst {
1591+
default: Some(self.arena.alloc(hir::AnonConst {
15921592
def_id: anon_const,
15931593
hir_id: const_id,
15941594
body: const_body,
1595-
}),
1595+
})),
15961596
is_host_effect: true,
15971597
},
15981598
colon_span: None,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,10 +1181,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11811181
tokens: None,
11821182
};
11831183

1184-
let ct = self.with_new_scopes(span, |this| hir::AnonConst {
1185-
def_id,
1186-
hir_id: this.lower_node_id(node_id),
1187-
body: this.lower_const_body(path_expr.span, Some(&path_expr)),
1184+
let ct = self.with_new_scopes(span, |this| {
1185+
self.arena.alloc(hir::AnonConst {
1186+
def_id,
1187+
hir_id: this.lower_node_id(node_id),
1188+
body: this
1189+
.lower_const_body(path_expr.span, Some(&path_expr)),
1190+
})
11881191
});
11891192
return GenericArg::Const(ConstArg {
11901193
value: ct,
@@ -2318,7 +2321,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23182321
}
23192322

23202323
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
2321-
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen {
2324+
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen<'hir> {
23222325
match c.value.kind {
23232326
ExprKind::Underscore => {
23242327
if self.tcx.features().generic_arg_infer {
@@ -2341,12 +2344,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23412344
}
23422345
}
23432346

2344-
fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
2345-
self.with_new_scopes(c.value.span, |this| hir::AnonConst {
2347+
fn lower_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2348+
self.arena.alloc(self.with_new_scopes(c.value.span, |this| hir::AnonConst {
23462349
def_id: this.local_def_id(c.id),
23472350
hir_id: this.lower_node_id(c.id),
23482351
body: this.lower_const_body(c.value.span, Some(&c.value)),
2349-
})
2352+
}))
23502353
}
23512354

23522355
fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
@@ -2653,7 +2656,7 @@ impl<'hir> GenericArgsCtor<'hir> {
26532656

26542657
lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
26552658
self.args.push(hir::GenericArg::Const(hir::ConstArg {
2656-
value: hir::AnonConst { def_id, hir_id, body },
2659+
value: lcx.arena.alloc(hir::AnonConst { def_id, hir_id, body }),
26572660
span,
26582661
is_desugared_from_effects: true,
26592662
}))

compiler/rustc_hir/src/hir.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ impl<'hir> PathSegment<'hir> {
230230
}
231231

232232
#[derive(Clone, Copy, Debug, HashStable_Generic)]
233-
pub struct ConstArg {
234-
pub value: AnonConst,
233+
pub struct ConstArg<'hir> {
234+
pub value: &'hir AnonConst,
235235
pub span: Span,
236236
/// Indicates whether this comes from a `~const` desugaring.
237237
pub is_desugared_from_effects: bool,
@@ -253,7 +253,7 @@ impl InferArg {
253253
pub enum GenericArg<'hir> {
254254
Lifetime(&'hir Lifetime),
255255
Type(&'hir Ty<'hir>),
256-
Const(ConstArg),
256+
Const(ConstArg<'hir>),
257257
Infer(InferArg),
258258
}
259259

@@ -491,7 +491,7 @@ pub enum GenericParamKind<'hir> {
491491
Const {
492492
ty: &'hir Ty<'hir>,
493493
/// Optional default value for the const generic param
494-
default: Option<AnonConst>,
494+
default: Option<&'hir AnonConst>,
495495
is_host_effect: bool,
496496
},
497497
}
@@ -1563,12 +1563,12 @@ impl fmt::Display for ConstContext {
15631563
pub type Lit = Spanned<LitKind>;
15641564

15651565
#[derive(Copy, Clone, Debug, HashStable_Generic)]
1566-
pub enum ArrayLen {
1566+
pub enum ArrayLen<'hir> {
15671567
Infer(InferArg),
1568-
Body(AnonConst),
1568+
Body(&'hir AnonConst),
15691569
}
15701570

1571-
impl ArrayLen {
1571+
impl ArrayLen<'_> {
15721572
pub fn hir_id(&self) -> HirId {
15731573
match self {
15741574
ArrayLen::Infer(InferArg { hir_id, .. }) | ArrayLen::Body(AnonConst { hir_id, .. }) => {
@@ -1965,7 +1965,7 @@ pub enum ExprKind<'hir> {
19651965
///
19661966
/// E.g., `[1; 5]`. The first expression is the element
19671967
/// to be repeated; the second is the number of times to repeat it.
1968-
Repeat(&'hir Expr<'hir>, ArrayLen),
1968+
Repeat(&'hir Expr<'hir>, ArrayLen<'hir>),
19691969

19701970
/// A suspension point for coroutines (i.e., `yield <expr>`).
19711971
Yield(&'hir Expr<'hir>, YieldSource),
@@ -2345,7 +2345,7 @@ pub struct TypeBinding<'hir> {
23452345
#[derive(Debug, Clone, Copy, HashStable_Generic)]
23462346
pub enum Term<'hir> {
23472347
Ty(&'hir Ty<'hir>),
2348-
Const(AnonConst),
2348+
Const(&'hir AnonConst),
23492349
}
23502350

23512351
impl<'hir> From<&'hir Ty<'hir>> for Term<'hir> {
@@ -2354,8 +2354,8 @@ impl<'hir> From<&'hir Ty<'hir>> for Term<'hir> {
23542354
}
23552355
}
23562356

2357-
impl<'hir> From<AnonConst> for Term<'hir> {
2358-
fn from(c: AnonConst) -> Self {
2357+
impl<'hir> From<&'hir AnonConst> for Term<'hir> {
2358+
fn from(c: &'hir AnonConst) -> Self {
23592359
Term::Const(c)
23602360
}
23612361
}
@@ -2646,7 +2646,7 @@ pub enum TyKind<'hir> {
26462646
/// A variable length slice (i.e., `[T]`).
26472647
Slice(&'hir Ty<'hir>),
26482648
/// A fixed length array (i.e., `[T; n]`).
2649-
Array(&'hir Ty<'hir>, ArrayLen),
2649+
Array(&'hir Ty<'hir>, ArrayLen<'hir>),
26502650
/// A raw pointer (i.e., `*const T` or `*mut T`).
26512651
Ptr(MutTy<'hir>),
26522652
/// A reference (i.e., `&'a T` or `&'a mut T`).
@@ -2675,7 +2675,7 @@ pub enum TyKind<'hir> {
26752675
/// where `Bound` is a trait or a lifetime.
26762676
TraitObject(&'hir [PolyTraitRef<'hir>], &'hir Lifetime, TraitObjectSyntax),
26772677
/// Unused for now.
2678-
Typeof(AnonConst),
2678+
Typeof(&'hir AnonConst),
26792679
/// `TyKind::Infer` means the type should be inferred instead of it having been
26802680
/// specified. This can appear anywhere in a type.
26812681
Infer,
@@ -2708,10 +2708,10 @@ pub enum InlineAsmOperand<'hir> {
27082708
out_expr: Option<&'hir Expr<'hir>>,
27092709
},
27102710
Const {
2711-
anon_const: AnonConst,
2711+
anon_const: &'hir AnonConst,
27122712
},
27132713
SymFn {
2714-
anon_const: AnonConst,
2714+
anon_const: &'hir AnonConst,
27152715
},
27162716
SymStatic {
27172717
path: QPath<'hir>,
@@ -2913,7 +2913,7 @@ pub struct Variant<'hir> {
29132913
/// Fields and constructor id of the variant.
29142914
pub data: VariantData<'hir>,
29152915
/// Explicit discriminant (e.g., `Foo = 1`).
2916-
pub disr_expr: Option<AnonConst>,
2916+
pub disr_expr: Option<&'hir AnonConst>,
29172917
/// Span
29182918
pub span: Span,
29192919
}
@@ -3833,7 +3833,7 @@ mod size_asserts {
38333833
static_assert_size!(FnDecl<'_>, 40);
38343834
static_assert_size!(ForeignItem<'_>, 72);
38353835
static_assert_size!(ForeignItemKind<'_>, 40);
3836-
static_assert_size!(GenericArg<'_>, 32);
3836+
static_assert_size!(GenericArg<'_>, 24);
38373837
static_assert_size!(GenericBound<'_>, 48);
38383838
static_assert_size!(Generics<'_>, 56);
38393839
static_assert_size!(Impl<'_>, 80);

compiler/rustc_hir/src/intravisit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub trait Visitor<'v>: Sized {
338338
fn visit_pat_field(&mut self, f: &'v PatField<'v>) -> Self::Result {
339339
walk_pat_field(self, f)
340340
}
341-
fn visit_array_length(&mut self, len: &'v ArrayLen) -> Self::Result {
341+
fn visit_array_length(&mut self, len: &'v ArrayLen<'v>) -> Self::Result {
342342
walk_array_len(self, len)
343343
}
344344
fn visit_anon_const(&mut self, c: &'v AnonConst) -> Self::Result {
@@ -703,7 +703,7 @@ pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'
703703
visitor.visit_pat(field.pat)
704704
}
705705

706-
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) -> V::Result {
706+
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen<'v>) -> V::Result {
707707
match len {
708708
// FIXME: Use `visit_infer` here.
709709
ArrayLen::Infer(InferArg { hir_id, span: _ }) => visitor.visit_id(*hir_id),

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector {
143143
_ => {}
144144
}
145145
}
146-
fn visit_array_length(&mut self, length: &'v hir::ArrayLen) {
146+
fn visit_array_length(&mut self, length: &'v hir::ArrayLen<'v>) {
147147
if let hir::ArrayLen::Infer(inf) = length {
148148
self.0.push(inf.span);
149149
}

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ impl<'a> State<'a> {
968968
self.print_else(elseopt)
969969
}
970970

971-
fn print_array_length(&mut self, len: &hir::ArrayLen) {
971+
fn print_array_length(&mut self, len: &hir::ArrayLen<'_>) {
972972
match len {
973973
hir::ArrayLen::Infer(..) => self.word("_"),
974974
hir::ArrayLen::Body(ct) => self.print_anon_const(ct),
@@ -1052,7 +1052,7 @@ impl<'a> State<'a> {
10521052
self.end()
10531053
}
10541054

1055-
fn print_expr_repeat(&mut self, element: &hir::Expr<'_>, count: &hir::ArrayLen) {
1055+
fn print_expr_repeat(&mut self, element: &hir::Expr<'_>, count: &hir::ArrayLen<'_>) {
10561056
self.ibox(INDENT_UNIT);
10571057
self.word("[");
10581058
self.print_expr(element);

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14441444
return;
14451445
};
14461446
if let hir::TyKind::Array(_, length) = ty.peel_refs().kind
1447-
&& let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length
1447+
&& let hir::ArrayLen::Body(&hir::AnonConst { hir_id, .. }) = length
14481448
{
14491449
let span = self.tcx.hir().span(hir_id);
14501450
self.dcx().try_steal_modify_and_emit_err(
@@ -1483,7 +1483,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14831483
fn check_expr_repeat(
14841484
&self,
14851485
element: &'tcx hir::Expr<'tcx>,
1486-
count: &'tcx hir::ArrayLen,
1486+
count: &'tcx hir::ArrayLen<'tcx>,
14871487
expected: Expectation<'tcx>,
14881488
expr: &'tcx hir::Expr<'tcx>,
14891489
) -> Ty<'tcx> {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
439439
}
440440
}
441441

442-
pub fn lower_array_length(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> {
442+
pub fn lower_array_length(&self, length: &hir::ArrayLen<'tcx>) -> ty::Const<'tcx> {
443443
match length {
444444
hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span),
445445
hir::ArrayLen::Body(anon_const) => {

src/librustdoc/clean/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
281281
Lifetime(lifetime.ident.name)
282282
}
283283

284-
pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
284+
pub(crate) fn clean_const<'tcx>(
285+
constant: &hir::ConstArg<'_>,
286+
cx: &mut DocContext<'tcx>,
287+
) -> Constant {
285288
let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id();
286289
Constant {
287290
type_: Box::new(clean_middle_ty(
@@ -2450,7 +2453,7 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
24502453

24512454
fn clean_variant_data<'tcx>(
24522455
variant: &hir::VariantData<'tcx>,
2453-
disr_expr: &Option<hir::AnonConst>,
2456+
disr_expr: &Option<&hir::AnonConst>,
24542457
cx: &mut DocContext<'tcx>,
24552458
) -> Variant {
24562459
let discriminant = disr_expr

src/tools/clippy/clippy_utils/src/hir_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl HirEqInterExpr<'_, '_, '_> {
224224
})
225225
}
226226

227-
pub fn eq_array_length(&mut self, left: ArrayLen, right: ArrayLen) -> bool {
227+
pub fn eq_array_length(&mut self, left: ArrayLen<'_>, right: ArrayLen<'_>) -> bool {
228228
match (left, right) {
229229
(ArrayLen::Infer(..), ArrayLen::Infer(..)) => true,
230230
(ArrayLen::Body(l_ct), ArrayLen::Body(r_ct)) => self.eq_body(l_ct.body, r_ct.body),
@@ -1116,7 +1116,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
11161116
}
11171117
}
11181118

1119-
pub fn hash_array_length(&mut self, length: ArrayLen) {
1119+
pub fn hash_array_length(&mut self, length: ArrayLen<'_>) {
11201120
match length {
11211121
ArrayLen::Infer(..) => {},
11221122
ArrayLen::Body(anon_const) => self.hash_body(anon_const.body),

0 commit comments

Comments
 (0)