Handle generic parameters.
This commit is contained in:
parent
cdf78073c5
commit
05812df603
25 changed files with 171 additions and 224 deletions
|
@ -2505,6 +2505,7 @@ pub struct OpaqueTy<'hir> {
|
|||
pub generics: &'hir Generics<'hir>,
|
||||
pub bounds: GenericBounds<'hir>,
|
||||
pub origin: OpaqueTyOrigin,
|
||||
pub in_trait: bool,
|
||||
}
|
||||
|
||||
/// From whence the opaque type came.
|
||||
|
@ -2518,12 +2519,6 @@ pub enum OpaqueTyOrigin {
|
|||
TyAlias,
|
||||
}
|
||||
|
||||
/// Placeholder representation of an `impl Trait` in a trait. Since this never gets lowered into a `ty::Opaque` of its own, we just keep this as
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct ImplTraitPlaceholder<'hir> {
|
||||
pub bounds: GenericBounds<'hir>,
|
||||
}
|
||||
|
||||
/// The various kinds of types recognized by the compiler.
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub enum TyKind<'hir> {
|
||||
|
@ -2550,12 +2545,9 @@ pub enum TyKind<'hir> {
|
|||
///
|
||||
/// The generic argument list contains the lifetimes (and in the future
|
||||
/// possibly parameters) that are actually bound on the `impl Trait`.
|
||||
OpaqueDef(ItemId, &'hir [GenericArg<'hir>]),
|
||||
/// A type that represents an `impl Trait` in a trait function. This is
|
||||
/// not an opaque type, since it acts more like an associated type than
|
||||
/// an opaque, and since it needs no generics since it inherits those
|
||||
/// from the item's parent.
|
||||
ImplTraitInTrait(ItemId),
|
||||
///
|
||||
/// The last parameter specifies whether this opaque appears in a trait definition.
|
||||
OpaqueDef(ItemId, &'hir [GenericArg<'hir>], bool),
|
||||
/// A trait object type `Bound1 + Bound2 + Bound3`
|
||||
/// where `Bound` is a trait or a lifetime.
|
||||
TraitObject(&'hir [PolyTraitRef<'hir>], &'hir Lifetime, TraitObjectSyntax),
|
||||
|
@ -3011,8 +3003,6 @@ pub enum ItemKind<'hir> {
|
|||
TyAlias(&'hir Ty<'hir>, &'hir Generics<'hir>),
|
||||
/// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`.
|
||||
OpaqueTy(OpaqueTy<'hir>),
|
||||
/// An `impl Trait` in a trait
|
||||
ImplTraitPlaceholder(ImplTraitPlaceholder<'hir>),
|
||||
/// An enum definition, e.g., `enum Foo<A, B> {C<A>, D<B>}`.
|
||||
Enum(EnumDef<'hir>, &'hir Generics<'hir>),
|
||||
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
|
||||
|
@ -3081,7 +3071,6 @@ impl ItemKind<'_> {
|
|||
ItemKind::Trait(..) => "trait",
|
||||
ItemKind::TraitAlias(..) => "trait alias",
|
||||
ItemKind::Impl(..) => "implementation",
|
||||
ItemKind::ImplTraitPlaceholder(..) => "opaque type in trait",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -562,10 +562,6 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
|||
walk_generics(visitor, generics);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
ItemKind::ImplTraitPlaceholder(ImplTraitPlaceholder { bounds }) => {
|
||||
visitor.visit_id(item.hir_id());
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
ItemKind::Enum(ref enum_definition, ref generics) => {
|
||||
visitor.visit_generics(generics);
|
||||
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
|
||||
|
@ -674,13 +670,10 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
|
|||
TyKind::Path(ref qpath) => {
|
||||
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
|
||||
}
|
||||
TyKind::OpaqueDef(item_id, lifetimes) => {
|
||||
TyKind::OpaqueDef(item_id, lifetimes, _in_trait) => {
|
||||
visitor.visit_nested_item(item_id);
|
||||
walk_list!(visitor, visit_generic_arg, lifetimes);
|
||||
}
|
||||
TyKind::ImplTraitInTrait(item_id) => {
|
||||
visitor.visit_nested_item(item_id);
|
||||
}
|
||||
TyKind::Array(ref ty, ref length) => {
|
||||
visitor.visit_ty(ty);
|
||||
visitor.visit_array_length(length)
|
||||
|
|
|
@ -80,8 +80,13 @@ impl Target {
|
|||
ItemKind::ForeignMod { .. } => Target::ForeignMod,
|
||||
ItemKind::GlobalAsm(..) => Target::GlobalAsm,
|
||||
ItemKind::TyAlias(..) => Target::TyAlias,
|
||||
ItemKind::OpaqueTy(..) => Target::OpaqueTy,
|
||||
ItemKind::ImplTraitPlaceholder(..) => Target::ImplTraitPlaceholder,
|
||||
ItemKind::OpaqueTy(ref opaque) => {
|
||||
if opaque.in_trait {
|
||||
Target::ImplTraitPlaceholder
|
||||
} else {
|
||||
Target::OpaqueTy
|
||||
}
|
||||
}
|
||||
ItemKind::Enum(..) => Target::Enum,
|
||||
ItemKind::Struct(..) => Target::Struct,
|
||||
ItemKind::Union(..) => Target::Union,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue