Move ConstArg::span to AnonConst::span

This commit is contained in:
Oli Scherer 2024-04-26 13:05:00 +00:00
parent 4dc46f7f17
commit 4a19711b25
4 changed files with 12 additions and 9 deletions

View file

@ -1592,6 +1592,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
def_id: anon_const,
hir_id: const_id,
body: const_body,
span,
})),
is_host_effect: true,
},

View file

@ -1187,11 +1187,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir_id: this.lower_node_id(node_id),
body: this
.lower_const_body(path_expr.span, Some(&path_expr)),
span,
})
});
return GenericArg::Const(ConstArg {
value: ct,
span,
is_desugared_from_effects: false,
});
}
@ -1203,7 +1203,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
value: self.lower_anon_const(ct),
span: self.lower_span(ct.value.span),
is_desugared_from_effects: false,
}),
}
@ -2349,6 +2348,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
def_id: this.local_def_id(c.id),
hir_id: this.lower_node_id(c.id),
body: this.lower_const_body(c.value.span, Some(&c.value)),
span: this.lower_span(c.value.span),
}))
}
@ -2656,8 +2656,7 @@ impl<'hir> GenericArgsCtor<'hir> {
lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
self.args.push(hir::GenericArg::Const(hir::ConstArg {
value: lcx.arena.alloc(hir::AnonConst { def_id, hir_id, body }),
span,
value: lcx.arena.alloc(hir::AnonConst { def_id, hir_id, body, span }),
is_desugared_from_effects: true,
}))
}

View file

@ -232,7 +232,6 @@ impl<'hir> PathSegment<'hir> {
#[derive(Clone, Copy, Debug, HashStable_Generic)]
pub struct ConstArg<'hir> {
pub value: &'hir AnonConst,
pub span: Span,
/// Indicates whether this comes from a `~const` desugaring.
pub is_desugared_from_effects: bool,
}
@ -262,7 +261,7 @@ impl GenericArg<'_> {
match self {
GenericArg::Lifetime(l) => l.ident.span,
GenericArg::Type(t) => t.span,
GenericArg::Const(c) => c.span,
GenericArg::Const(c) => c.value.span,
GenericArg::Infer(i) => i.span,
}
}
@ -1591,6 +1590,7 @@ pub struct AnonConst {
pub hir_id: HirId,
pub def_id: LocalDefId,
pub body: BodyId,
pub span: Span,
}
/// An inline constant expression `const { something }`.

View file

@ -73,9 +73,12 @@ fn gen_args(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> String {
GenericArg::Type(ty) => {
cx.tcx.sess.source_map().span_to_snippet(ty.span).unwrap_or_else(|_| "_".into())
}
GenericArg::Const(c) => {
cx.tcx.sess.source_map().span_to_snippet(c.span).unwrap_or_else(|_| "_".into())
}
GenericArg::Const(c) => cx
.tcx
.sess
.source_map()
.span_to_snippet(c.value.span)
.unwrap_or_else(|_| "_".into()),
GenericArg::Infer(_) => String::from("_"),
})
.collect::<Vec<_>>();