Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f6a4e4

Browse files
authoredDec 4, 2024
Unrolled build for rust-lang#133768
Rollup merge of rust-lang#133768 - compiler-errors:gate, r=lcnr,jackh726 Remove `generic_associated_types_extended` feature gate This PR retires nightly support for the `generic_associated_types_extended` feature. This feature hasn't received much attention in the last two years or so, and I believe the feature still remains both unsound and ICEy to use. I think that if we were to redesign and reimplement it, we'd want to first figure out how to implement it soundly, but in the mean time I'd prefer to clean this up. r? ``@lcnr`` cc ``@jackh726`` who added this feature gate I think
2 parents c44b3d5 + f91fd0c commit 1f6a4e4

24 files changed

+300
-124
lines changed
 

‎compiler/rustc_feature/src/removed.rs

+7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ declare_features! (
119119
(removed, generator_clone, "1.65.0", Some(95360), Some("renamed to `coroutine_clone`")),
120120
/// Allows defining generators.
121121
(removed, generators, "1.21.0", Some(43122), Some("renamed to `coroutines`")),
122+
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
123+
(removed, generic_associated_types_extended, "CURRENT_RUSTC_VERSION", Some(95451),
124+
Some(
125+
"feature needs overhaul and reimplementation pending \
126+
better implied higher-ranked implied bounds support"
127+
)
128+
),
122129
/// Allows `impl Trait` in bindings (`let`, `const`, `static`).
123130
(removed, impl_trait_in_bindings, "1.55.0", Some(63065),
124131
Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")),

‎compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,6 @@ declare_features! (
499499
(unstable, gen_blocks, "1.75.0", Some(117078)),
500500
/// Infer generic args for both consts and types.
501501
(unstable, generic_arg_infer, "1.55.0", Some(85077)),
502-
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
503-
(incomplete, generic_associated_types_extended, "1.61.0", Some(95451)),
504502
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
505503
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
506504
/// Allows generic parameters and where-clauses on free & associated const items.

‎compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ pub fn dyn_compatibility_violations_for_assoc_item(
328328
.collect(),
329329
// Associated types can only be dyn-compatible if they have `Self: Sized` bounds.
330330
ty::AssocKind::Type => {
331-
if !tcx.features().generic_associated_types_extended()
332-
&& !tcx.generics_of(item.def_id).is_own_empty()
333-
&& !item.is_impl_trait_in_trait()
334-
{
331+
if !tcx.generics_of(item.def_id).is_own_empty() && !item.is_impl_trait_in_trait() {
335332
vec![DynCompatibilityViolation::GAT(item.name, item.ident(tcx).span)]
336333
} else {
337334
// We will permit associated types if they are explicitly mentioned in the trait object.

‎compiler/rustc_trait_selection/src/traits/project.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::traits::select::OverflowError;
1414
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ImplSourceUserDefinedData};
1515
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
1616
use rustc_middle::ty::fold::TypeFoldable;
17-
use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable, TypeVisitableExt};
17+
use rustc_middle::ty::visit::TypeVisitableExt;
1818
use rustc_middle::ty::{self, Term, Ty, TyCtxt, TypingMode, Upcast};
1919
use rustc_middle::{bug, span_bug};
2020
use rustc_span::symbol::sym;
@@ -179,35 +179,11 @@ pub(super) fn poly_project_and_unify_term<'cx, 'tcx>(
179179
) -> ProjectAndUnifyResult<'tcx> {
180180
let infcx = selcx.infcx;
181181
let r = infcx.commit_if_ok(|_snapshot| {
182-
let old_universe = infcx.universe();
183182
let placeholder_predicate = infcx.enter_forall_and_leak_universe(obligation.predicate);
184-
let new_universe = infcx.universe();
185183

186184
let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
187185
match project_and_unify_term(selcx, &placeholder_obligation) {
188186
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
189-
ProjectAndUnifyResult::Holds(obligations)
190-
if old_universe != new_universe
191-
&& selcx.tcx().features().generic_associated_types_extended() =>
192-
{
193-
// If the `generic_associated_types_extended` feature is active, then we ignore any
194-
// obligations references lifetimes from any universe greater than or equal to the
195-
// universe just created. Otherwise, we can end up with something like `for<'a> I: 'a`,
196-
// which isn't quite what we want. Ideally, we want either an implied
197-
// `for<'a where I: 'a> I: 'a` or we want to "lazily" check these hold when we
198-
// instantiate concrete regions. There is design work to be done here; until then,
199-
// however, this allows experimenting potential GAT features without running into
200-
// well-formedness issues.
201-
let new_obligations = obligations
202-
.into_iter()
203-
.filter(|obligation| {
204-
let mut visitor = MaxUniverse::new();
205-
obligation.predicate.visit_with(&mut visitor);
206-
visitor.max_universe() < new_universe
207-
})
208-
.collect();
209-
Ok(ProjectAndUnifyResult::Holds(new_obligations))
210-
}
211187
other => Ok(other),
212188
}
213189
});

‎compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
626626
for assoc_type in assoc_types {
627627
let defs: &ty::Generics = tcx.generics_of(assoc_type);
628628

629-
if !defs.own_params.is_empty() && !tcx.features().generic_associated_types_extended() {
629+
if !defs.own_params.is_empty() {
630630
tcx.dcx().span_delayed_bug(
631631
obligation.cause.span,
632632
"GATs in trait object shouldn't have been considered",

‎tests/crashes/131538.rs

-13
This file was deleted.

‎tests/ui/feature-gates/feature-gate-generic_associated_types_extended.rs

-4
This file was deleted.

‎tests/ui/feature-gates/feature-gate-generic_associated_types_extended.stderr

-12
This file was deleted.

‎tests/ui/generic-associated-types/extended/lending_iterator.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
//@ revisions: base extended
2-
//@[base] check-fail
3-
//@[extended] check-pass
4-
5-
#![cfg_attr(extended, feature(generic_associated_types_extended))]
6-
#![cfg_attr(extended, allow(incomplete_features))]
1+
//@ known-bug: #133805
72

83
pub trait FromLendingIterator<A>: Sized {
94
fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
105
}
116

127
impl<A> FromLendingIterator<A> for Vec<A> {
138
fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
14-
//[base]~^ impl has stricter
159
let mut v = vec![];
1610
while let Some(item) = iter.next() {
1711
v.push(item);
@@ -32,7 +26,6 @@ pub trait LendingIterator {
3226
Self: for<'q> LendingIterator<Item<'q> = A>,
3327
{
3428
<B as FromLendingIterator<A>>::from_iter(self)
35-
//[base]~^ ERROR: does not live long enough
3629
}
3730
}
3831

‎tests/ui/generic-associated-types/extended/lending_iterator.base.stderr ‎tests/ui/generic-associated-types/extended/lending_iterator.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0276]: impl has stricter requirements than trait
2-
--> $DIR/lending_iterator.rs:13:45
2+
--> $DIR/lending_iterator.rs:8:45
33
|
44
LL | fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
55
| ------------------------------------------------------------------------ definition of `from_iter` from trait
@@ -8,7 +8,7 @@ LL | fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) ->
88
| ^^^^^^^^^^^^ impl has extra requirement `I: 'x`
99

1010
error: `Self` does not live long enough
11-
--> $DIR/lending_iterator.rs:34:9
11+
--> $DIR/lending_iterator.rs:28:9
1212
|
1313
LL | <B as FromLendingIterator<A>>::from_iter(self)
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

‎tests/ui/generic-associated-types/extended/lending_iterator_2.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
//@ revisions: base extended
2-
//@[base] check-fail
3-
//@[extended] check-pass
4-
5-
#![cfg_attr(extended, feature(generic_associated_types_extended))]
6-
#![cfg_attr(extended, allow(incomplete_features))]
1+
//@ known-bug: #133805
72

83
pub trait FromLendingIterator<A>: Sized {
94
fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
105
}
116

127
impl<A> FromLendingIterator<A> for Vec<A> {
138
fn from_iter<I: for<'x> LendingIterator<Item<'x> = A>>(mut iter: I) -> Self {
14-
//[base]~^ impl has stricter
159
let mut v = vec![];
1610
while let Some(item) = iter.next() {
1711
v.push(item);

‎tests/ui/generic-associated-types/extended/lending_iterator_2.base.stderr ‎tests/ui/generic-associated-types/extended/lending_iterator_2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0276]: impl has stricter requirements than trait
2-
--> $DIR/lending_iterator_2.rs:13:45
2+
--> $DIR/lending_iterator_2.rs:8:45
33
|
44
LL | fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
55
| ------------------------------------------------------------------------ definition of `from_iter` from trait

‎tests/ui/generic-associated-types/gat-in-trait-path.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
//@ revisions: base extended
2-
//@[base] check-fail
3-
//@[extended] check-pass
1+
//@ check-fail
42

53
#![feature(associated_type_defaults)]
6-
#![cfg_attr(extended, feature(generic_associated_types_extended))]
7-
#![cfg_attr(extended, allow(incomplete_features))]
84

95
trait Foo {
106
type A<'a> where Self: 'a;
@@ -24,12 +20,12 @@ impl<T> Foo for Fooer<T> {
2420
}
2521

2622
fn f(_arg : Box<dyn for<'a> Foo<A<'a> = &'a ()>>) {}
27-
//[base]~^ the trait `Foo` cannot be made into an object
23+
//~^ the trait `Foo` cannot be made into an object
2824

2925

3026
fn main() {
3127
let foo = Fooer(5);
3228
f(Box::new(foo));
33-
//[base]~^ the trait `Foo` cannot be made into an object
34-
//[base]~| the trait `Foo` cannot be made into an object
29+
//~^ the trait `Foo` cannot be made into an object
30+
//~| the trait `Foo` cannot be made into an object
3531
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
error[E0038]: the trait `Foo` cannot be made into an object
2+
--> $DIR/gat-in-trait-path.rs:22:17
3+
|
4+
LL | fn f(_arg : Box<dyn for<'a> Foo<A<'a> = &'a ()>>) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object
6+
|
7+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
8+
--> $DIR/gat-in-trait-path.rs:6:10
9+
|
10+
LL | trait Foo {
11+
| --- this trait cannot be made into an object...
12+
LL | type A<'a> where Self: 'a;
13+
| ^ ...because it contains the generic associated type `A`
14+
= help: consider moving `A` to another trait
15+
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Foo` for this new enum and using it instead:
16+
Fooy
17+
Fooer<T>
18+
19+
error[E0038]: the trait `Foo` cannot be made into an object
20+
--> $DIR/gat-in-trait-path.rs:28:5
21+
|
22+
LL | f(Box::new(foo));
23+
| ^^^^^^^^^^^^^ `Foo` cannot be made into an object
24+
|
25+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
26+
--> $DIR/gat-in-trait-path.rs:6:10
27+
|
28+
LL | trait Foo {
29+
| --- this trait cannot be made into an object...
30+
LL | type A<'a> where Self: 'a;
31+
| ^ ...because it contains the generic associated type `A`
32+
= help: consider moving `A` to another trait
33+
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Foo` for this new enum and using it instead:
34+
Fooy
35+
Fooer<T>
36+
37+
error[E0038]: the trait `Foo` cannot be made into an object
38+
--> $DIR/gat-in-trait-path.rs:28:5
39+
|
40+
LL | f(Box::new(foo));
41+
| ^^^^^^^^^^^^^ `Foo` cannot be made into an object
42+
|
43+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
44+
--> $DIR/gat-in-trait-path.rs:6:10
45+
|
46+
LL | trait Foo {
47+
| --- this trait cannot be made into an object...
48+
LL | type A<'a> where Self: 'a;
49+
| ^ ...because it contains the generic associated type `A`
50+
= help: consider moving `A` to another trait
51+
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Foo` for this new enum and using it instead:
52+
Fooy
53+
Fooer<T>
54+
= note: required for the cast from `Box<Fooer<{integer}>>` to `Box<(dyn Foo<A<'a> = &'a ()> + 'static)>`
55+
56+
error: aborting due to 3 previous errors
57+
58+
For more information about this error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
//@ revisions: base extended
2-
//@[base] check-fail
3-
//@[extended] check-pass
4-
5-
#![cfg_attr(extended, feature(generic_associated_types_extended))]
6-
#![cfg_attr(extended, allow(incomplete_features))]
1+
//@ check-fail
72

83
trait X {
94
type Y<'a>;
105
}
116

127
fn _func1<'a>(_x: Box<dyn X<Y<'a>=&'a ()>>) {}
13-
//[base]~^ ERROR the trait `X` cannot be made into an object
8+
//~^ ERROR the trait `X` cannot be made into an object
149

1510
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0038]: the trait `X` cannot be made into an object
2+
--> $DIR/issue-67510-pass.rs:7:23
3+
|
4+
LL | fn _func1<'a>(_x: Box<dyn X<Y<'a>=&'a ()>>) {}
5+
| ^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
6+
|
7+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
8+
--> $DIR/issue-67510-pass.rs:4:10
9+
|
10+
LL | trait X {
11+
| - this trait cannot be made into an object...
12+
LL | type Y<'a>;
13+
| ^ ...because it contains the generic associated type `Y`
14+
= help: consider moving `Y` to another trait
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0038`.

‎tests/ui/generic-associated-types/issue-76535.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
//@ revisions: base extended
2-
3-
#![cfg_attr(extended, feature(generic_associated_types_extended))]
4-
#![cfg_attr(extended, allow(incomplete_features))]
5-
61
pub trait SubTrait {}
72

83
pub trait SuperTrait {
@@ -38,6 +33,6 @@ impl SuperTrait for SuperStruct {
3833
fn main() {
3934
let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
4035
//~^ ERROR missing generics for associated type
41-
//[base]~^^ ERROR the trait
42-
//[base]~| ERROR the trait
36+
//~^^ ERROR the trait
37+
//~| ERROR the trait
4338
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error[E0107]: missing generics for associated type `SuperTrait::SubType`
2+
--> $DIR/issue-76535.rs:34:33
3+
|
4+
LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
5+
| ^^^^^^^ expected 1 lifetime argument
6+
|
7+
note: associated type defined here, with 1 lifetime parameter: `'a`
8+
--> $DIR/issue-76535.rs:4:10
9+
|
10+
LL | type SubType<'a>: SubTrait where Self: 'a;
11+
| ^^^^^^^ --
12+
help: add missing lifetime argument
13+
|
14+
LL | let sub: Box<dyn SuperTrait<SubType<'a> = SubStruct>> = Box::new(SuperStruct::new(0));
15+
| ++++
16+
17+
error[E0038]: the trait `SuperTrait` cannot be made into an object
18+
--> $DIR/issue-76535.rs:34:14
19+
|
20+
LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object
22+
|
23+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
24+
--> $DIR/issue-76535.rs:4:10
25+
|
26+
LL | pub trait SuperTrait {
27+
| ---------- this trait cannot be made into an object...
28+
LL | type SubType<'a>: SubTrait where Self: 'a;
29+
| ^^^^^^^ ...because it contains the generic associated type `SubType`
30+
= help: consider moving `SubType` to another trait
31+
= help: only type `SuperStruct` is seen to implement the trait in this crate, consider using it directly instead
32+
= note: `SuperTrait` can be implemented in other crates; if you want to support your users passing their own types here, you can't refer to a specific type
33+
34+
error[E0038]: the trait `SuperTrait` cannot be made into an object
35+
--> $DIR/issue-76535.rs:34:57
36+
|
37+
LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object
39+
|
40+
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
41+
--> $DIR/issue-76535.rs:4:10
42+
|
43+
LL | pub trait SuperTrait {
44+
| ---------- this trait cannot be made into an object...
45+
LL | type SubType<'a>: SubTrait where Self: 'a;
46+
| ^^^^^^^ ...because it contains the generic associated type `SubType`
47+
= help: consider moving `SubType` to another trait
48+
= help: only type `SuperStruct` is seen to implement the trait in this crate, consider using it directly instead
49+
= note: `SuperTrait` can be implemented in other crates; if you want to support your users passing their own types here, you can't refer to a specific type
50+
= note: required for the cast from `Box<SuperStruct>` to `Box<dyn SuperTrait<SubType<'_> = SubStruct<'_>>>`
51+
52+
error: aborting due to 3 previous errors
53+
54+
Some errors have detailed explanations: E0038, E0107.
55+
For more information about an error, try `rustc --explain E0038`.
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.