parent
4e49e67c44
commit
4201fd273e
|
@ -54,15 +54,11 @@ pub enum DefKind {
|
|||
/// Refers to the variant itself, `DefKind::Ctor` refers to its constructor if it exists.
|
||||
Variant,
|
||||
Trait,
|
||||
/// `type Foo = impl Bar;`
|
||||
OpaqueTy,
|
||||
/// `type Foo = Bar;`
|
||||
TyAlias,
|
||||
ForeignTy,
|
||||
TraitAlias,
|
||||
AssocTy,
|
||||
/// `type Foo = impl Bar;`
|
||||
AssocOpaqueTy,
|
||||
TyParam,
|
||||
|
||||
// Value namespace
|
||||
|
@ -83,6 +79,7 @@ pub enum DefKind {
|
|||
Use,
|
||||
ForeignMod,
|
||||
AnonConst,
|
||||
OpaqueTy,
|
||||
Field,
|
||||
LifetimeParam,
|
||||
GlobalAsm,
|
||||
|
@ -115,7 +112,6 @@ impl DefKind {
|
|||
DefKind::TyAlias => "type alias",
|
||||
DefKind::TraitAlias => "trait alias",
|
||||
DefKind::AssocTy => "associated type",
|
||||
DefKind::AssocOpaqueTy => "associated opaque type",
|
||||
DefKind::Union => "union",
|
||||
DefKind::Trait => "trait",
|
||||
DefKind::ForeignTy => "foreign type",
|
||||
|
@ -143,7 +139,6 @@ impl DefKind {
|
|||
match *self {
|
||||
DefKind::AssocTy
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocOpaqueTy
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Enum
|
||||
| DefKind::OpaqueTy
|
||||
|
@ -168,7 +163,6 @@ impl DefKind {
|
|||
| DefKind::ForeignTy
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::AssocOpaqueTy
|
||||
| DefKind::TyParam => ns == Namespace::TypeNS,
|
||||
|
||||
DefKind::Fn
|
||||
|
|
|
@ -1919,14 +1919,12 @@ pub enum ImplItemKind<'hir> {
|
|||
Fn(FnSig<'hir>, BodyId),
|
||||
/// An associated type.
|
||||
TyAlias(&'hir Ty<'hir>),
|
||||
/// An associated `type = impl Trait`.
|
||||
OpaqueTy(GenericBounds<'hir>),
|
||||
}
|
||||
|
||||
impl ImplItemKind<'_> {
|
||||
pub fn namespace(&self) -> Namespace {
|
||||
match self {
|
||||
ImplItemKind::OpaqueTy(..) | ImplItemKind::TyAlias(..) => Namespace::TypeNS,
|
||||
ImplItemKind::TyAlias(..) => Namespace::TypeNS,
|
||||
ImplItemKind::Const(..) | ImplItemKind::Fn(..) => Namespace::ValueNS,
|
||||
}
|
||||
}
|
||||
|
@ -2016,8 +2014,6 @@ pub struct OpaqueTy<'hir> {
|
|||
/// From whence the opaque type came.
|
||||
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
|
||||
pub enum OpaqueTyOrigin {
|
||||
/// `type Foo = impl Trait;`
|
||||
TypeAlias,
|
||||
/// `-> impl Trait`
|
||||
FnReturn,
|
||||
/// `async fn`
|
||||
|
@ -2614,7 +2610,6 @@ pub enum AssocItemKind {
|
|||
Const,
|
||||
Fn { has_self: bool },
|
||||
Type,
|
||||
OpaqueTy,
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
|
||||
|
|
|
@ -1007,10 +1007,6 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
|||
visitor.visit_id(impl_item.hir_id);
|
||||
visitor.visit_ty(ty);
|
||||
}
|
||||
ImplItemKind::OpaqueTy(bounds) => {
|
||||
visitor.visit_id(impl_item.hir_id);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1003,12 +1003,6 @@ impl<'a> State<'a> {
|
|||
hir::ImplItemKind::TyAlias(ref ty) => {
|
||||
self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(bounds) => {
|
||||
self.word_space("type");
|
||||
self.print_ident(ii.ident);
|
||||
self.print_bounds("= impl", bounds);
|
||||
self.s.word(";");
|
||||
}
|
||||
}
|
||||
self.ann.post(self, AnnNode::SubItem(ii.hir_id))
|
||||
}
|
||||
|
|
|
@ -336,7 +336,6 @@ impl DirtyCleanVisitor<'tcx> {
|
|||
ImplItemKind::Fn(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL),
|
||||
ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL),
|
||||
ImplItemKind::TyAlias(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
|
||||
ImplItemKind::OpaqueTy(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
|
||||
},
|
||||
_ => self.tcx.sess.span_fatal(
|
||||
attr.span,
|
||||
|
|
|
@ -224,9 +224,7 @@ fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str {
|
|||
fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
|
||||
match item.kind {
|
||||
hir::ImplItemKind::Fn(..) => "method body",
|
||||
hir::ImplItemKind::Const(..)
|
||||
| hir::ImplItemKind::OpaqueTy(..)
|
||||
| hir::ImplItemKind::TyAlias(..) => "associated item",
|
||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(..) => "associated item",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -579,7 +579,6 @@ impl EntryKind {
|
|||
EntryKind::ConstParam => DefKind::ConstParam,
|
||||
EntryKind::OpaqueTy => DefKind::OpaqueTy,
|
||||
EntryKind::AssocType(_) => DefKind::AssocTy,
|
||||
EntryKind::AssocOpaqueTy(_) => DefKind::AssocOpaqueTy,
|
||||
EntryKind::Mod(_) => DefKind::Mod,
|
||||
EntryKind::Variant(_) => DefKind::Variant,
|
||||
EntryKind::Trait(_) => DefKind::Trait,
|
||||
|
@ -1145,7 +1144,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||
(ty::AssocKind::Fn, data.container, data.has_self)
|
||||
}
|
||||
EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
|
||||
EntryKind::AssocOpaqueTy(container) => (ty::AssocKind::OpaqueTy, container, false),
|
||||
_ => bug!("cannot get associated-item of `{:?}`", def_key),
|
||||
};
|
||||
|
||||
|
|
|
@ -874,7 +874,6 @@ impl EncodeContext<'tcx> {
|
|||
}))
|
||||
}
|
||||
ty::AssocKind::Type => EntryKind::AssocType(container),
|
||||
ty::AssocKind::OpaqueTy => span_bug!(ast_item.span, "opaque type in trait"),
|
||||
});
|
||||
record!(self.tables.visibility[def_id] <- trait_item.vis);
|
||||
record!(self.tables.span[def_id] <- ast_item.span);
|
||||
|
@ -892,7 +891,6 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_item_type(def_id);
|
||||
}
|
||||
}
|
||||
ty::AssocKind::OpaqueTy => unreachable!(),
|
||||
}
|
||||
if trait_item.kind == ty::AssocKind::Fn {
|
||||
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
||||
|
@ -957,7 +955,6 @@ impl EncodeContext<'tcx> {
|
|||
has_self: impl_item.fn_has_self_parameter,
|
||||
}))
|
||||
}
|
||||
ty::AssocKind::OpaqueTy => EntryKind::AssocOpaqueTy(container),
|
||||
ty::AssocKind::Type => EntryKind::AssocType(container)
|
||||
});
|
||||
record!(self.tables.visibility[def_id] <- impl_item.vis);
|
||||
|
@ -989,7 +986,7 @@ impl EncodeContext<'tcx> {
|
|||
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
|
||||
needs_inline || is_const_fn || always_encode_mir
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => false,
|
||||
hir::ImplItemKind::TyAlias(..) => false,
|
||||
};
|
||||
if mir {
|
||||
self.encode_optimized_mir(def_id.expect_local());
|
||||
|
@ -1786,7 +1783,7 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> {
|
|||
self.prefetch_mir(def_id)
|
||||
}
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => (),
|
||||
hir::ImplItemKind::TyAlias(..) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,7 +308,6 @@ enum EntryKind {
|
|||
Impl(Lazy<ImplData>),
|
||||
AssocFn(Lazy<AssocFnData>),
|
||||
AssocType(AssocContainer),
|
||||
AssocOpaqueTy(AssocContainer),
|
||||
AssocConst(AssocContainer, mir::ConstQualifs, Lazy<RenderedConst>),
|
||||
TraitAlias,
|
||||
}
|
||||
|
|
|
@ -228,7 +228,6 @@ impl<'hir> Map<'hir> {
|
|||
ImplItemKind::Const(..) => DefKind::AssocConst,
|
||||
ImplItemKind::Fn(..) => DefKind::AssocFn,
|
||||
ImplItemKind::TyAlias(..) => DefKind::AssocTy,
|
||||
ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy,
|
||||
},
|
||||
Node::Variant(_) => DefKind::Variant,
|
||||
Node::Ctor(variant_data) => {
|
||||
|
@ -1023,9 +1022,6 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String {
|
|||
ImplItemKind::TyAlias(_) => {
|
||||
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
|
||||
}
|
||||
ImplItemKind::OpaqueTy(_) => {
|
||||
format!("assoc opaque type {} in {}{}", ii.ident, path_str(), id_str)
|
||||
}
|
||||
},
|
||||
Some(Node::TraitItem(ti)) => {
|
||||
let kind = match ti.kind {
|
||||
|
|
|
@ -100,24 +100,11 @@ impl<'tcx> Node {
|
|||
trait_item_kind: ty::AssocKind,
|
||||
trait_def_id: DefId,
|
||||
) -> Option<ty::AssocItem> {
|
||||
use crate::ty::AssocKind::*;
|
||||
|
||||
tcx.associated_items(self.def_id())
|
||||
.filter_by_name_unhygienic(trait_item_name.name)
|
||||
.find(move |impl_item| {
|
||||
match (trait_item_kind, impl_item.kind) {
|
||||
| (Const, Const)
|
||||
| (Fn, Fn)
|
||||
| (Type, Type)
|
||||
| (Type, OpaqueTy) // assoc. types can be made opaque in impls
|
||||
=> tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id),
|
||||
|
||||
| (Const, _)
|
||||
| (Fn, _)
|
||||
| (Type, _)
|
||||
| (OpaqueTy, _)
|
||||
=> false,
|
||||
}
|
||||
trait_item_kind == impl_item.kind
|
||||
&& tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id)
|
||||
})
|
||||
.copied()
|
||||
}
|
||||
|
|
|
@ -814,7 +814,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
// FIXME: account for `#![feature(specialization)]`
|
||||
for item in &items[..] {
|
||||
match item.kind {
|
||||
hir::AssocItemKind::Type | hir::AssocItemKind::OpaqueTy => {
|
||||
hir::AssocItemKind::Type => {
|
||||
// FIXME: account for returning some type in a trait fn impl that has
|
||||
// an assoc type as a return type (#72076).
|
||||
if let hir::Defaultness::Default { has_value: true } = item.defaultness
|
||||
|
@ -838,7 +838,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
})) => {
|
||||
for item in &items[..] {
|
||||
match item.kind {
|
||||
hir::AssocItemKind::Type | hir::AssocItemKind::OpaqueTy => {
|
||||
hir::AssocItemKind::Type => {
|
||||
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
|
||||
db.span_label(item.span, "expected this associated type");
|
||||
return true;
|
||||
|
|
|
@ -198,14 +198,13 @@ pub struct AssocItem {
|
|||
pub enum AssocKind {
|
||||
Const,
|
||||
Fn,
|
||||
OpaqueTy,
|
||||
Type,
|
||||
}
|
||||
|
||||
impl AssocKind {
|
||||
pub fn namespace(&self) -> Namespace {
|
||||
match *self {
|
||||
ty::AssocKind::OpaqueTy | ty::AssocKind::Type => Namespace::TypeNS,
|
||||
ty::AssocKind::Type => Namespace::TypeNS,
|
||||
ty::AssocKind::Const | ty::AssocKind::Fn => Namespace::ValueNS,
|
||||
}
|
||||
}
|
||||
|
@ -215,22 +214,11 @@ impl AssocKind {
|
|||
AssocKind::Const => DefKind::AssocConst,
|
||||
AssocKind::Fn => DefKind::AssocFn,
|
||||
AssocKind::Type => DefKind::AssocTy,
|
||||
AssocKind::OpaqueTy => DefKind::AssocOpaqueTy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AssocItem {
|
||||
/// Tests whether the associated item admits a non-trivial implementation
|
||||
/// for !
|
||||
pub fn relevant_for_never(&self) -> bool {
|
||||
match self.kind {
|
||||
AssocKind::OpaqueTy | AssocKind::Const | AssocKind::Type => true,
|
||||
// FIXME(canndrew): Be more thorough here, check if any argument is uninhabited.
|
||||
AssocKind::Fn => !self.fn_has_self_parameter,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
|
||||
match self.kind {
|
||||
ty::AssocKind::Fn => {
|
||||
|
@ -241,8 +229,6 @@ impl AssocItem {
|
|||
tcx.fn_sig(self.def_id).skip_binder().to_string()
|
||||
}
|
||||
ty::AssocKind::Type => format!("type {};", self.ident),
|
||||
// FIXME(type_alias_impl_trait): we should print bounds here too.
|
||||
ty::AssocKind::OpaqueTy => format!("type {};", self.ident),
|
||||
ty::AssocKind::Const => {
|
||||
format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id))
|
||||
}
|
||||
|
@ -2581,10 +2567,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
.filter(|item| item.kind == AssocKind::Fn && item.defaultness.has_value())
|
||||
}
|
||||
|
||||
pub fn trait_relevant_for_never(self, did: DefId) -> bool {
|
||||
self.associated_items(did).in_definition_order().any(|item| item.relevant_for_never())
|
||||
}
|
||||
|
||||
pub fn opt_item_name(self, def_id: DefId) -> Option<Ident> {
|
||||
def_id
|
||||
.as_local()
|
||||
|
|
|
@ -37,7 +37,7 @@ fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>)
|
|||
Target::Method(MethodKind::Inherent)
|
||||
}
|
||||
}
|
||||
hir::ImplItemKind::TyAlias(..) | hir::ImplItemKind::OpaqueTy(..) => Target::AssocTy,
|
||||
hir::ImplItemKind::TyAlias(..) => Target::AssocTy,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -668,7 +668,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
|
|||
}
|
||||
self.visit_nested_body(body_id)
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => {}
|
||||
hir::ImplItemKind::TyAlias(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(_) => false,
|
||||
hir::ImplItemKind::TyAlias(_) => false,
|
||||
}
|
||||
}
|
||||
Some(_) => false,
|
||||
|
@ -289,7 +289,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
self.visit_nested_body(body)
|
||||
}
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(_) => {}
|
||||
hir::ImplItemKind::TyAlias(_) => {}
|
||||
},
|
||||
Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(.., body, _, _), .. }) => {
|
||||
self.visit_nested_body(body);
|
||||
|
|
|
@ -615,7 +615,6 @@ impl EmbargoVisitor<'tcx> {
|
|||
// public, or are not namespaced at all.
|
||||
DefKind::AssocConst
|
||||
| DefKind::AssocTy
|
||||
| DefKind::AssocOpaqueTy
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Ctor(_, _)
|
||||
| DefKind::Enum
|
||||
|
@ -1333,11 +1332,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
|
|||
_ => None,
|
||||
};
|
||||
let def = def.filter(|(kind, _)| match kind {
|
||||
DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocTy
|
||||
| DefKind::AssocOpaqueTy
|
||||
| DefKind::Static => true,
|
||||
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static => true,
|
||||
_ => false,
|
||||
});
|
||||
if let Some((kind, def_id)) = def {
|
||||
|
@ -1602,9 +1597,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
|||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => {
|
||||
self.access_levels.is_reachable(impl_item_ref.id.hir_id)
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(_) => {
|
||||
false
|
||||
}
|
||||
hir::ImplItemKind::TyAlias(_) => false,
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1952,9 +1945,6 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
|
|||
let (check_ty, is_assoc_ty) = match assoc_item_kind {
|
||||
AssocItemKind::Const | AssocItemKind::Fn { .. } => (true, false),
|
||||
AssocItemKind::Type => (defaultness.has_value(), true),
|
||||
// `ty()` for opaque types is the underlying type,
|
||||
// it's not a part of interface, so we skip it.
|
||||
AssocItemKind::OpaqueTy => (false, true),
|
||||
};
|
||||
check.in_assoc_ty = is_assoc_ty;
|
||||
check.generics().predicates();
|
||||
|
|
|
@ -916,8 +916,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
| DefKind::ForeignTy
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::AssocOpaqueTy,
|
||||
| DefKind::AssocTy,
|
||||
_,
|
||||
)
|
||||
| Res::PrimTy(..)
|
||||
|
|
|
@ -799,43 +799,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
this.visit_ty(ty);
|
||||
});
|
||||
}
|
||||
OpaqueTy(bounds) => {
|
||||
let generics = &impl_item.generics;
|
||||
let mut index = self.next_early_index();
|
||||
let mut next_early_index = index;
|
||||
debug!("visit_ty: index = {}", index);
|
||||
let lifetimes = generics
|
||||
.params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
Some(Region::early(&self.tcx.hir(), &mut index, param))
|
||||
}
|
||||
GenericParamKind::Type { .. } => {
|
||||
next_early_index += 1;
|
||||
None
|
||||
}
|
||||
GenericParamKind::Const { .. } => {
|
||||
next_early_index += 1;
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let scope = Scope::Binder {
|
||||
lifetimes,
|
||||
next_early_index,
|
||||
s: self.scope,
|
||||
track_lifetime_uses: true,
|
||||
opaque_type_parent: true,
|
||||
};
|
||||
self.with(scope, |_old_scope, this| {
|
||||
this.visit_generics(generics);
|
||||
for bound in bounds {
|
||||
this.visit_param_bound(bound);
|
||||
}
|
||||
});
|
||||
}
|
||||
Const(_, _) => {
|
||||
// Only methods and types support generics.
|
||||
assert!(impl_item.generics.params.is_empty());
|
||||
|
|
|
@ -1102,7 +1102,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
|||
impl_item.span,
|
||||
);
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) => {}
|
||||
hir::ImplItemKind::TyAlias(ref ty) => {
|
||||
// FIXME: uses of the assoc type should ideally point to this
|
||||
// 'def' and the name here should be a ref to the def in the
|
||||
|
|
|
@ -698,7 +698,6 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
|||
| HirDefKind::TyAlias
|
||||
| HirDefKind::ForeignTy
|
||||
| HirDefKind::TraitAlias
|
||||
| HirDefKind::AssocOpaqueTy
|
||||
| HirDefKind::AssocTy
|
||||
| HirDefKind::Trait
|
||||
| HirDefKind::OpaqueTy
|
||||
|
|
|
@ -11,7 +11,7 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
|
|||
use rustc_infer::infer::{self, InferCtxt, InferOk};
|
||||
use rustc_middle::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
|
||||
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::config::nightly_options;
|
||||
use rustc_span::Span;
|
||||
|
||||
|
@ -1059,21 +1059,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
|||
),
|
||||
origin,
|
||||
),
|
||||
_ => (def_scope_default(), hir::OpaqueTyOrigin::TypeAlias),
|
||||
},
|
||||
Some(Node::ImplItem(item)) => match item.kind {
|
||||
hir::ImplItemKind::OpaqueTy(_) => (
|
||||
may_define_opaque_type(
|
||||
tcx,
|
||||
self.parent_def_id.expect_local(),
|
||||
opaque_hir_id,
|
||||
),
|
||||
hir::OpaqueTyOrigin::TypeAlias,
|
||||
),
|
||||
_ => (def_scope_default(), hir::OpaqueTyOrigin::TypeAlias),
|
||||
_ => (def_scope_default(), hir::OpaqueTyOrigin::Misc),
|
||||
},
|
||||
_ => bug!(
|
||||
"expected (impl) item, found {}",
|
||||
"expected item, found {}",
|
||||
tcx.hir().node_to_string(opaque_hir_id),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ use rustc_errors::ErrorReported;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::lang_items::{FnOnceTraitLangItem, GeneratorTraitLangItem};
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
|
||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||
use rustc_middle::ty::subst::Subst;
|
||||
use rustc_middle::ty::util::IntTypeExt;
|
||||
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, WithConstness};
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
|
@ -1477,12 +1477,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
|||
let substs = obligation.predicate.substs.rebase_onto(tcx, trait_def_id, substs);
|
||||
let substs =
|
||||
translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.defining_node);
|
||||
let ty = if let ty::AssocKind::OpaqueTy = assoc_ty.item.kind {
|
||||
let item_substs = InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
|
||||
tcx.mk_opaque(assoc_ty.item.def_id, item_substs)
|
||||
} else {
|
||||
tcx.type_of(assoc_ty.item.def_id)
|
||||
};
|
||||
let ty = tcx.type_of(assoc_ty.item.def_id);
|
||||
if substs.len() != tcx.generics_of(assoc_ty.item.def_id).count() {
|
||||
tcx.sess
|
||||
.delay_span_bug(DUMMY_SP, "impl item and trait item have different parameter counts");
|
||||
|
@ -1515,7 +1510,7 @@ fn assoc_ty_def(
|
|||
// cycle error if the specialization graph is currently being built.
|
||||
let impl_node = specialization_graph::Node::Impl(impl_def_id);
|
||||
for item in impl_node.items(tcx) {
|
||||
if matches!(item.kind, ty::AssocKind::Type | ty::AssocKind::OpaqueTy)
|
||||
if matches!(item.kind, ty::AssocKind::Type)
|
||||
&& tcx.hygienic_eq(item.ident, assoc_ty_name, trait_def_id)
|
||||
{
|
||||
return Ok(specialization_graph::LeafDef {
|
||||
|
|
|
@ -85,7 +85,6 @@ fn associated_item_from_trait_item_ref(
|
|||
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
|
||||
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
|
||||
hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
|
||||
hir::AssocItemKind::OpaqueTy => bug!("only impls can have opaque types"),
|
||||
};
|
||||
|
||||
ty::AssocItem {
|
||||
|
@ -110,7 +109,6 @@ fn associated_item_from_impl_item_ref(
|
|||
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
|
||||
hir::AssocItemKind::Fn { has_self } => (ty::AssocKind::Fn, has_self),
|
||||
hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
|
||||
hir::AssocItemKind::OpaqueTy => (ty::AssocKind::OpaqueTy, false),
|
||||
};
|
||||
|
||||
ty::AssocItem {
|
||||
|
|
|
@ -1165,6 +1165,6 @@ fn assoc_item_kind_str(impl_item: &ty::AssocItem) -> &'static str {
|
|||
match impl_item.kind {
|
||||
ty::AssocKind::Const => "const",
|
||||
ty::AssocKind::Fn => "method",
|
||||
ty::AssocKind::Type | ty::AssocKind::OpaqueTy => "type",
|
||||
ty::AssocKind::Type => "type",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1556,7 +1556,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
match self.mode {
|
||||
Mode::MethodCall => item.fn_has_self_parameter,
|
||||
Mode::Path => match item.kind {
|
||||
ty::AssocKind::OpaqueTy | ty::AssocKind::Type => false,
|
||||
ty::AssocKind::Type => false,
|
||||
ty::AssocKind::Fn | ty::AssocKind::Const => true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -158,9 +158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let path = self.tcx.def_path_str(trait_ref.def_id);
|
||||
|
||||
let ty = match item.kind {
|
||||
ty::AssocKind::Const
|
||||
| ty::AssocKind::Type
|
||||
| ty::AssocKind::OpaqueTy => rcvr_ty,
|
||||
ty::AssocKind::Const | ty::AssocKind::Type => rcvr_ty,
|
||||
ty::AssocKind::Fn => self
|
||||
.tcx
|
||||
.fn_sig(item.def_id)
|
||||
|
|
|
@ -1943,7 +1943,6 @@ fn check_specialization_validity<'tcx>(
|
|||
let kind = match impl_item.kind {
|
||||
hir::ImplItemKind::Const(..) => ty::AssocKind::Const,
|
||||
hir::ImplItemKind::Fn(..) => ty::AssocKind::Fn,
|
||||
hir::ImplItemKind::OpaqueTy(..) => ty::AssocKind::OpaqueTy,
|
||||
hir::ImplItemKind::TyAlias(_) => ty::AssocKind::Type,
|
||||
};
|
||||
|
||||
|
@ -2114,7 +2113,7 @@ fn check_impl_items_against_trait<'tcx>(
|
|||
err.emit()
|
||||
}
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(_) => {
|
||||
hir::ImplItemKind::TyAlias(_) => {
|
||||
let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id);
|
||||
if ty_trait_item.kind == ty::AssocKind::Type {
|
||||
compare_ty_impl(
|
||||
|
@ -2367,8 +2366,6 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
|
|||
)
|
||||
}
|
||||
ty::AssocKind::Type => format!("type {} = Type;", assoc.ident),
|
||||
// FIXME(type_alias_impl_trait): we should print bounds here too.
|
||||
ty::AssocKind::OpaqueTy => format!("type {} = Type;", assoc.ident),
|
||||
ty::AssocKind::Const => {
|
||||
let ty = tcx.type_of(assoc.def_id);
|
||||
let val = expr::ty_kind_suggestion(ty).unwrap_or("value");
|
||||
|
|
|
@ -316,9 +316,6 @@ fn check_associated_item(
|
|||
fcx.register_wf_obligation(ty.into(), span, code.clone());
|
||||
}
|
||||
}
|
||||
ty::AssocKind::OpaqueTy => {
|
||||
// Do nothing: opaque types check themselves.
|
||||
}
|
||||
}
|
||||
|
||||
implied_bounds
|
||||
|
@ -900,102 +897,102 @@ fn check_opaque_types<'fcx, 'tcx>(
|
|||
if !def_id.is_local() {
|
||||
return ty;
|
||||
}
|
||||
let opaque_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
|
||||
let opaque_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
|
||||
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn: Some(_), .. }) =
|
||||
tcx.hir().expect_item(opaque_hir_id).kind
|
||||
{
|
||||
// Don't check return position impl trait.
|
||||
return ty;
|
||||
}
|
||||
if may_define_opaque_type(tcx, fn_def_id, opaque_hir_id) {
|
||||
trace!("check_opaque_types: may define, generics={:#?}", generics);
|
||||
let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default();
|
||||
for (i, arg) in substs.iter().enumerate() {
|
||||
let arg_is_param = match arg.unpack() {
|
||||
GenericArgKind::Type(ty) => matches!(ty.kind, ty::Param(_)),
|
||||
if may_define_opaque_type(tcx, fn_def_id, opaque_hir_id) {
|
||||
trace!("check_opaque_types: may define, generics={:#?}", generics);
|
||||
let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default();
|
||||
for (i, arg) in substs.iter().enumerate() {
|
||||
let arg_is_param = match arg.unpack() {
|
||||
GenericArgKind::Type(ty) => matches!(ty.kind, ty::Param(_)),
|
||||
|
||||
GenericArgKind::Lifetime(region) => {
|
||||
if let ty::ReStatic = region {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
"non-defining opaque type use in defining scope",
|
||||
)
|
||||
.span_label(
|
||||
tcx.def_span(generics.param_at(i, tcx).def_id),
|
||||
"cannot use static lifetime; use a bound lifetime \
|
||||
GenericArgKind::Lifetime(region) => {
|
||||
if let ty::ReStatic = region {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
"non-defining opaque type use in defining scope",
|
||||
)
|
||||
.span_label(
|
||||
tcx.def_span(generics.param_at(i, tcx).def_id),
|
||||
"cannot use static lifetime; use a bound lifetime \
|
||||
instead or remove the lifetime parameter from the \
|
||||
opaque type",
|
||||
)
|
||||
.emit();
|
||||
continue;
|
||||
}
|
||||
|
||||
true
|
||||
)
|
||||
.emit();
|
||||
continue;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
GenericArgKind::Const(ct) => matches!(ct.val, ty::ConstKind::Param(_)),
|
||||
};
|
||||
};
|
||||
|
||||
if arg_is_param {
|
||||
seen_params.entry(arg).or_default().push(i);
|
||||
} else {
|
||||
// Prevent `fn foo() -> Foo<u32>` from being defining.
|
||||
let opaque_param = generics.param_at(i, tcx);
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
"non-defining opaque type use in defining scope",
|
||||
)
|
||||
.span_note(
|
||||
tcx.def_span(opaque_param.def_id),
|
||||
&format!(
|
||||
"used non-generic {} `{}` for generic parameter",
|
||||
opaque_param.kind.descr(),
|
||||
arg,
|
||||
),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
} // for (arg, param)
|
||||
|
||||
for (_, indices) in seen_params {
|
||||
if indices.len() > 1 {
|
||||
let descr = generics.param_at(indices[0], tcx).kind.descr();
|
||||
let spans: Vec<_> = indices
|
||||
.into_iter()
|
||||
.map(|i| tcx.def_span(generics.param_at(i, tcx).def_id))
|
||||
.collect();
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
"non-defining opaque type use in defining scope",
|
||||
)
|
||||
.span_note(spans, &format!("{} used multiple times", descr))
|
||||
.emit();
|
||||
}
|
||||
if arg_is_param {
|
||||
seen_params.entry(arg).or_default().push(i);
|
||||
} else {
|
||||
// Prevent `fn foo() -> Foo<u32>` from being defining.
|
||||
let opaque_param = generics.param_at(i, tcx);
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
"non-defining opaque type use in defining scope",
|
||||
)
|
||||
.span_note(
|
||||
tcx.def_span(opaque_param.def_id),
|
||||
&format!(
|
||||
"used non-generic {} `{}` for generic parameter",
|
||||
opaque_param.kind.descr(),
|
||||
arg,
|
||||
),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
} // if may_define_opaque_type
|
||||
} // for (arg, param)
|
||||
|
||||
// Now register the bounds on the parameters of the opaque type
|
||||
// so the parameters given by the function need to fulfill them.
|
||||
//
|
||||
// type Foo<T: Bar> = impl Baz + 'static;
|
||||
// fn foo<U>() -> Foo<U> { .. *}
|
||||
//
|
||||
// becomes
|
||||
//
|
||||
// type Foo<T: Bar> = impl Baz + 'static;
|
||||
// fn foo<U: Bar>() -> Foo<U> { .. *}
|
||||
let predicates = tcx.predicates_of(def_id);
|
||||
trace!("check_opaque_types: may define, predicates={:#?}", predicates,);
|
||||
for &(pred, _) in predicates.predicates {
|
||||
let substituted_pred = pred.subst(fcx.tcx, substs);
|
||||
// Avoid duplication of predicates that contain no parameters, for example.
|
||||
if !predicates.predicates.iter().any(|&(p, _)| p == substituted_pred) {
|
||||
substituted_predicates.push(substituted_pred);
|
||||
for (_, indices) in seen_params {
|
||||
if indices.len() > 1 {
|
||||
let descr = generics.param_at(indices[0], tcx).kind.descr();
|
||||
let spans: Vec<_> = indices
|
||||
.into_iter()
|
||||
.map(|i| tcx.def_span(generics.param_at(i, tcx).def_id))
|
||||
.collect();
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
"non-defining opaque type use in defining scope",
|
||||
)
|
||||
.span_note(spans, &format!("{} used multiple times", descr))
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
} // if may_define_opaque_type
|
||||
|
||||
// Now register the bounds on the parameters of the opaque type
|
||||
// so the parameters given by the function need to fulfill them.
|
||||
//
|
||||
// type Foo<T: Bar> = impl Baz + 'static;
|
||||
// fn foo<U>() -> Foo<U> { .. *}
|
||||
//
|
||||
// becomes
|
||||
//
|
||||
// type Foo<T: Bar> = impl Baz + 'static;
|
||||
// fn foo<U: Bar>() -> Foo<U> { .. *}
|
||||
let predicates = tcx.predicates_of(def_id);
|
||||
trace!("check_opaque_types: may define, predicates={:#?}", predicates,);
|
||||
for &(pred, _) in predicates.predicates {
|
||||
let substituted_pred = pred.subst(fcx.tcx, substs);
|
||||
// Avoid duplication of predicates that contain no parameters, for example.
|
||||
if !predicates.predicates.iter().any(|&(p, _)| p == substituted_pred) {
|
||||
substituted_predicates.push(substituted_pred);
|
||||
}
|
||||
}
|
||||
} // if let Opaque
|
||||
ty
|
||||
},
|
||||
|
|
|
@ -742,7 +742,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
|
|||
hir::ImplItemKind::Fn(..) => {
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
}
|
||||
hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => {
|
||||
hir::ImplItemKind::TyAlias(_) => {
|
||||
// Account for `type T = _;`
|
||||
let mut visitor = PlaceholderHirTyCollector::default();
|
||||
visitor.visit_impl_item(impl_item);
|
||||
|
@ -1203,10 +1203,10 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
impl_trait_fn.or_else(|| {
|
||||
let parent_id = tcx.hir().get_parent_item(hir_id);
|
||||
assert!(parent_id != hir_id && parent_id != CRATE_HIR_ID);
|
||||
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
|
||||
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
|
||||
// Opaque types are always nested within another item, and
|
||||
// inherit the generics of the item.
|
||||
Some(tcx.hir().local_def_id(parent_id).to_def_id())
|
||||
Some(tcx.hir().local_def_id(parent_id).to_def_id())
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
|
@ -1704,31 +1704,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
|||
let ast_generics = match node {
|
||||
Node::TraitItem(item) => &item.generics,
|
||||
|
||||
Node::ImplItem(item) => match item.kind {
|
||||
ImplItemKind::OpaqueTy(ref bounds) => {
|
||||
ty::print::with_no_queries(|| {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let opaque_ty = tcx.mk_opaque(def_id, substs);
|
||||
debug!(
|
||||
"explicit_predicates_of({:?}): created opaque type {:?}",
|
||||
def_id, opaque_ty
|
||||
);
|
||||
|
||||
// Collect the bounds, i.e., the `A + B + 'c` in `impl A + B + 'c`.
|
||||
let bounds = AstConv::compute_bounds(
|
||||
&icx,
|
||||
opaque_ty,
|
||||
bounds,
|
||||
SizedByDefault::Yes,
|
||||
tcx.def_span(def_id),
|
||||
);
|
||||
|
||||
predicates.extend(bounds.predicates(tcx, opaque_ty));
|
||||
&item.generics
|
||||
})
|
||||
}
|
||||
_ => &item.generics,
|
||||
},
|
||||
Node::ImplItem(item) => &item.generics,
|
||||
|
||||
Node::Item(item) => {
|
||||
match item.kind {
|
||||
|
|
|
@ -64,13 +64,6 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
icx.to_ty(ty)
|
||||
}
|
||||
}
|
||||
ImplItemKind::OpaqueTy(_) => {
|
||||
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id).to_def_id()).is_none() {
|
||||
report_assoc_ty_on_inherent_impl(tcx, item.span);
|
||||
}
|
||||
|
||||
find_opaque_ty_constraints(tcx, def_id.expect_local())
|
||||
}
|
||||
ImplItemKind::TyAlias(ref ty) => {
|
||||
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id).to_def_id()).is_none() {
|
||||
report_assoc_ty_on_inherent_impl(tcx, item.span);
|
||||
|
|
|
@ -140,13 +140,6 @@ fn enforce_impl_params_are_constrained(
|
|||
Vec::new()
|
||||
}
|
||||
}
|
||||
ty::AssocKind::OpaqueTy => {
|
||||
// We don't know which lifetimes appear in the actual
|
||||
// opaque type, so use all of the lifetimes that appear
|
||||
// in the type's predicates.
|
||||
let predicates = tcx.predicates_of(def_id).instantiate_identity(tcx);
|
||||
cgp::parameters_for(&predicates, true)
|
||||
}
|
||||
ty::AssocKind::Fn | ty::AssocKind::Const => Vec::new(),
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1138,10 +1138,6 @@ impl Clean<Item> for hir::ImplItem<'_> {
|
|||
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
|
||||
TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
|
||||
}
|
||||
hir::ImplItemKind::OpaqueTy(ref bounds) => OpaqueTyItem(
|
||||
OpaqueTy { bounds: bounds.clean(cx), generics: Generics::default() },
|
||||
true,
|
||||
),
|
||||
};
|
||||
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
|
||||
Item {
|
||||
|
@ -1308,7 +1304,6 @@ impl Clean<Item> for ty::AssocItem {
|
|||
)
|
||||
}
|
||||
}
|
||||
ty::AssocKind::OpaqueTy => unimplemented!(),
|
||||
};
|
||||
|
||||
let visibility = match self.container {
|
||||
|
|
|
@ -379,7 +379,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
|||
TyKind::Path(ref path) => {
|
||||
self.collect_anonymous_lifetimes(path, ty);
|
||||
},
|
||||
TyKind::Def(item, _) => {
|
||||
TyKind::OpaqueDef(item, _) => {
|
||||
let map = self.cx.tcx.hir();
|
||||
if let ItemKind::OpaqueTy(ref exist_ty) = map.expect_item(item.id).kind {
|
||||
for bound in exist_ty.bounds {
|
||||
|
|
|
@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ManualAsyncFn {
|
|||
|
||||
fn future_trait_ref<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &'tcx Ty<'tcx>) -> Option<&'tcx TraitRef<'tcx>> {
|
||||
if_chain! {
|
||||
if let TyKind::Def(item_id, _) = ty.kind;
|
||||
if let TyKind::OpaqueDef(item_id, _) = ty.kind;
|
||||
let item = cx.tcx.hir().item(item_id.id);
|
||||
if let ItemKind::OpaqueTy(opaque) = &item.kind;
|
||||
if opaque.bounds.len() == 1;
|
||||
|
|
|
@ -710,7 +710,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||
segment.ident.name.hash(&mut self.s);
|
||||
},
|
||||
},
|
||||
TyKind::Def(_, arg_list) => {
|
||||
TyKind::OpaqueDef(_, arg_list) => {
|
||||
for arg in *arg_list {
|
||||
match arg {
|
||||
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
|
||||
|
|
Loading…
Reference in New Issue