Rename TyKind::Def to OpaqueDef

This commit is contained in:
Matthew Jasper 2020-06-07 18:56:17 +01:00
parent 6c04d8672d
commit ee0d3c7f90
14 changed files with 22 additions and 21 deletions

View File

@ -1400,7 +1400,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
lctx.generate_opaque_type(opaque_ty_node_id, opaque_ty_item, span, opaque_ty_span); lctx.generate_opaque_type(opaque_ty_node_id, opaque_ty_item, span, opaque_ty_span);
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`. // `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, lifetimes) hir::TyKind::OpaqueDef(hir::ItemId { id: opaque_ty_id }, lifetimes)
}) })
} }

View File

@ -2046,12 +2046,12 @@ pub enum TyKind<'hir> {
/// ///
/// Type parameters may be stored in each `PathSegment`. /// Type parameters may be stored in each `PathSegment`.
Path(QPath<'hir>), Path(QPath<'hir>),
/// A type definition itself. This is currently only used for the `type Foo = impl Trait` /// A opaque type definition itself. This is currently only used for the
/// item that `impl Trait` in return position desugars to. /// `opaque type Foo: Trait` item that `impl Trait` in desugars to.
/// ///
/// The generic argument list contains the lifetimes (and in the future possibly parameters) /// The generic argument list contains the lifetimes (and in the future
/// that are actually bound on the `impl Trait`. /// possibly parameters) that are actually bound on the `impl Trait`.
Def(ItemId, &'hir [GenericArg<'hir>]), OpaqueDef(ItemId, &'hir [GenericArg<'hir>]),
/// A trait object type `Bound1 + Bound2 + Bound3` /// A trait object type `Bound1 + Bound2 + Bound3`
/// where `Bound` is a trait or a lifetime. /// where `Bound` is a trait or a lifetime.
TraitObject(&'hir [PolyTraitRef<'hir>], Lifetime), TraitObject(&'hir [PolyTraitRef<'hir>], Lifetime),

View File

@ -690,7 +690,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
TyKind::Path(ref qpath) => { TyKind::Path(ref qpath) => {
visitor.visit_qpath(qpath, typ.hir_id, typ.span); visitor.visit_qpath(qpath, typ.hir_id, typ.span);
} }
TyKind::Def(item_id, lifetimes) => { TyKind::OpaqueDef(item_id, lifetimes) => {
visitor.visit_nested_item(item_id); visitor.visit_nested_item(item_id);
walk_list!(visitor, visit_generic_arg, lifetimes); walk_list!(visitor, visit_generic_arg, lifetimes);
} }

View File

@ -407,7 +407,7 @@ impl<'a> State<'a> {
&f.param_names[..], &f.param_names[..],
); );
} }
hir::TyKind::Def(..) => self.s.word("/*impl Trait*/"), hir::TyKind::OpaqueDef(..) => self.s.word("/*impl Trait*/"),
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false), hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
hir::TyKind::TraitObject(bounds, ref lifetime) => { hir::TyKind::TraitObject(bounds, ref lifetime) => {
let mut first = true; let mut first = true;

View File

@ -84,7 +84,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
rustc_hir::intravisit::walk_ty(&mut v, ty); rustc_hir::intravisit::walk_ty(&mut v, ty);
debug!("try_report_named_anon_conflict: ret ty {:?}", ty); debug!("try_report_named_anon_conflict: ret ty {:?}", ty);
if sub == &ty::ReStatic && (matches!(ty.kind, TyKind::Def(_, _)) || v.0.len() == 1) if sub == &ty::ReStatic
&& (matches!(ty.kind, TyKind::OpaqueDef(_, _)) || v.0.len() == 1)
{ {
debug!("try_report_named_anon_conflict: impl Trait + 'static"); debug!("try_report_named_anon_conflict: impl Trait + 'static");
// This is an `impl Trait` or `dyn Trait` return that evaluates de need of // This is an `impl Trait` or `dyn Trait` return that evaluates de need of

View File

@ -1102,7 +1102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
hir::ItemKind::TyAlias(ref ty, ref generics) => (&*ty, generics), hir::ItemKind::TyAlias(ref ty, ref generics) => (&*ty, generics),
_ => return, _ => return,
}; };
if let hir::TyKind::Def(..) = ty.kind { if let hir::TyKind::OpaqueDef(..) = ty.kind {
// Bounds are respected for `type X = impl Trait` // Bounds are respected for `type X = impl Trait`
return; return;
} }

View File

@ -304,7 +304,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
} }
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) { fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
if let TyKind::Def(item_id, _) = ty.kind { if let TyKind::OpaqueDef(item_id, _) = ty.kind {
let item = self.tcx.hir().expect_item(item_id.id); let item = self.tcx.hir().expect_item(item_id.id);
intravisit::walk_item(self, item); intravisit::walk_item(self, item);
} }

View File

@ -400,9 +400,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.with(scope, |_, this| intravisit::walk_item(this, item)); self.with(scope, |_, this| intravisit::walk_item(this, item));
} }
hir::ItemKind::OpaqueTy(hir::OpaqueTy { .. }) => { hir::ItemKind::OpaqueTy(hir::OpaqueTy { .. }) => {
// Opaque types are visited when we visit the `TyKind::Def`, so // Opaque types are visited when we visit the
// that they have the lifetimes from their parent opaque_ty in // `TyKind::OpaqueDef`, so that they have the lifetimes from
// scope. // their parent opaque_ty in scope.
} }
hir::ItemKind::TyAlias(_, ref generics) hir::ItemKind::TyAlias(_, ref generics)
| hir::ItemKind::Enum(_, ref generics) | hir::ItemKind::Enum(_, ref generics)
@ -557,7 +557,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}; };
self.with(scope, |_, this| this.visit_ty(&mt.ty)); self.with(scope, |_, this| this.visit_ty(&mt.ty));
} }
hir::TyKind::Def(item_id, lifetimes) => { hir::TyKind::OpaqueDef(item_id, lifetimes) => {
// Resolve the lifetimes in the bounds to the lifetime defs in the generics. // Resolve the lifetimes in the bounds to the lifetime defs in the generics.
// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to // `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
// `type MyAnonTy<'b> = impl MyTrait<'b>;` // `type MyAnonTy<'b> = impl MyTrait<'b>;`

View File

@ -1379,7 +1379,7 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
v.visit_expr(&map.body(anon_const.body).value) v.visit_expr(&map.body(anon_const.body).value)
}); });
} }
hir::TyKind::Def(item_id, _) => { hir::TyKind::OpaqueDef(item_id, _) => {
let item = self.tcx.hir().item(item_id.id); let item = self.tcx.hir().item(item_id.id);
self.nest_tables(self.tcx.hir().local_def_id(item_id.id), |v| v.visit_item(item)); self.nest_tables(self.tcx.hir().local_def_id(item_id.id), |v| v.visit_item(item));
} }

View File

@ -324,7 +324,7 @@ impl<'hir> Sig for hir::Ty<'hir> {
let text = format!("[{}; {}]", nested_ty.text, expr); let text = format!("[{}; {}]", nested_ty.text, expr);
Ok(replace_text(nested_ty, text)) Ok(replace_text(nested_ty, text))
} }
hir::TyKind::Def(item_id, _) => { hir::TyKind::OpaqueDef(item_id, _) => {
let item = scx.tcx.hir().item(item_id.id); let item = scx.tcx.hir().item(item_id.id);
item.make(offset, Some(item_id.id), scx) item.make(offset, Some(item_id.id), scx)
} }

View File

@ -2838,7 +2838,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself)); let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself));
self.res_to_ty(opt_self_ty, path, false) self.res_to_ty(opt_self_ty, path, false)
} }
hir::TyKind::Def(item_id, ref lifetimes) => { hir::TyKind::OpaqueDef(item_id, ref lifetimes) => {
let opaque_ty = tcx.hir().expect_item(item_id.id); let opaque_ty = tcx.hir().expect_item(item_id.id);
let def_id = tcx.hir().local_def_id(item_id.id).to_def_id(); let def_id = tcx.hir().local_def_id(item_id.id).to_def_id();

View File

@ -1494,7 +1494,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
let mut is_object_safe = false; let mut is_object_safe = false;
if let hir::FnRetTy::Return(ty) = fn_output { if let hir::FnRetTy::Return(ty) = fn_output {
// Get the return type. // Get the return type.
if let hir::TyKind::Def(..) = ty.kind { if let hir::TyKind::OpaqueDef(..) = ty.kind {
let ty = AstConv::ast_ty_to_ty(fcx, ty); let ty = AstConv::ast_ty_to_ty(fcx, ty);
// Get the `impl Trait`'s `DefId`. // Get the `impl Trait`'s `DefId`.
if let ty::Opaque(def_id, _) = ty.kind { if let ty::Opaque(def_id, _) = ty.kind {

View File

@ -1417,7 +1417,7 @@ fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool {
Slice(ty) | Array(ty, _) => is_suggestable_infer_ty(ty), Slice(ty) | Array(ty, _) => is_suggestable_infer_ty(ty),
Tup(tys) => tys.iter().any(is_suggestable_infer_ty), Tup(tys) => tys.iter().any(is_suggestable_infer_ty),
Ptr(mut_ty) | Rptr(_, mut_ty) => is_suggestable_infer_ty(mut_ty.ty), Ptr(mut_ty) | Rptr(_, mut_ty) => is_suggestable_infer_ty(mut_ty.ty),
Def(_, generic_args) => are_suggestable_generic_args(generic_args), OpaqueDef(_, generic_args) => are_suggestable_generic_args(generic_args),
Path(hir::QPath::TypeRelative(ty, segment)) => { Path(hir::QPath::TypeRelative(ty, segment)) => {
is_suggestable_infer_ty(ty) || are_suggestable_generic_args(segment.generic_args().args) is_suggestable_infer_ty(ty) || are_suggestable_generic_args(segment.generic_args().args)
} }

View File

@ -1351,7 +1351,7 @@ impl Clean<Type> for hir::Ty<'_> {
Array(box ty.clean(cx), length) Array(box ty.clean(cx), length)
} }
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)), TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
TyKind::Def(item_id, _) => { TyKind::OpaqueDef(item_id, _) => {
let item = cx.tcx.hir().expect_item(item_id.id); let item = cx.tcx.hir().expect_item(item_id.id);
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind { if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
ImplTrait(ty.bounds.clean(cx)) ImplTrait(ty.bounds.clean(cx))