Skip to content

Commit

Permalink
Remove associated opaque types
Browse files Browse the repository at this point in the history
They're unused now.
  • Loading branch information
matthewjasper committed Jun 11, 2020
1 parent 4e49e67 commit 4201fd2
Show file tree
Hide file tree
Showing 36 changed files with 116 additions and 300 deletions.
8 changes: 1 addition & 7 deletions src/librustc_hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,6 +79,7 @@ pub enum DefKind {
Use,
ForeignMod,
AnonConst,
OpaqueTy,
Field,
LifetimeParam,
GlobalAsm,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -143,7 +139,6 @@ impl DefKind {
match *self {
DefKind::AssocTy
| DefKind::AssocConst
| DefKind::AssocOpaqueTy
| DefKind::AssocFn
| DefKind::Enum
| DefKind::OpaqueTy
Expand All @@ -168,7 +163,6 @@ impl DefKind {
| DefKind::ForeignTy
| DefKind::TraitAlias
| DefKind::AssocTy
| DefKind::AssocOpaqueTy
| DefKind::TyParam => ns == Namespace::TypeNS,

DefKind::Fn
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -2614,7 +2610,6 @@ pub enum AssocItemKind {
Const,
Fn { has_self: bool },
Type,
OpaqueTy,
}

#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/librustc_hir_pretty/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
};

Expand Down
7 changes: 2 additions & 5 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(..) => (),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ enum EntryKind {
Impl(Lazy<ImplData>),
AssocFn(Lazy<AssocFnData>),
AssocType(AssocContainer),
AssocOpaqueTy(AssocContainer),
AssocConst(AssocContainer, mir::ConstQualifs, Lazy<RenderedConst>),
TraitAlias,
}
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 2 additions & 15 deletions src/librustc_middle/traits/specialization_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
20 changes: 1 addition & 19 deletions src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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 => {
Expand All @@ -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))
}
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..) => {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
}
}
}
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(_) => false,
hir::ImplItemKind::TyAlias(_) => false,
}
}
Some(_) => false,
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 2 additions & 12 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
});

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
| DefKind::ForeignTy
| DefKind::OpaqueTy
| DefKind::TraitAlias
| DefKind::AssocTy
| DefKind::AssocOpaqueTy,
| DefKind::AssocTy,
_,
)
| Res::PrimTy(..)
Expand Down
Loading

0 comments on commit 4201fd2

Please sign in to comment.