Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8ca44ef

Browse files
committed
Auto merge of rust-lang#112988 - spastorino:new-rpitit-24, r=compiler-errors
Replace RPITIT current impl with new strategy that lowers as a GAT This PR replaces the current implementation of RPITITs with the new implementation that we had under -Zlower-impl-trait-in-trait-to-assoc-ty flag that lowers the RPIT as a GAT on the trait and on the impls that implement that trait. Opening this PR as a draft because this goes after rust-lang#112682, ~rust-lang#112981~ and ~rust-lang#112983~. As soon as those are merged, I can rebase and we should run perf, crater and test a lot. r? `@compiler-errors`
2 parents 05b82e5 + 20429af commit 8ca44ef

File tree

146 files changed

+1106
-586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1106
-586
lines changed

‎compiler/rustc_hir/src/def.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ 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,
114112
Field,
115113
/// Lifetime parameter: the `'a` in `struct Foo<'a> { ... }`
116114
LifetimeParam,
@@ -143,7 +141,6 @@ impl DefKind {
143141
DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct",
144142
DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct",
145143
DefKind::OpaqueTy => "opaque type",
146-
DefKind::ImplTraitPlaceholder => "opaque type in trait",
147144
DefKind::TyAlias => "type alias",
148145
DefKind::TraitAlias => "trait alias",
149146
DefKind::AssocTy => "associated type",
@@ -227,8 +224,7 @@ impl DefKind {
227224
| DefKind::Use
228225
| DefKind::ForeignMod
229226
| DefKind::GlobalAsm
230-
| DefKind::Impl { .. }
231-
| DefKind::ImplTraitPlaceholder => None,
227+
| DefKind::Impl { .. } => None,
232228
}
233229
}
234230

