1
Fork 0

Rename Def::{Param, Foreign} to Def::{TyParam, TyForeign}

This commit is contained in:
varkor 2018-08-22 02:13:31 +01:00
parent 08f3685a82
commit 05cfb3f5b5
17 changed files with 38 additions and 38 deletions

View file

@ -53,13 +53,13 @@ pub enum Def {
Existential(DefId), Existential(DefId),
/// `type Foo = Bar;` /// `type Foo = Bar;`
TyAlias(DefId), TyAlias(DefId),
Foreign(DefId), TyForeign(DefId),
TraitAlias(DefId), TraitAlias(DefId),
AssociatedTy(DefId), AssociatedTy(DefId),
/// `existential type Foo: Bar;` /// `existential type Foo: Bar;`
AssociatedExistential(DefId), AssociatedExistential(DefId),
PrimTy(hir::PrimTy), PrimTy(hir::PrimTy),
Param(DefId), TyParam(DefId),
SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */), SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */),
ToolMod, // e.g. `rustfmt` in `#[rustfmt::skip]` ToolMod, // e.g. `rustfmt` in `#[rustfmt::skip]`
@ -269,10 +269,10 @@ impl Def {
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) | Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) |
Def::TyAlias(id) | Def::TraitAlias(id) | Def::TyAlias(id) | Def::TraitAlias(id) |
Def::AssociatedTy(id) | Def::Param(id) | Def::Struct(id) | Def::StructCtor(id, ..) | Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) | Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
Def::AssociatedConst(id) | Def::Macro(id, ..) | Def::AssociatedConst(id) | Def::Macro(id, ..) |
Def::Existential(id) | Def::AssociatedExistential(id) | Def::Foreign(id) => { Def::Existential(id) | Def::AssociatedExistential(id) | Def::TyForeign(id) => {
id id
} }
@ -311,11 +311,11 @@ impl Def {
Def::StructCtor(.., CtorKind::Fictive) => bug!("impossible struct constructor"), Def::StructCtor(.., CtorKind::Fictive) => bug!("impossible struct constructor"),
Def::Union(..) => "union", Def::Union(..) => "union",
Def::Trait(..) => "trait", Def::Trait(..) => "trait",
Def::Foreign(..) => "foreign type", Def::TyForeign(..) => "foreign type",
Def::Method(..) => "method", Def::Method(..) => "method",
Def::Const(..) => "constant", Def::Const(..) => "constant",
Def::AssociatedConst(..) => "associated constant", Def::AssociatedConst(..) => "associated constant",
Def::Param(..) => "type parameter", Def::TyParam(..) => "type parameter",
Def::PrimTy(..) => "builtin type", Def::PrimTy(..) => "builtin type",
Def::Local(..) => "local variable", Def::Local(..) => "local variable",
Def::Upvar(..) => "closure capture", Def::Upvar(..) => "closure capture",

View file

@ -1213,7 +1213,7 @@ impl<'a> LoweringContext<'a> {
None, None,
P(hir::Path { P(hir::Path {
span, span,
def: Def::Param(DefId::local(def_index)), def: Def::TyParam(DefId::local(def_index)),
segments: hir_vec![hir::PathSegment::from_ident(ident)], segments: hir_vec![hir::PathSegment::from_ident(ident)],
}), }),
)) ))
@ -2352,7 +2352,7 @@ impl<'a> LoweringContext<'a> {
if path.segments.len() == 1 if path.segments.len() == 1
&& bound_pred.bound_generic_params.is_empty() => && bound_pred.bound_generic_params.is_empty() =>
{ {
if let Some(Def::Param(def_id)) = self.resolver if let Some(Def::TyParam(def_id)) = self.resolver
.get_resolution(bound_pred.bounded_ty.id) .get_resolution(bound_pred.bounded_ty.id)
.map(|d| d.base_def()) .map(|d| d.base_def())
{ {

View file

@ -453,7 +453,7 @@ impl<'hir> Map<'hir> {
match item.node { match item.node {
ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)), ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)),
ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)), ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)),
ForeignItemKind::Type => Some(Def::Foreign(def_id)), ForeignItemKind::Type => Some(Def::TyForeign(def_id)),
} }
} }
NodeTraitItem(item) => { NodeTraitItem(item) => {
@ -499,7 +499,7 @@ impl<'hir> Map<'hir> {
NodeGenericParam(param) => { NodeGenericParam(param) => {
Some(match param.kind { Some(match param.kind {
GenericParamKind::Lifetime { .. } => Def::Local(param.id), GenericParamKind::Lifetime { .. } => Def::Local(param.id),
GenericParamKind::Type { .. } => Def::Param(self.local_def_id(param.id)), GenericParamKind::Type { .. } => Def::TyParam(self.local_def_id(param.id)),
}) })
} }
} }

View file

@ -1010,9 +1010,9 @@ impl_stable_hash_for!(enum hir::def::Def {
AssociatedTy(def_id), AssociatedTy(def_id),
AssociatedExistential(def_id), AssociatedExistential(def_id),
PrimTy(prim_ty), PrimTy(prim_ty),
Param(def_id), TyParam(def_id),
SelfTy(trait_def_id, impl_def_id), SelfTy(trait_def_id, impl_def_id),
Foreign(def_id), TyForeign(def_id),
Fn(def_id), Fn(def_id),
Const(def_id), Const(def_id),
Static(def_id, is_mutbl), Static(def_id, is_mutbl),

View file

@ -1326,7 +1326,7 @@ fn object_lifetime_defaults_for_item(
_ => continue, _ => continue,
}; };
if def == Def::Param(param_def_id) { if def == Def::TyParam(param_def_id) {
add_bounds(&mut set, &data.bounds); add_bounds(&mut set, &data.bounds);
} }
} }

