Skip to content

Commit 02c1774

Browse files
committed
Give inline const separate DefKind
1 parent 089a016 commit 02c1774

File tree

16 files changed

+46
-15
lines changed

16 files changed

+46
-15
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
4242
| DefKind::Static
4343
| DefKind::ConstParam
4444
| DefKind::AnonConst
45+
| DefKind::InlineConst
4546
| DefKind::AssocConst
4647
),
4748
"Unexpected DefKind: {:?}",

compiler/rustc_hir/src/def.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ pub enum DefKind {
104104
Use,
105105
/// An `extern` block.
106106
ForeignMod,
107-
/// Anonymous constant, e.g. the `1 + 2` in `[u8; 1 + 2]`, or `const { 1 + 2}`
107+
/// Anonymous constant, e.g. the `1 + 2` in `[u8; 1 + 2]`
108108
AnonConst,
109+
/// An inline constant, e.g. `const { 1 + 2 }`
110+
InlineConst,
109111
/// Opaque type, aka `impl Trait`.
110112
OpaqueTy,
111113
Field,
@@ -155,6 +157,7 @@ impl DefKind {
155157
DefKind::Use => "import",
156158
DefKind::ForeignMod => "foreign module",
157159
DefKind::AnonConst => "constant expression",
160+
DefKind::InlineConst => "inline constant",
158161
DefKind::Field => "field",
159162
DefKind::Impl => "implementation",
160163
DefKind::Closure => "closure",
@@ -174,6 +177,7 @@ impl DefKind {
174177
| DefKind::OpaqueTy
175178
| DefKind::Impl
176179
| DefKind::Use
180+
| DefKind::InlineConst
177181
| DefKind::ExternCrate => "an",
178182
DefKind::Macro(macro_kind) => macro_kind.article(),
179183
_ => "a",
@@ -207,6 +211,7 @@ impl DefKind {
207211

208212
// Not namespaced.
209213
DefKind::AnonConst
214+
| DefKind::InlineConst
210215
| DefKind::Field
211216
| DefKind::LifetimeParam
212217
| DefKind::ExternCrate

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
797797
| DefKind::ConstParam
798798
| DefKind::LifetimeParam
799799
| DefKind::AnonConst
800+
| DefKind::InlineConst
800801
| DefKind::GlobalAsm
801802
| DefKind::Closure
802803
| DefKind::Generator
@@ -832,6 +833,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
832833
DefKind::Use
833834
| DefKind::LifetimeParam
834835
| DefKind::AnonConst
836+
| DefKind::InlineConst
835837
| DefKind::GlobalAsm
836838
| DefKind::Closure
837839
| DefKind::Generator
@@ -856,9 +858,11 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
856858
(true, mir_opt_base)
857859
}
858860
// Constants
859-
DefKind::AnonConst | DefKind::AssocConst | DefKind::Static | DefKind::Const => {
860-
(true, false)
861-
}
861+
DefKind::AnonConst
862+
| DefKind::InlineConst
863+
| DefKind::AssocConst
864+
| DefKind::Static
865+
| DefKind::Const => (true, false),
862866
// Full-fledged functions
863867
DefKind::AssocFn | DefKind::Fn => {
864868
let generics = tcx.generics_of(def_id);
@@ -914,6 +918,7 @@ fn should_encode_variances(def_kind: DefKind) -> bool {
914918
| DefKind::Use
915919
| DefKind::LifetimeParam
916920
| DefKind::AnonConst
921+
| DefKind::InlineConst
917922
| DefKind::GlobalAsm
918923
| DefKind::Closure
919924
| DefKind::Generator
@@ -939,6 +944,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
939944
| DefKind::AssocFn
940945
| DefKind::AssocConst
941946
| DefKind::AnonConst
947+
| DefKind::InlineConst
942948
| DefKind::OpaqueTy
943949
| DefKind::Impl
944950
| DefKind::Field

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,15 @@ impl<'hir> Map<'hir> {
266266
};
267267
DefKind::Ctor(ctor_of, def::CtorKind::from_hir(variant_data))
268268
}
269-
Node::AnonConst(_) => DefKind::AnonConst,
269+
Node::AnonConst(_) => {
270+
let inline = match self.find(self.get_parent_node(hir_id)) {
271+
Some(Node::Expr(&Expr {
272+
kind: ExprKind::ConstBlock(ref anon_const), ..
273+
})) if anon_const.hir_id == hir_id => true,
274+
_ => false,
275+
};
276+
if inline { DefKind::InlineConst } else { DefKind::AnonConst }
277+
}
270278
Node::Field(_) => DefKind::Field,
271279
Node::Expr(expr) => match expr.kind {
272280
ExprKind::Closure(.., None) => DefKind::Closure,

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn Write) -> io::Res
958958
write!(w, "static {}", if tcx.is_mutable_static(def_id) { "mut " } else { "" })?
959959
}
960960
(_, _) if is_function => write!(w, "fn ")?,
961-
(DefKind::AnonConst, _) => {} // things like anon const, not an item
961+
(DefKind::AnonConst | DefKind::InlineConst, _) => {} // things like anon const, not an item
962962
_ => bug!("Unexpected def kind {:?}", kind),
963963
}
964964

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,8 @@ impl<'tcx> TyCtxt<'tcx> {
19271927
| DefKind::Static
19281928
| DefKind::AssocConst
19291929
| DefKind::Ctor(..)
1930-
| DefKind::AnonConst => self.mir_for_ctfe_opt_const_arg(def),
1930+
| DefKind::AnonConst
1931+
| DefKind::InlineConst => self.mir_for_ctfe_opt_const_arg(def),
19311932
// If the caller wants `mir_for_ctfe` of a function they should not be using
19321933
// `instance_mir`, so we'll assume const fn also wants the optimized version.
19331934
_ => {

compiler/rustc_monomorphize/src/polymorphize.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn mark_used_by_default_parameters<'tcx>(
167167
| DefKind::Use
168168
| DefKind::ForeignMod
169169
| DefKind::AnonConst
170+
| DefKind::InlineConst
170171
| DefKind::OpaqueTy
171172
| DefKind::Field
172173
| DefKind::LifetimeParam
@@ -303,7 +304,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
303304
ControlFlow::CONTINUE
304305
}
305306
ty::ConstKind::Unevaluated(uv)
306-
if self.tcx.def_kind(uv.def.did) == DefKind::AnonConst =>
307+
if matches!(self.tcx.def_kind(uv.def.did), DefKind::AnonConst | DefKind::InlineConst) =>
307308
{
308309
self.visit_child_body(uv.def.did, uv.substs(self.tcx));
309310
ControlFlow::CONTINUE

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ impl EmbargoVisitor<'tcx> {
618618
| DefKind::Use
619619
| DefKind::ForeignMod
620620
| DefKind::AnonConst
621+
| DefKind::InlineConst
621622
| DefKind::Field
622623
| DefKind::GlobalAsm
623624
| DefKind::Impl

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
967967
| DefKind::Use
968968
| DefKind::ForeignMod
969969
| DefKind::AnonConst
970+
| DefKind::InlineConst
970971
| DefKind::Field
971972
| DefKind::LifetimeParam
972973
| DefKind::GlobalAsm

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ fn is_late_bound_map<'tcx>(
540540
def_id: LocalDefId,
541541
) -> Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
542542
match tcx.def_kind(def_id) {
543-
DefKind::AnonConst => {
543+
DefKind::AnonConst | DefKind::InlineConst => {
544544
let mut def_id = tcx
545545
.parent(def_id.to_def_id())
546546
.unwrap_or_else(|| bug!("anon const or closure without a parent"));

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ impl<'tcx> SaveContext<'tcx> {
739739
| HirDefKind::ForeignMod
740740
| HirDefKind::LifetimeParam
741741
| HirDefKind::AnonConst
742+
| HirDefKind::InlineConst
742743
| HirDefKind::Use
743744
| HirDefKind::Field
744745
| HirDefKind::GlobalAsm

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
151151

152152
if concrete.is_ok() && uv.substs(infcx.tcx).definitely_has_param_types_or_consts(infcx.tcx) {
153153
match infcx.tcx.def_kind(uv.def.did) {
154-
DefKind::AnonConst => {
154+
DefKind::AnonConst | DefKind::InlineConst => {
155155
let mir_body = infcx.tcx.mir_for_ctfe_opt_const_arg(uv.def);
156156

157157
if mir_body.is_polymorphic {
@@ -495,7 +495,7 @@ pub(super) fn thir_abstract_const<'tcx>(
495495
// we want to look into them or treat them as opaque projections.
496496
//
497497
// Right now we do neither of that and simply always fail to unify them.
498-
DefKind::AnonConst => (),
498+
DefKind::AnonConst | DefKind::InlineConst => (),
499499
_ => return Ok(None),
500500
}
501501

src/librustdoc/clean/utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
430430
| Res::NonMacroAttr(_)
431431
| Res::Err => return res.def_id(),
432432
Res::Def(
433-
TyParam | ConstParam | Ctor(..) | ExternCrate | Use | ForeignMod | AnonConst | OpaqueTy
434-
| Field | LifetimeParam | GlobalAsm | Impl | Closure | Generator,
433+
TyParam | ConstParam | Ctor(..) | ExternCrate | Use | ForeignMod | AnonConst
434+
| InlineConst | OpaqueTy | Field | LifetimeParam | GlobalAsm | Impl | Closure
435+
| Generator,
435436
id,
436437
) => return id,
437438
};

src/librustdoc/formats/item_type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl From<DefKind> for ItemType {
134134
| DefKind::Use
135135
| DefKind::ForeignMod
136136
| DefKind::AnonConst
137+
| DefKind::InlineConst
137138
| DefKind::OpaqueTy
138139
| DefKind::Field
139140
| DefKind::LifetimeParam

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,8 @@ fn resolution_failure(
19371937
| Use
19381938
| LifetimeParam
19391939
| Ctor(_, _)
1940-
| AnonConst => {
1940+
| AnonConst
1941+
| InlineConst => {
19411942
let note = assoc_item_not_allowed(res);
19421943
if let Some(span) = sp {
19431944
diag.span_label(span, &note);

src/tools/clippy/clippy_lints/src/matches.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,10 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
10651065
PatKind::Path(path) => {
10661066
#[allow(clippy::match_same_arms)]
10671067
let id = match cx.qpath_res(path, pat.hir_id) {
1068-
Res::Def(DefKind::Const | DefKind::ConstParam | DefKind::AnonConst, _) => return,
1068+
Res::Def(
1069+
DefKind::Const | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst,
1070+
_,
1071+
) => return,
10691072
Res::Def(_, id) => id,
10701073
_ => return,
10711074
};

0 commit comments

Comments
 (0)