@@ -262,7 +258,6 @@ impl DefKind {
262258
| DefKind::Use
263259
| DefKind::ForeignMod
264260
| DefKind::OpaqueTy
265-
| DefKind::ImplTraitPlaceholder
266261
| DefKind::Impl { .. }
267262
| DefKind::Field
268263
| DefKind::TyParam

‎compiler/rustc_hir/src/target.rs‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub enum Target {
3636
GlobalAsm,
3737
TyAlias,
3838
OpaqueTy,
39-
ImplTraitPlaceholder,
4039
Enum,
4140
Variant,
4241
Struct,
@@ -80,13 +79,7 @@ impl Target {
8079
ItemKind::ForeignMod { .. } => Target::ForeignMod,
8180
ItemKind::GlobalAsm(..) => Target::GlobalAsm,
8281
ItemKind::TyAlias(..) => Target::TyAlias,
83-
ItemKind::OpaqueTy(ref opaque) => {
84-
if opaque.in_trait {
85-
Target::ImplTraitPlaceholder
86-
} else {
87-
Target::OpaqueTy
88-
}
89-
}
82+
ItemKind::OpaqueTy(..) => Target::OpaqueTy,
9083
ItemKind::Enum(..) => Target::Enum,
9184
ItemKind::Struct(..) => Target::Struct,
9285
ItemKind::Union(..) => Target::Union,
@@ -110,7 +103,6 @@ impl Target {
110103
DefKind::GlobalAsm => Target::GlobalAsm,
111104
DefKind::TyAlias => Target::TyAlias,
112105
DefKind::OpaqueTy => Target::OpaqueTy,
113-
DefKind::ImplTraitPlaceholder => Target::ImplTraitPlaceholder,
114106
DefKind::Enum => Target::Enum,
115107
DefKind::Struct => Target::Struct,
116108
DefKind::Union => Target::Union,
@@ -165,7 +157,6 @@ impl Target {
165157
Target::GlobalAsm => "global asm",
166158
Target::TyAlias => "type alias",
167159
Target::OpaqueTy => "opaque type",
168-
Target::ImplTraitPlaceholder => "opaque type in trait",
169160
Target::Enum => "enum",
170161
Target::Variant => "enum variant",
171162
Target::Struct => "struct",

‎compiler/rustc_hir_analysis/src/astconv/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21282128

21292129
let span = path.span;
21302130
match path.res {
2131-
Res::Def(DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder, did) => {
2131+
Res::Def(DefKind::OpaqueTy, did) => {
21322132
// Check for desugared `impl Trait`.
21332133
assert!(tcx.is_type_alias_impl_trait(did));
21342134
let item_segment = path.segments.split_last().unwrap();
@@ -2439,7 +2439,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24392439
// If this is an RPITIT and we are using the new RPITIT lowering scheme, we
24402440
// generate the def_id of an associated type for the trait and return as
24412441
// type a projection.
2442-
let def_id = if in_trait && tcx.lower_impl_trait_in_trait_to_assoc_ty(){
2442+
let def_id = if in_trait {
24432443
tcx.associated_type_for_impl_trait_in_trait(local_def_id).to_def_id()
24442444
} else {
24452445
local_def_id.to_def_id()

‎compiler/rustc_hir_analysis/src/check/check.rs‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,11 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
302302

303303
if let ItemKind::OpaqueTy(&hir::OpaqueTy {
304304
origin: hir::OpaqueTyOrigin::AsyncFn(..) | hir::OpaqueTyOrigin::FnReturn(..),
305-
in_trait,
306305
..
307306
}) = item.kind
308307
{
309308
let substs = InternalSubsts::identity_for_item(tcx, def_id);
310-
let opaque_identity_ty = if in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
311-
Ty::new_projection(tcx, def_id.to_def_id(), substs)
312-
} else {
313-
Ty::new_opaque(tcx, def_id.to_def_id(), substs)
314-
};
309+
let opaque_identity_ty = Ty::new_opaque(tcx, def_id.to_def_id(), substs);
315310
let mut visitor = ProhibitOpaqueVisitor {
316311
opaque_identity_ty,
317312
parent_count: tcx.generics_of(def_id).parent_count as u32,
@@ -576,17 +571,6 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
576571
check_opaque(tcx, id);
577572
}
578573
}
579-
DefKind::ImplTraitPlaceholder => {
580-
let parent = tcx.impl_trait_in_trait_parent_fn(id.owner_id.to_def_id());
581-
// Only check the validity of this opaque type if the function has a default body
582-
if let hir::Node::TraitItem(hir::TraitItem {
583-
kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)),
584-
..
585-
}) = tcx.hir().get_by_def_id(parent.expect_local())
586-
{
587-
check_opaque(tcx, id);
588-
}
589-
}
590574
DefKind::TyAlias => {
591575
let pty_ty = tcx.type_of(id.owner_id).subst_identity();
592576
let generics = tcx.generics_of(id.owner_id);

‎compiler/rustc_hir_analysis/src/collect/item_bounds.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,12 @@ pub(super) fn explicit_item_bounds(
113113
..
114114
}) => associated_type_bounds(tcx, def_id, bounds, *span),
115115
hir::Node::Item(hir::Item {
116-
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, in_trait,.. }),
116+
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }),
117117
span,
118118
..
119119
}) => {
120120
let substs = InternalSubsts::identity_for_item(tcx, def_id);
121-
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
122-
Ty::new_projection(tcx, def_id.to_def_id(), substs)
123-
} else {
124-
Ty::new_opaque(tcx, def_id.to_def_id(), substs)
125-
};
121+
let item_ty = Ty::new_opaque(tcx, def_id.to_def_id(), substs);
126122
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
127123
}
128124
hir::Node::Item(hir::Item { kind: hir::ItemKind::TyAlias(..), .. }) => &[],

‎compiler/rustc_hir_analysis/src/impl_wf_check.rs‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
109109
vec![]
110110
}
111111
}
112-
ty::AssocKind::Fn => {
113-
if !tcx.lower_impl_trait_in_trait_to_assoc_ty()
114-
&& item.defaultness(tcx).has_value()
115-
&& tcx.impl_method_has_trait_impl_trait_tys(item.def_id)
116-
&& let Ok(table) = tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
117-
{
118-
table.values().copied().flat_map(|ty| {
119-
cgp::parameters_for(&ty.subst_identity(), true)
120-
}).collect()
121-
} else {
122-
vec![]
123-
}
124-
}
125-
ty::AssocKind::Const => vec![],
112+
ty::AssocKind::Fn | ty::AssocKind::Const => vec![],
126113
}
127114
})
128115
.collect();

