Skip to content

Commit 78b962a

Browse files
RPITIT placeholder items
1 parent c6861df commit 78b962a

File tree

21 files changed

+70
-2
lines changed

21 files changed

+70
-2
lines changed

compiler/rustc_hir/src/def.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ pub enum DefKind {
109109
InlineConst,
110110
/// Opaque type, aka `impl Trait`.
111111
OpaqueTy,
112+
/// A return-position `impl Trait` in a trait definition
113+
ImplTraitPlaceholder,
112114
Field,
113115
/// Lifetime parameter: the `'a` in `struct Foo<'a> { ... }`
114116
LifetimeParam,
@@ -138,6 +140,7 @@ impl DefKind {
138140
panic!("impossible struct constructor")
139141
}
140142
DefKind::OpaqueTy => "opaque type",
143+
DefKind::ImplTraitPlaceholder => "opaque type in trait",
141144
DefKind::TyAlias => "type alias",
142145
DefKind::TraitAlias => "trait alias",
143146
DefKind::AssocTy => "associated type",
@@ -190,6 +193,7 @@ impl DefKind {
190193
| DefKind::Variant
191194
| DefKind::Trait
192195
| DefKind::OpaqueTy
196+
| DefKind::ImplTraitPlaceholder
193197
| DefKind::TyAlias
194198
| DefKind::ForeignTy
195199
| DefKind::TraitAlias
@@ -254,6 +258,7 @@ impl DefKind {
254258
| DefKind::Use
255259
| DefKind::ForeignMod
256260
| DefKind::OpaqueTy
261+
| DefKind::ImplTraitPlaceholder
257262
| DefKind::Impl
258263
| DefKind::Field
259264
| DefKind::TyParam

compiler/rustc_hir/src/hir.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,12 @@ pub enum OpaqueTyOrigin {
25182518
TyAlias,
25192519
}
25202520

2521+
/// 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
2522+
#[derive(Debug, HashStable_Generic)]
2523+
pub struct ImplTraitPlaceholder<'hir> {
2524+
pub bounds: GenericBounds<'hir>,
2525+
}
2526+
25212527
/// The various kinds of types recognized by the compiler.
25222528
#[derive(Debug, HashStable_Generic)]
25232529
pub enum TyKind<'hir> {
@@ -2545,6 +2551,8 @@ pub enum TyKind<'hir> {
25452551
/// The generic argument list contains the lifetimes (and in the future
25462552
/// possibly parameters) that are actually bound on the `impl Trait`.
25472553
OpaqueDef(ItemId, &'hir [GenericArg<'hir>]),
2554+
/// The placeholder
2555+
ImplTraitInTrait(ItemId),
25482556
/// A trait object type `Bound1 + Bound2 + Bound3`
25492557
/// where `Bound` is a trait or a lifetime.
25502558
TraitObject(&'hir [PolyTraitRef<'hir>], &'hir Lifetime, TraitObjectSyntax),
@@ -3000,6 +3008,8 @@ pub enum ItemKind<'hir> {
30003008
TyAlias(&'hir Ty<'hir>, &'hir Generics<'hir>),
30013009
/// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`.
30023010
OpaqueTy(OpaqueTy<'hir>),
3011+
/// An `impl Trait` in a trait
3012+
ImplTraitPlaceholder(ImplTraitPlaceholder<'hir>),
30033013
/// An enum definition, e.g., `enum Foo<A, B> {C<A>, D<B>}`.
30043014
Enum(EnumDef<'hir>, &'hir Generics<'hir>),
30053015
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
@@ -3068,6 +3078,7 @@ impl ItemKind<'_> {
30683078
ItemKind::Trait(..) => "trait",
30693079
ItemKind::TraitAlias(..) => "trait alias",
30703080
ItemKind::Impl(..) => "implementation",
3081+
ItemKind::ImplTraitPlaceholder(..) => "opaque type in trait",
30713082
}
30723083
}
30733084
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,10 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
562562
walk_generics(visitor, generics);
563563
walk_list!(visitor, visit_param_bound, bounds);
564564
}
565+
ItemKind::ImplTraitPlaceholder(ImplTraitPlaceholder { bounds }) => {
566+
visitor.visit_id(item.hir_id());
567+
walk_list!(visitor, visit_param_bound, bounds);
568+
}
565569
ItemKind::Enum(ref enum_definition, ref generics) => {
566570
visitor.visit_generics(generics);
567571
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
@@ -674,6 +678,9 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
674678
visitor.visit_nested_item(item_id);
675679
walk_list!(visitor, visit_generic_arg, lifetimes);
676680
}
681+
TyKind::ImplTraitInTrait(item_id) => {
682+
visitor.visit_nested_item(item_id);
683+
}
677684
TyKind::Array(ref ty, ref length) => {
678685
visitor.visit_ty(ty);
679686
visitor.visit_array_length(length)

compiler/rustc_hir/src/target.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub enum Target {
3636
GlobalAsm,
3737
TyAlias,
3838
OpaqueTy,
39+
ImplTraitPlaceholder,
3940
Enum,
4041
Variant,
4142
Struct,
@@ -80,6 +81,7 @@ impl Target {
8081
ItemKind::GlobalAsm(..) => Target::GlobalAsm,
8182
ItemKind::TyAlias(..) => Target::TyAlias,
8283
ItemKind::OpaqueTy(..) => Target::OpaqueTy,
84+
ItemKind::ImplTraitPlaceholder(..) => Target::ImplTraitPlaceholder,
8385
ItemKind::Enum(..) => Target::Enum,
8486
ItemKind::Struct(..) => Target::Struct,
8587
ItemKind::Union(..) => Target::Union,
@@ -157,6 +159,7 @@ impl Target {
157159
Target::GlobalAsm => "global asm",
158160
Target::TyAlias => "type alias",
159161
Target::OpaqueTy => "opaque type",
162+
Target::ImplTraitPlaceholder => "opaque type in trait",
160163
Target::Enum => "enum",
161164
Target::Variant => "enum variant",
162165
Target::Struct => "struct",

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ impl<'a> State<'a> {
327327
self.print_ty_fn(f.abi, f.unsafety, f.decl, None, f.generic_params, f.param_names);
328328
}
329329
hir::TyKind::OpaqueDef(..) => self.word("/*impl Trait*/"),
330+
hir::TyKind::ImplTraitInTrait(..) => self.word("/*impl Trait*/"),
330331
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
331332
hir::TyKind::TraitObject(bounds, ref lifetime, syntax) => {
332333
if syntax == ast::TraitObjectSyntax::Dyn {
@@ -608,6 +609,9 @@ impl<'a> State<'a> {
608609
state.print_bounds("= impl", real_bounds);
609610
});
610611
}
612+
hir::ItemKind::ImplTraitPlaceholder(..) => {
613+
unreachable!("FIXME(RPITIT): I don't think this ever gets called here...");
614+
}
611615
hir::ItemKind::Enum(ref enum_definition, params) => {
612616
self.print_enum_def(enum_definition, params, item.ident.name, item.span);
613617
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
847847
| DefKind::Use
848848
| DefKind::ForeignMod
849849
| DefKind::OpaqueTy
850+
| DefKind::ImplTraitPlaceholder
850851
| DefKind::Impl
851852
| DefKind::Field => true,
852853
DefKind::TyParam
@@ -879,6 +880,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
879880
| DefKind::ForeignMod
880881
| DefKind::TyAlias
881882
| DefKind::OpaqueTy
883+
| DefKind::ImplTraitPlaceholder
882884
| DefKind::Enum
883885
| DefKind::Union
884886
| DefKind::Impl
@@ -967,6 +969,7 @@ fn should_encode_variances(def_kind: DefKind) -> bool {
967969
| DefKind::ForeignMod
968970
| DefKind::TyAlias
969971
| DefKind::OpaqueTy
972+
| DefKind::ImplTraitPlaceholder
970973
| DefKind::Impl
971974
| DefKind::Trait
972975
| DefKind::TraitAlias
@@ -1003,6 +1006,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
10031006
| DefKind::AnonConst
10041007
| DefKind::InlineConst
10051008
| DefKind::OpaqueTy
1009+
| DefKind::ImplTraitPlaceholder
10061010
| DefKind::Impl
10071011
| DefKind::Field
10081012
| DefKind::TyParam
@@ -1493,6 +1497,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14931497
}
14941498
hir::ItemKind::OpaqueTy(..) => {
14951499
self.encode_explicit_item_bounds(def_id);
1500+
EntryKind::OpaqueTy
14961501
}
14971502
hir::ItemKind::Enum(..) => {
14981503
let adt_def = self.tcx.adt_def(def_id);

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ fixed_size_enum! {
9090
( AnonConst )
9191
( InlineConst )
9292
( OpaqueTy )
93+
( ImplTraitPlaceholder )
9394
( Field )
9495
( LifetimeParam )
9596
( GlobalAsm )

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl<'hir> Map<'hir> {
213213
ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind),
214214
ItemKind::Mod(..) => DefKind::Mod,
215215
ItemKind::OpaqueTy(..) => DefKind::OpaqueTy,
216+
ItemKind::ImplTraitPlaceholder(..) => DefKind::ImplTraitPlaceholder,
216217
ItemKind::TyAlias(..) => DefKind::TyAlias,
217218
ItemKind::Enum(..) => DefKind::Enum,
218219
ItemKind::Struct(..) => DefKind::Struct,
@@ -1188,6 +1189,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
11881189
ItemKind::GlobalAsm(..) => "global asm",
11891190
ItemKind::TyAlias(..) => "ty",
11901191
ItemKind::OpaqueTy(..) => "opaque type",
1192+
ItemKind::ImplTraitPlaceholder(..) => "opaque type in trait",
11911193
ItemKind::Enum(..) => "enum",
11921194
ItemKind::Struct(..) => "struct",
11931195
ItemKind::Union(..) => "union",

compiler/rustc_monomorphize/src/polymorphize.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn mark_used_by_default_parameters<'tcx>(
170170
| DefKind::AnonConst
171171
| DefKind::InlineConst
172172
| DefKind::OpaqueTy
173+
| DefKind::ImplTraitPlaceholder
173174
| DefKind::Field
174175
| DefKind::LifetimeParam
175176
| DefKind::GlobalAsm

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ impl CheckAttrVisitor<'_> {
661661
| Target::GlobalAsm
662662
| Target::TyAlias
663663
| Target::OpaqueTy
664+
| Target::ImplTraitPlaceholder
664665
| Target::Enum
665666
| Target::Variant
666667
| Target::Struct

compiler/rustc_passes/src/reachable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ impl<'tcx> ReachableContext<'tcx> {
235235
hir::ItemKind::ExternCrate(_)
236236
| hir::ItemKind::Use(..)
237237
| hir::ItemKind::OpaqueTy(..)
238+
| hir::ItemKind::ImplTraitPlaceholder(..)
238239
| hir::ItemKind::TyAlias(..)
239240
| hir::ItemKind::Macro(..)
240241
| hir::ItemKind::Mod(..)

compiler/rustc_privacy/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
596596
| DefKind::ForeignTy
597597
| DefKind::Fn
598598
| DefKind::OpaqueTy
599+
| DefKind::ImplTraitPlaceholder
599600
| DefKind::AssocFn
600601
| DefKind::Trait
601602
| DefKind::TyParam
@@ -685,6 +686,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
685686
}
686687

687688
hir::ItemKind::OpaqueTy(..)
689+
| hir::ItemKind::ImplTraitPlaceholder(..)
688690
| hir::ItemKind::Use(..)
689691
| hir::ItemKind::Static(..)
690692
| hir::ItemKind::Const(..)
@@ -720,6 +722,9 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
720722
self.reach(item.def_id, exist_level).generics().predicates().ty();
721723
}
722724
}
725+
hir::ItemKind::ImplTraitPlaceholder(..) => {
726+
// FIXME(RPITIT): Do we need to do anything here?
727+
}
723728
// Visit everything.
724729
hir::ItemKind::Const(..)
725730
| hir::ItemKind::Static(..)

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
972972
| DefKind::TyAlias
973973
| DefKind::ForeignTy
974974
| DefKind::OpaqueTy
975+
| DefKind::ImplTraitPlaceholder
975976
| DefKind::TraitAlias
976977
| DefKind::AssocTy,
977978
_,

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
596596
}
597597
}
598598
}
599+
hir::ItemKind::ImplTraitPlaceholder(..) => {
600+
// FIXME(RPITIT): We don't need to do anything here, right?
601+
}
599602
hir::ItemKind::TyAlias(_, ref generics)
600603
| hir::ItemKind::Enum(_, ref generics)
601604
| hir::ItemKind::Struct(_, ref generics)

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ impl<'tcx> SaveContext<'tcx> {
685685
| HirDefKind::AssocTy
686686
| HirDefKind::Trait
687687
| HirDefKind::OpaqueTy
688+
| HirDefKind::ImplTraitPlaceholder
688689
| HirDefKind::TyParam,
689690
def_id,
690691
) => Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(def_id) }),

compiler/rustc_save_analysis/src/sig.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ impl<'hir> Sig for hir::Ty<'hir> {
320320
let item = scx.tcx.hir().item(item_id);
321321
item.make(offset, Some(item_id.hir_id()), scx)
322322
}
323+
hir::TyKind::ImplTraitInTrait(item_id) => {
324+
let item = scx.tcx.hir().item(item_id);
325+
item.make(offset, Some(item_id.hir_id()), scx)
326+
}
323327
hir::TyKind::Typeof(_) | hir::TyKind::Infer | hir::TyKind::Err => Err("Ty"),
324328
}
325329
}
@@ -562,6 +566,7 @@ impl<'hir> Sig for hir::Item<'hir> {
562566
hir::ItemKind::GlobalAsm(_) => Err("global asm"),
563567
hir::ItemKind::ExternCrate(_) => Err("extern crate"),
564568
hir::ItemKind::OpaqueTy(..) => Err("opaque type"),
569+
hir::ItemKind::ImplTraitPlaceholder(..) => Err("opaque type in trait"),
565570
// FIXME should implement this (e.g., pub use).
566571
hir::ItemKind::Use(..) => Err("import"),
567572
}