View file

@ -1510,7 +1510,7 @@ impl TypeAliasBounds {
match ty.node { match ty.node {
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => { hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => {
match path.def { match path.def {
Def::Param(_) => true, Def::TyParam(_) => true,
_ => false _ => false
} }
} }

View file

@ -429,7 +429,7 @@ impl<'tcx> EntryKind<'tcx> {
EntryKind::Trait(_) => Def::Trait(did), EntryKind::Trait(_) => Def::Trait(did),
EntryKind::Enum(..) => Def::Enum(did), EntryKind::Enum(..) => Def::Enum(did),
EntryKind::MacroDef(_) => Def::Macro(did, MacroKind::Bang), EntryKind::MacroDef(_) => Def::Macro(did, MacroKind::Bang),
EntryKind::ForeignType => Def::Foreign(did), EntryKind::ForeignType => Def::TyForeign(did),
EntryKind::ForeignMod | EntryKind::ForeignMod |
EntryKind::GlobalAsm | EntryKind::GlobalAsm |

View file

@ -656,7 +656,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
(Def::Static(self.definitions.local_def_id(item.id), m), ValueNS) (Def::Static(self.definitions.local_def_id(item.id), m), ValueNS)
} }
ForeignItemKind::Ty => { ForeignItemKind::Ty => {
(Def::Foreign(self.definitions.local_def_id(item.id)), TypeNS) (Def::TyForeign(self.definitions.local_def_id(item.id)), TypeNS)
} }
ForeignItemKind::Macro(_) => unreachable!(), ForeignItemKind::Macro(_) => unreachable!(),
}; };
@ -692,7 +692,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
span); span);
self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion)); self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
} }
Def::Variant(..) | Def::TyAlias(..) | Def::Foreign(..) => { Def::Variant(..) | Def::TyAlias(..) | Def::TyForeign(..) => {
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion)); self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
} }
Def::Fn(..) | Def::Static(..) | Def::Const(..) | Def::VariantCtor(..) => { Def::Fn(..) | Def::Static(..) | Def::Const(..) | Def::VariantCtor(..) => {

View file

@ -204,14 +204,14 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
"`Self` type implicitly declared here, on the `impl`"); "`Self` type implicitly declared here, on the `impl`");
} }
}, },
Def::Param(typaram_defid) => { Def::TyParam(typaram_defid) => {
if let Some(typaram_span) = resolver.definitions.opt_span(typaram_defid) { if let Some(typaram_span) = resolver.definitions.opt_span(typaram_defid) {
err.span_label(typaram_span, "type variable from outer function"); err.span_label(typaram_span, "type variable from outer function");
} }
}, },
_ => { _ => {
bug!("TypeParametersFromOuterFunction should only be used with Def::SelfTy or \ bug!("TypeParametersFromOuterFunction should only be used with Def::SelfTy or \
Def::Param") Def::TyParam")
} }
} }
@ -537,9 +537,9 @@ impl<'a> PathSource<'a> {
PathSource::Type => match def { PathSource::Type => match def {
Def::Struct(..) | Def::Union(..) | Def::Enum(..) | Def::Struct(..) | Def::Union(..) | Def::Enum(..) |
Def::Trait(..) | Def::TyAlias(..) | Def::AssociatedTy(..) | Def::Trait(..) | Def::TyAlias(..) | Def::AssociatedTy(..) |
Def::PrimTy(..) | Def::Param(..) | Def::SelfTy(..) | Def::PrimTy(..) | Def::TyParam(..) | Def::SelfTy(..) |
Def::Existential(..) | Def::Existential(..) |
Def::Foreign(..) => true, Def::TyForeign(..) => true,
_ => false, _ => false,
}, },
PathSource::Trait(AliasPossibility::No) => match def { PathSource::Trait(AliasPossibility::No) => match def {
@ -2359,7 +2359,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
seen_bindings.entry(ident).or_insert(param.ident.span); seen_bindings.entry(ident).or_insert(param.ident.span);
// Plain insert (no renaming). // Plain insert (no renaming).
let def = Def::Param(self.definitions.local_def_id(param.id)); let def = Def::TyParam(self.definitions.local_def_id(param.id));
function_type_rib.bindings.insert(ident, def); function_type_rib.bindings.insert(ident, def);
self.record_def(param.id, PathResolution::new(def)); self.record_def(param.id, PathResolution::new(def));
} }
@ -3765,7 +3765,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
} }
} }
} }
Def::Param(..) | Def::SelfTy(..) => { Def::TyParam(..) | Def::SelfTy(..) => {
for rib in ribs { for rib in ribs {
match rib.kind { match rib.kind {
NormalRibKind | TraitOrImplItemRibKind | ClosureRibKind(..) | NormalRibKind | TraitOrImplItemRibKind | ClosureRibKind(..) |

View file

@ -747,13 +747,13 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
HirDef::Union(def_id) | HirDef::Union(def_id) |
HirDef::Enum(def_id) | HirDef::Enum(def_id) |
HirDef::TyAlias(def_id) | HirDef::TyAlias(def_id) |
HirDef::Foreign(def_id) | HirDef::TyForeign(def_id) |
HirDef::TraitAlias(def_id) | HirDef::TraitAlias(def_id) |
HirDef::AssociatedExistential(def_id) | HirDef::AssociatedExistential(def_id) |
HirDef::AssociatedTy(def_id) | HirDef::AssociatedTy(def_id) |
HirDef::Trait(def_id) | HirDef::Trait(def_id) |
HirDef::Existential(def_id) | HirDef::Existential(def_id) |
HirDef::Param(def_id) => { HirDef::TyParam(def_id) => {
let span = self.span_from_span(sub_span); let span = self.span_from_span(sub_span);
Some(Ref { Some(Ref {
kind: RefKind::Type, kind: RefKind::Type,

View file

@ -1240,7 +1240,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
} }
} }
(&ty::Param(_), Def::SelfTy(Some(param_did), None)) | (&ty::Param(_), Def::SelfTy(Some(param_did), None)) |
(&ty::Param(_), Def::Param(param_did)) => { (&ty::Param(_), Def::TyParam(param_did)) => {
match self.find_bound_for_assoc_item(param_did, assoc_name, span) { match self.find_bound_for_assoc_item(param_did, assoc_name, span) {
Ok(bound) => bound, Ok(bound) => bound,
Err(ErrorReported) => return (tcx.types.err, Def::Err), Err(ErrorReported) => return (tcx.types.err, Def::Err),
@ -1387,7 +1387,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
) )
} }
Def::Enum(did) | Def::TyAlias(did) | Def::Struct(did) | Def::Enum(did) | Def::TyAlias(did) | Def::Struct(did) |
Def::Union(did) | Def::Foreign(did) => { Def::Union(did) | Def::TyForeign(did) => {
assert_eq!(opt_self_ty, None); assert_eq!(opt_self_ty, None);
self.prohibit_generics(path.segments.split_last().unwrap().1); self.prohibit_generics(path.segments.split_last().unwrap().1);
self.ast_path_to_ty(span, did, path.segments.last().unwrap()) self.ast_path_to_ty(span, did, path.segments.last().unwrap())
@ -1401,7 +1401,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
tcx.parent_def_id(did).unwrap(), tcx.parent_def_id(did).unwrap(),
path.segments.last().unwrap()) path.segments.last().unwrap())
} }
Def::Param(did) => { Def::TyParam(did) => {
assert_eq!(opt_self_ty, None); assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments); self.prohibit_generics(&path.segments);

View file

@ -830,7 +830,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
hir::intravisit::walk_ty(self, ty); hir::intravisit::walk_ty(self, ty);
match ty.node { match ty.node {
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => { hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => {
if let hir::def::Def::Param(def_id) = path.def { if let hir::def::Def::TyParam(def_id) = path.def {
if def_id == self.1 { if def_id == self.1 {
self.0 = Some(ty.span); self.0 = Some(ty.span);
} }

View file

@ -350,7 +350,7 @@ fn is_param<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node { if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node {
match path.def { match path.def {
Def::SelfTy(Some(def_id), None) | Def::SelfTy(Some(def_id), None) |
Def::Param(def_id) => { Def::TyParam(def_id) => {
def_id == tcx.hir.local_def_id(param_id) def_id == tcx.hir.local_def_id(param_id)
} }
_ => false _ => false

View file

@ -83,7 +83,7 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
ret.extend(build_impls(cx, did, true)); ret.extend(build_impls(cx, did, true));
clean::EnumItem(build_enum(cx, did)) clean::EnumItem(build_enum(cx, did))
} }
Def::Foreign(did) => { Def::TyForeign(did) => {
record_extern_fqn(cx, did, clean::TypeKind::Foreign); record_extern_fqn(cx, did, clean::TypeKind::Foreign);
ret.extend(build_impls(cx, did, false)); ret.extend(build_impls(cx, did, false));
clean::ForeignTypeItem clean::ForeignTypeItem

View file

@ -2411,7 +2411,7 @@ impl Clean<Type> for hir::Ty {
return new_ty; return new_ty;
} }
if let Def::Param(did) = path.def { if let Def::TyParam(did) = path.def {
if let Some(bounds) = cx.impl_trait_bounds.borrow_mut().remove(&did) { if let Some(bounds) = cx.impl_trait_bounds.borrow_mut().remove(&did) {
return ImplTrait(bounds); return ImplTrait(bounds);
} }
@ -2460,7 +2460,7 @@ impl Clean<Type> for hir::Ty {
} }
hir::GenericParamKind::Type { ref default, .. } => { hir::GenericParamKind::Type { ref default, .. } => {
let ty_param_def = let ty_param_def =
Def::Param(cx.tcx.hir.local_def_id(param.id)); Def::TyParam(cx.tcx.hir.local_def_id(param.id));
let mut j = 0; let mut j = 0;
let type_ = generic_args.args.iter().find_map(|arg| { let type_ = generic_args.args.iter().find_map(|arg| {
match arg { match arg {
@ -3710,10 +3710,10 @@ fn resolve_type(cx: &DocContext,
Def::SelfTy(..) if path.segments.len() == 1 => { Def::SelfTy(..) if path.segments.len() == 1 => {
return Generic(keywords::SelfType.name().to_string()); return Generic(keywords::SelfType.name().to_string());
} }
Def::Param(..) if path.segments.len() == 1 => { Def::TyParam(..) if path.segments.len() == 1 => {
return Generic(format!("{:#}", path)); return Generic(format!("{:#}", path));
} }
Def::SelfTy(..) | Def::Param(..) | Def::AssociatedTy(..) => true, Def::SelfTy(..) | Def::TyParam(..) | Def::AssociatedTy(..) => true,
_ => false, _ => false,
}; };
let did = register_def(&*cx, path.def); let did = register_def(&*cx, path.def);
@ -3731,7 +3731,7 @@ pub fn register_def(cx: &DocContext, def: Def) -> DefId {
Def::Struct(i) => (i, TypeKind::Struct), Def::Struct(i) => (i, TypeKind::Struct),
Def::Union(i) => (i, TypeKind::Union), Def::Union(i) => (i, TypeKind::Union),
Def::Mod(i) => (i, TypeKind::Module), Def::Mod(i) => (i, TypeKind::Module),
Def::Foreign(i) => (i, TypeKind::Foreign), Def::TyForeign(i) => (i, TypeKind::Foreign),
Def::Const(i) => (i, TypeKind::Const), Def::Const(i) => (i, TypeKind::Const),
Def::Static(i, _) => (i, TypeKind::Static), Def::Static(i, _) => (i, TypeKind::Static),
Def::Variant(i) => (cx.tcx.parent_def_id(i).expect("cannot get parent def id"), Def::Variant(i) => (cx.tcx.parent_def_id(i).expect("cannot get parent def id"),

View file

@ -234,7 +234,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> DocContext<'a, 'tcx, 'rcx, 'cstore> {
None, None,
P(hir::Path { P(hir::Path {
span: DUMMY_SP, span: DUMMY_SP,
def: Def::Param(param.def_id), def: Def::TyParam(param.def_id),
segments: HirVec::from_vec(vec![ segments: HirVec::from_vec(vec![
hir::PathSegment::from_ident(Ident::from_interned_str(param.name)) hir::PathSegment::from_ident(Ident::from_interned_str(param.name))
]), ]),

View file

@ -267,7 +267,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
Def::Struct(did) | Def::Struct(did) |
Def::Union(did) | Def::Union(did) |
Def::Enum(did) | Def::Enum(did) |
Def::Foreign(did) | Def::TyForeign(did) |
Def::TyAlias(did) if !self_is_hidden => { Def::TyAlias(did) if !self_is_hidden => {
self.cx.access_levels.borrow_mut().map.insert(did, AccessLevel::Public); self.cx.access_levels.borrow_mut().map.insert(did, AccessLevel::Public);
}, },