Skip to content

Commit

Permalink
Add const params to Def
Browse files Browse the repository at this point in the history
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
  • Loading branch information
varkor and yodaldevoid committed Feb 7, 2019
1 parent ea0d998 commit 29f7206
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum Def {
AssociatedExistential(DefId),
PrimTy(hir::PrimTy),
TyParam(DefId),
ConstParam(DefId),
SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */),
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`

Expand Down Expand Up @@ -265,7 +266,8 @@ impl Def {
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) |
Def::TyAlias(id) | Def::TraitAlias(id) |
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
Def::AssociatedTy(id) | Def::TyParam(id) | Def::ConstParam(id) | Def::Struct(id) |
Def::StructCtor(id, ..) |
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
Def::AssociatedConst(id) | Def::Macro(id, ..) |
Def::Existential(id) | Def::AssociatedExistential(id) | Def::ForeignTy(id) => {
Expand Down Expand Up @@ -322,6 +324,7 @@ impl Def {
Def::Const(..) => "constant",
Def::AssociatedConst(..) => "associated constant",
Def::TyParam(..) => "type parameter",
Def::ConstParam(..) => "const parameter",
Def::PrimTy(..) => "builtin type",
Def::Local(..) => "local variable",
Def::Upvar(..) => "closure capture",
Expand Down
1 change: 1 addition & 0 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
let def_path_data = match param.kind {
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeParam(name),
GenericParamKind::Type { .. } => DefPathData::TypeParam(name),
GenericParamKind::Const { .. } => DefPathData::ConstParam(name),
};
self.create_def(param.id, def_path_data, REGULAR_SPACE, param.ident.span);

Expand Down
8 changes: 6 additions & 2 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ pub enum DefPathData {
/// A closure expression
ClosureExpr,
// Subportions of items
/// A type parameter (generic parameter)
/// A type (generic) parameter
TypeParam(InternedString),
/// A lifetime definition
/// A lifetime (generic) parameter
LifetimeParam(InternedString),
/// A const (generic) parameter
ConstParam(InternedString),
/// A variant of a enum
EnumVariant(InternedString),
/// A struct field
Expand Down Expand Up @@ -641,6 +643,7 @@ impl DefPathData {
MacroDef(name) |
TypeParam(name) |
LifetimeParam(name) |
ConstParam(name) |
EnumVariant(name) |
Field(name) |
GlobalMetaData(name) => Some(name),
Expand Down Expand Up @@ -669,6 +672,7 @@ impl DefPathData {
MacroDef(name) |
TypeParam(name) |
LifetimeParam(name) |
ConstParam(name) |
EnumVariant(name) |
Field(name) |
GlobalMetaData(name) => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ impl_stable_hash_for!(enum hir::def::Def {
AssociatedExistential(def_id),
PrimTy(prim_ty),
TyParam(def_id),
ConstParam(def_id),
SelfTy(trait_def_id, impl_def_id),
ForeignTy(def_id),
Fn(def_id),
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/item_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
data @ DefPathData::Module(..) |
data @ DefPathData::TypeParam(..) |
data @ DefPathData::LifetimeParam(..) |
data @ DefPathData::ConstParam(..) |
data @ DefPathData::EnumVariant(..) |
data @ DefPathData::Field(..) |
data @ DefPathData::AnonConst |
Expand Down
1 change: 1 addition & 0 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ impl PrintContext {
DefPathData::ClosureExpr |
DefPathData::TypeParam(_) |
DefPathData::LifetimeParam(_) |
DefPathData::ConstParam(_) |
DefPathData::Field(_) |
DefPathData::StructCtor |
DefPathData::AnonConst |
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,13 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
ref_id: id_from_def_id(def_id),
})
}
HirDef::ConstParam(def_id) => {
Some(Ref {
kind: RefKind::Variable,
span,
ref_id: id_from_def_id(def_id),
})
}
HirDef::StructCtor(def_id, _) => {
// This is a reference to a tuple struct where the def_id points
// to an invisible constructor function. That is not a very useful
Expand Down

0 comments on commit 29f7206

Please sign in to comment.