‎compiler/rustc_hir_analysis/src/variance/mod.rs‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
5656
let crate_map = tcx.crate_variances(());
5757
return crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]);
5858
}
59-
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder=> {
59+
DefKind::OpaqueTy => {
6060
return variance_of_opaque(tcx, item_def_id);
6161
}
6262
_ => {}
@@ -115,14 +115,6 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
115115
{
116116
self.visit_opaque(*def_id, substs)
117117
}
118-
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) check whether this is necessary
119-
// at all for RPITITs.
120-
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
121-
if self.tcx.is_impl_trait_in_trait(*def_id)
122-
&& !self.tcx.lower_impl_trait_in_trait_to_assoc_ty() =>
123-
{
124-
self.visit_opaque(*def_id, substs)
125-
}
126118
_ => t.super_visit_with(self),
127119
}
128120
}

‎compiler/rustc_metadata/src/rmeta/encoder.rs‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ fn should_encode_span(def_kind: DefKind) -> bool {
824824
| DefKind::AnonConst
825825
| DefKind::InlineConst
826826
| DefKind::OpaqueTy
827-
| DefKind::ImplTraitPlaceholder
828827
| DefKind::Field
829828
| DefKind::Impl { .. }
830829
| DefKind::Closure
@@ -867,7 +866,6 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
867866
| DefKind::AnonConst
868867
| DefKind::InlineConst
869868
| DefKind::OpaqueTy
870-
| DefKind::ImplTraitPlaceholder
871869
| DefKind::LifetimeParam
872870
| DefKind::GlobalAsm
873871
| DefKind::Generator => false,
@@ -902,7 +900,6 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
902900
| DefKind::AnonConst
903901
| DefKind::InlineConst
904902
| DefKind::OpaqueTy
905-
| DefKind::ImplTraitPlaceholder
906903
| DefKind::Field
907904
| DefKind::LifetimeParam
908905
| DefKind::GlobalAsm
@@ -939,7 +936,6 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
939936
| DefKind::AnonConst
940937
| DefKind::InlineConst
941938
| DefKind::OpaqueTy
942-
| DefKind::ImplTraitPlaceholder
943939
| DefKind::GlobalAsm
944940
| DefKind::Impl { .. }
945941
| DefKind::Closure
@@ -966,7 +962,6 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
966962
| DefKind::ForeignMod
967963
| DefKind::TyAlias
968964
| DefKind::OpaqueTy
969-
| DefKind::ImplTraitPlaceholder
970965
| DefKind::Enum
971966
| DefKind::Union
972967
| DefKind::Impl { .. }
@@ -1033,7 +1028,6 @@ fn should_encode_variances(def_kind: DefKind) -> bool {
10331028
| DefKind::Enum
10341029
| DefKind::Variant
10351030
| DefKind::OpaqueTy
1036-
| DefKind::ImplTraitPlaceholder
10371031
| DefKind::Fn
10381032
| DefKind::Ctor(..)
10391033
| DefKind::AssocFn => true,
@@ -1083,7 +1077,6 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
10831077
| DefKind::AnonConst
10841078
| DefKind::InlineConst
10851079
| DefKind::OpaqueTy
1086-
| DefKind::ImplTraitPlaceholder
10871080
| DefKind::Impl { .. }
10881081
| DefKind::Field
10891082
| DefKind::TyParam
@@ -1134,19 +1127,6 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
11341127
}
11351128
}
11361129

