Skip to content

Commit acd3ad9

Browse files
committed
Add optional ConstArg field to ItemKind::Const
Currently always None, but will be Some if the const item value is a const path.
1 parent e0883a2 commit acd3ad9

File tree

21 files changed

+30
-28
lines changed

21 files changed

+30
-28
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
212212
},
213213
);
214214
self.lower_define_opaque(hir_id, &define_opaque);
215-
hir::ItemKind::Const(ident, ty, generics, body_id)
215+
// TODO: make const arg instead of always using None
216+
hir::ItemKind::Const(ident, ty, generics, body_id, None)
216217
}
217218
ItemKind::Fn(box Fn {
218219
sig: FnSig { decl, header, span: fn_sig_span },

compiler/rustc_hir/src/hir.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3986,8 +3986,8 @@ impl<'hir> Item<'hir> {
39863986
expect_static, (Ident, &'hir Ty<'hir>, Mutability, BodyId),
39873987
ItemKind::Static(ident, ty, mutbl, body), (*ident, ty, *mutbl, *body);
39883988

3989-
expect_const, (Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
3990-
ItemKind::Const(ident, ty, generics, body), (*ident, ty, generics, *body);
3989+
expect_const, (Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId, Option<&'hir ConstArg<'hir>>),
3990+
ItemKind::Const(ident, ty, generics, body, ct), (*ident, ty, generics, *body, *ct);
39913991

39923992
expect_fn, (Ident, &FnSig<'hir>, &'hir Generics<'hir>, BodyId),
39933993
ItemKind::Fn { ident, sig, generics, body, .. }, (*ident, sig, generics, *body);
@@ -4157,7 +4157,7 @@ pub enum ItemKind<'hir> {
41574157
/// A `static` item.
41584158
Static(Ident, &'hir Ty<'hir>, Mutability, BodyId),
41594159
/// A `const` item.
4160-
Const(Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
4160+
Const(Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId, Option<&'hir ConstArg<'hir>>),
41614161
/// A function declaration.
41624162
Fn {
41634163
ident: Ident,
@@ -4252,7 +4252,7 @@ impl ItemKind<'_> {
42524252
Some(match self {
42534253
ItemKind::Fn { generics, .. }
42544254
| ItemKind::TyAlias(_, _, generics)
4255-
| ItemKind::Const(_, _, generics, _)
4255+
| ItemKind::Const(_, _, generics, _, _)
42564256
| ItemKind::Enum(_, _, generics)
42574257
| ItemKind::Struct(_, _, generics)
42584258
| ItemKind::Union(_, _, generics)
@@ -4455,7 +4455,7 @@ impl<'hir> OwnerNode<'hir> {
44554455
OwnerNode::Item(Item {
44564456
kind:
44574457
ItemKind::Static(_, _, _, body)
4458-
| ItemKind::Const(_, _, _, body)
4458+
| ItemKind::Const(_, _, _, body, _)
44594459
| ItemKind::Fn { body, .. },
44604460
..
44614461
})
@@ -4681,7 +4681,7 @@ impl<'hir> Node<'hir> {
46814681
Node::Item(it) => match it.kind {
46824682
ItemKind::TyAlias(_, ty, _)
46834683
| ItemKind::Static(_, ty, _, _)
4684-
| ItemKind::Const(_, ty, _, _) => Some(ty),
4684+
| ItemKind::Const(_, ty, _, _, _) => Some(ty),
46854685
ItemKind::Impl(impl_item) => Some(&impl_item.self_ty),
46864686
_ => None,
46874687
},
@@ -4712,7 +4712,7 @@ impl<'hir> Node<'hir> {
47124712
Node::Item(Item {
47134713
owner_id,
47144714
kind:
4715-
ItemKind::Const(_, _, _, body)
4715+
ItemKind::Const(_, _, _, body, _)
47164716
| ItemKind::Static(.., body)
47174717
| ItemKind::Fn { body, .. },
47184718
..

compiler/rustc_hir/src/intravisit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,12 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
550550
try_visit!(visitor.visit_ty_unambig(typ));
551551
try_visit!(visitor.visit_nested_body(body));
552552
}
553-
ItemKind::Const(ident, ref typ, ref generics, body) => {
553+
ItemKind::Const(ident, ref typ, ref generics, body, ct) => {
554554
try_visit!(visitor.visit_ident(ident));
555555
try_visit!(visitor.visit_ty_unambig(typ));
556556
try_visit!(visitor.visit_generics(generics));
557557
try_visit!(visitor.visit_nested_body(body));
558+
visit_opt!(visitor, visit_const_arg_unambig, ct);
558559
}
559560
ItemKind::Fn { ident, sig, generics, body: body_id, .. } => {
560561
try_visit!(visitor.visit_ident(ident));

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
628628
intravisit::walk_item(self, item);
629629
}
630630
hir::ItemKind::TyAlias(_, _, generics)
631-
| hir::ItemKind::Const(_, _, generics, _)
631+
| hir::ItemKind::Const(_, _, generics,_, _)
632632
| hir::ItemKind::Enum(_, _, generics)
633633
| hir::ItemKind::Struct(_, _, generics)
634634
| hir::ItemKind::Union(_, _, generics)

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
216216
icx.lower_ty(ty)
217217
}
218218
}
219-
ItemKind::Const(ident, ty, _, body_id) => {
219+
ItemKind::Const(ident, ty, _, body_id,_) => {
220220
if ty.is_suggestable_infer_ty() {
221221
infer_placeholder_type(
222222
icx.lowerer(),

compiler/rustc_hir_analysis/src/hir_wf_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn diagnostic_hir_wf_check<'tcx>(
138138
hir::Node::Item(item) => match item.kind {
139139
hir::ItemKind::TyAlias(_, ty, _)
140140
| hir::ItemKind::Static(_, ty, _, _)
141-
| hir::ItemKind::Const(_, ty, _, _) => vec![ty],
141+
| hir::ItemKind::Const(_, ty, _, _,_) => vec![ty],
142142
hir::ItemKind::Impl(impl_) => match &impl_.of_trait {
143143
Some(t) => t
144144
.path

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl<'a> State<'a> {
608608
self.word(";");
609609
self.end(); // end the outer cbox
610610
}
611-
hir::ItemKind::Const(ident, ty, generics, expr) => {
611+
hir::ItemKind::Const(ident, ty, generics, expr, _ct) => {
612612
self.head("const");
613613
self.print_ident(ident);
614614
self.print_generic_params(generics.params);

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12451245
match opt_def_id {
12461246
Some(def_id) => match self.tcx.hir_get_if_local(def_id) {
12471247
Some(hir::Node::Item(hir::Item {
1248-
kind: hir::ItemKind::Const(_, _, _, body_id),
1248+
kind: hir::ItemKind::Const(_, _, _, body_id, _),
12491249
..
12501250
})) => match self.tcx.hir_node(body_id.hir_id) {
12511251
hir::Node::Expr(expr) => {

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ impl<'tcx> LateContext<'tcx> {
949949
..
950950
}) => *init,
951951
hir::Node::Item(item) => match item.kind {
952-
hir::ItemKind::Const(.., body_id) | hir::ItemKind::Static(.., body_id) => {
952+
hir::ItemKind::Const(.., body_id,_) | hir::ItemKind::Static(.., body_id) => {
953953
Some(self.tcx.hir_body(body_id).value)
954954
}
955955
_ => None,

compiler/rustc_lint/src/non_local_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
183183
&& parent_opt_item_name != Some(kw::Underscore)
184184
&& let Some(parent) = parent.as_local()
185185
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent)
186-
&& let ItemKind::Const(ident, ty, _, _) = item.kind
186+
&& let ItemKind::Const(ident, ty, _, _, _) = item.kind
187187
&& let TyKind::Tup(&[]) = ty.kind
188188
{
189189
Some(ident.span)

0 commit comments

Comments
 (0)