compiler/rustc_ty_utils/src/implied_bounds.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::List<Ty
5151
| DefKind::AnonConst
5252
| DefKind::InlineConst
5353
| DefKind::OpaqueTy
54+
| DefKind::ImplTraitPlaceholder
5455
| DefKind::Field
5556
| DefKind::LifetimeParam
5657
| DefKind::GlobalAsm

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26382638
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
26392639
}
26402640
}
2641+
hir::TyKind::ImplTraitInTrait(..) => {
2642+
span_bug!(ast_ty.span, "not yet implemented")
2643+
}
26412644
hir::TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => {
26422645
debug!(?qself, ?segment);
26432646
let ty = self.ast_ty_to_ty_inner(qself, false, true);

compiler/rustc_typeck/src/collect.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
815815
tcx.ensure().predicates_of(def_id);
816816
tcx.ensure().explicit_item_bounds(def_id);
817817
}
818+
hir::ItemKind::ImplTraitPlaceholder(..) => {
819+
tcx.ensure().generics_of(def_id);
820+
tcx.ensure().predicates_of(def_id);
821+
tcx.ensure().explicit_item_bounds(def_id);
822+
}
818823
hir::ItemKind::TyAlias(..)
819824
| hir::ItemKind::Static(..)
820825
| hir::ItemKind::Const(..)

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
336336
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner), .. }) => {
337337
find_opaque_ty_constraints_for_rpit(tcx, def_id, owner)
338338
}
339+
ItemKind::ImplTraitPlaceholder(..) => {
340+
span_bug!(item.span, "not yet implemented")
341+
}
339342
ItemKind::Trait(..)
340343
| ItemKind::TraitAlias(..)
341344
| ItemKind::Macro(..)

src/librustdoc/clean/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
511511
| Res::Err => return res.def_id(),
512512
Res::Def(
513513
TyParam | ConstParam | Ctor(..) | ExternCrate | Use | ForeignMod | AnonConst
514-
| InlineConst | OpaqueTy | Field | LifetimeParam | GlobalAsm | Impl | Closure
515-
| Generator,
514+
| InlineConst | OpaqueTy | ImplTraitPlaceholder | Field | LifetimeParam | GlobalAsm
515+
| Impl | Closure | Generator,
516516
id,
517517
) => return id,
518518
};

0 commit comments

Comments
 (0)