Skip to content

Commit 29f7206

Browse files
varkoryodaldevoid
andcommitted
Add const params to Def
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent ea0d998 commit 29f7206

File tree

7 files changed

+21
-3
lines changed

7 files changed

+21
-3
lines changed

src/librustc/hir/def.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub enum Def {
5252
AssociatedExistential(DefId),
5353
PrimTy(hir::PrimTy),
5454
TyParam(DefId),
55+
ConstParam(DefId),
5556
SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */),
5657
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`
5758

@@ -265,7 +266,8 @@ impl Def {
265266
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
266267
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) |
267268
Def::TyAlias(id) | Def::TraitAlias(id) |
268-
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
269+
Def::AssociatedTy(id) | Def::TyParam(id) | Def::ConstParam(id) | Def::Struct(id) |
270+
Def::StructCtor(id, ..) |
269271
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
270272
Def::AssociatedConst(id) | Def::Macro(id, ..) |
271273
Def::Existential(id) | Def::AssociatedExistential(id) | Def::ForeignTy(id) => {
@@ -322,6 +324,7 @@ impl Def {
322324
Def::Const(..) => "constant",
323325
Def::AssociatedConst(..) => "associated constant",
324326
Def::TyParam(..) => "type parameter",
327+
Def::ConstParam(..) => "const parameter",
325328
Def::PrimTy(..) => "builtin type",
326329
Def::Local(..) => "local variable",
327330
Def::Upvar(..) => "closure capture",

src/librustc/hir/map/def_collector.rs

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
218218
let def_path_data = match param.kind {
219219
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeParam(name),
220220
GenericParamKind::Type { .. } => DefPathData::TypeParam(name),
221+
GenericParamKind::Const { .. } => DefPathData::ConstParam(name),
221222
};
222223
self.create_def(param.id, def_path_data, REGULAR_SPACE, param.ident.span);
223224

src/librustc/hir/map/definitions.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,12 @@ pub enum DefPathData {
356356
/// A closure expression
357357
ClosureExpr,
358358
// Subportions of items
359-
/// A type parameter (generic parameter)
359+
/// A type (generic) parameter
360360
TypeParam(InternedString),
361-
/// A lifetime definition
361+
/// A lifetime (generic) parameter
362362
LifetimeParam(InternedString),
363+
/// A const (generic) parameter
364+
ConstParam(InternedString),
363365
/// A variant of a enum
364366
EnumVariant(InternedString),
365367
/// A struct field
@@ -641,6 +643,7 @@ impl DefPathData {
641643
MacroDef(name) |
642644
TypeParam(name) |
643645
LifetimeParam(name) |
646+
ConstParam(name) |
644647
EnumVariant(name) |
645648
Field(name) |
646649
GlobalMetaData(name) => Some(name),
@@ -669,6 +672,7 @@ impl DefPathData {
669672
MacroDef(name) |
670673
TypeParam(name) |
671674
LifetimeParam(name) |
675+
ConstParam(name) |
672676
EnumVariant(name) |
673677
Field(name) |
674678
GlobalMetaData(name) => {

src/librustc/ich/impls_hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ impl_stable_hash_for!(enum hir::def::Def {
10461046
AssociatedExistential(def_id),
10471047
PrimTy(prim_ty),
10481048
TyParam(def_id),
1049+
ConstParam(def_id),
10491050
SelfTy(trait_def_id, impl_def_id),
10501051
ForeignTy(def_id),
10511052
Fn(def_id),

src/librustc/ty/item_path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
325325
data @ DefPathData::Module(..) |
326326
data @ DefPathData::TypeParam(..) |
327327
data @ DefPathData::LifetimeParam(..) |
328+
data @ DefPathData::ConstParam(..) |
328329
data @ DefPathData::EnumVariant(..) |
329330
data @ DefPathData::Field(..) |
330331
data @ DefPathData::AnonConst |

src/librustc/util/ppaux.rs

+1
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ impl PrintContext {
426426
DefPathData::ClosureExpr |
427427
DefPathData::TypeParam(_) |
428428
DefPathData::LifetimeParam(_) |
429+
DefPathData::ConstParam(_) |
429430
DefPathData::Field(_) |
430431
DefPathData::StructCtor |
431432
DefPathData::AnonConst |

src/librustc_save_analysis/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,13 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
762762
ref_id: id_from_def_id(def_id),
763763
})
764764
}
765+
HirDef::ConstParam(def_id) => {
766+
Some(Ref {
767+
kind: RefKind::Variable,
768+
span,
769+
ref_id: id_from_def_id(def_id),
770+
})
771+
}
765772
HirDef::StructCtor(def_id, _) => {
766773
// This is a reference to a tuple struct where the def_id points
767774
// to an invisible constructor function. That is not a very useful

0 commit comments

Comments
 (0)