1137-
DefKind::ImplTraitPlaceholder => {
1138-
let parent_def_id = tcx.impl_trait_in_trait_parent_fn(def_id.to_def_id());
1139-
let assoc_item = tcx.associated_item(parent_def_id);
1140-
match assoc_item.container {
1141-
// Always encode an RPIT in an impl fn, since it always has a body
1142-
ty::AssocItemContainer::ImplContainer => true,
1143-
ty::AssocItemContainer::TraitContainer => {
1144-
// Encode an RPIT for a trait only if the trait has a default body
1145-
assoc_item.defaultness(tcx).has_value()
1146-
}
1147-
}
1148-
}
1149-
11501130
DefKind::AssocTy => {
11511131
let assoc_item = tcx.associated_item(def_id);
11521132
match assoc_item.container {
@@ -1192,7 +1172,6 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
11921172
| DefKind::Ctor(..)
11931173
| DefKind::TyAlias
11941174
| DefKind::OpaqueTy
1195-
| DefKind::ImplTraitPlaceholder
11961175
| DefKind::ForeignTy
11971176
| DefKind::Impl { .. }
11981177
| DefKind::AssocConst
@@ -1235,7 +1214,6 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
12351214
| DefKind::TyAlias
12361215
| DefKind::OpaqueTy
12371216
| DefKind::Impl { of_trait: false }
1238-
| DefKind::ImplTraitPlaceholder
12391217
| DefKind::ForeignTy
12401218
| DefKind::Generator
12411219
| DefKind::ConstParam
@@ -1268,7 +1246,6 @@ fn should_encode_const(def_kind: DefKind) -> bool {
12681246
| DefKind::Static(..)
12691247
| DefKind::TyAlias
12701248
| DefKind::OpaqueTy
1271-
| DefKind::ImplTraitPlaceholder
12721249
| DefKind::ForeignTy
12731250
| DefKind::Impl { .. }
12741251
| DefKind::AssocFn
@@ -1289,11 +1266,8 @@ fn should_encode_const(def_kind: DefKind) -> bool {
12891266
}
12901267
}
12911268

1292-
// We only encode impl trait in trait when using `lower-impl-trait-in-trait-to-assoc-ty` unstable
1293-
// option.
12941269
fn should_encode_fn_impl_trait_in_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
1295-
if tcx.lower_impl_trait_in_trait_to_assoc_ty()
1296-
&& let Some(assoc_item) = tcx.opt_associated_item(def_id)
1270+
if let Some(assoc_item) = tcx.opt_associated_item(def_id)
12971271
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
12981272
&& assoc_item.kind == ty::AssocKind::Fn
12991273
{
@@ -1447,9 +1421,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14471421
.is_type_alias_impl_trait
14481422
.set(def_id.index, self.tcx.is_type_alias_impl_trait(def_id));
14491423
}
1450-
if let DefKind::ImplTraitPlaceholder = def_kind {
1451-
self.encode_explicit_item_bounds(def_id);
1452-
}
14531424
if tcx.impl_method_has_trait_impl_trait_tys(def_id)
14541425
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
14551426
{

‎compiler/rustc_metadata/src/rmeta/table.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ fixed_size_enum! {
142142
( AnonConst )
143143
( InlineConst )
144144
( OpaqueTy )
145-
( ImplTraitPlaceholder )
146145
( Field )
147146
( LifetimeParam )
148147
( GlobalAsm )

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,7 @@ impl<'hir> Map<'hir> {
195195
ItemKind::Fn(..) => DefKind::Fn,
196196
ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind),
197197
ItemKind::Mod(..) => DefKind::Mod,
198-
ItemKind::OpaqueTy(ref opaque) => {
199-
if opaque.in_trait && !self.tcx.lower_impl_trait_in_trait_to_assoc_ty() {
200-
DefKind::ImplTraitPlaceholder
201-
} else {
202-
DefKind::OpaqueTy
203-
}
204-
}
198+
ItemKind::OpaqueTy(..) => DefKind::OpaqueTy,
205199
ItemKind::TyAlias(..) => DefKind::TyAlias,
206200
ItemKind::Enum(..) => DefKind::Enum,
207201
ItemKind::Struct(..) => DefKind::Struct,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /