Skip to content

Commit 4968eea

Browse files
authored
Rollup merge of rust-lang#53364 - varkor:gat-warn-broken, r=pnkfelix
Warn if the user tries to use GATs GATs are currently broken, but still accessible behind a feature gate. This leads to people attempting to use them and then immediately encountering ICEs (or other broken behaviour). Here, we emit a warning if the user tries to use any feature associated with GATs, hopefully making it obvious that ICEs and the like are expected. For the meantime, this seems better than continually getting reported errors (for example: [here](https://github.com/rust-lang/rust/issues?q=is%3Aissue+gat+is%3Aclosed) and [here](https://github.com/rust-lang/rust/issues?utf8=%E2%9C%93&q=is%3Aissue+generic_associated_types+is%3Aclosed)).
2 parents 1cda84b + bc8cead commit 4968eea

21 files changed

+152
-47
lines changed

src/libsyntax/feature_gate.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,11 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19221922
err.emit();
19231923
}
19241924

1925+
// Some features are known to be incomplete and using them is likely to have
1926+
// unanticipated results, such as compiler crashes. We warn the user about these
1927+
// to alert them.
1928+
let incomplete_features = ["generic_associated_types"];
1929+
19251930
let mut features = Features::new();
19261931
let mut edition_enabled_features = FxHashMap();
19271932

@@ -1957,6 +1962,16 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19571962
continue
19581963
};
19591964

1965+
if incomplete_features.iter().any(|f| *f == name.as_str()) {
1966+
span_handler.struct_span_warn(
1967+
mi.span,
1968+
&format!(
1969+
"the feature `{}` is incomplete and may cause the compiler to crash",
1970+
name
1971+
)
1972+
).emit();
1973+
}
1974+
19601975
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
19611976
if *edition <= crate_edition {
19621977
continue

src/test/ui/rfc1598-generic-associated-types/collections.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
// except according to those terms.
1010

1111
#![feature(generic_associated_types)]
12+
//~^ WARNING the feature `generic_associated_types` is incomplete
1213
#![feature(associated_type_defaults)]
1314

14-
//FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
15-
//follow-up PR
15+
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
16+
// follow-up PR.
1617

1718
// A Collection trait and collection families. Based on
1819
// http://smallcultfollowing.com/babysteps/blog/2016/11/03/

src/test/ui/rfc1598-generic-associated-types/collections.stderr

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
2+
--> $DIR/collections.rs:11:12
3+
|
4+
LL | #![feature(generic_associated_types)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
17
error[E0109]: type parameters are not allowed on this type
2-
--> $DIR/collections.rs:65:90
8+
--> $DIR/collections.rs:66:90
39
|
410
LL | fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
511
| ^^^ type parameter not allowed
612

713
error[E0109]: type parameters are not allowed on this type
8-
--> $DIR/collections.rs:77:69
14+
--> $DIR/collections.rs:78:69
915
|
1016
LL | fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
1117
| ^^^ type parameter not allowed
1218

1319
error[E0109]: type parameters are not allowed on this type
14-
--> $DIR/collections.rs:26:71
20+
--> $DIR/collections.rs:27:71
1521
|
1622
LL | <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
1723
| ^ type parameter not allowed
1824

1925
error[E0110]: lifetime parameters are not allowed on this type
20-
--> $DIR/collections.rs:33:50
26+
--> $DIR/collections.rs:34:50
2127
|
2228
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
2329
| ^^^^^ lifetime parameter not allowed
2430

2531
error[E0110]: lifetime parameters are not allowed on this type
26-
--> $DIR/collections.rs:59:50
32+
--> $DIR/collections.rs:60:50
2733
|
2834
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
2935
| ^^^^^ lifetime parameter not allowed

src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
// except according to those terms.
1010

1111
#![feature(generic_associated_types)]
12+
//~^ WARNING the feature `generic_associated_types` is incomplete
1213

1314
use std::ops::Deref;
1415

15-
//FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
16-
//follow-up PR
16+
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
17+
// follow-up PR.
1718

1819
trait Foo {
1920
type Bar<'a, 'b>;

src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
2+
--> $DIR/construct_with_other_type.rs:11:12
3+
|
4+
LL | #![feature(generic_associated_types)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
17
error[E0110]: lifetime parameters are not allowed on this type
2-
--> $DIR/construct_with_other_type.rs:26:46
8+
--> $DIR/construct_with_other_type.rs:27:46
39
|
410
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
511
| ^^ lifetime parameter not allowed
612

713
error[E0110]: lifetime parameters are not allowed on this type
8-
--> $DIR/construct_with_other_type.rs:26:63
14+
--> $DIR/construct_with_other_type.rs:27:63
915
|
1016
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
1117
| ^^ lifetime parameter not allowed
1218

1319
error[E0110]: lifetime parameters are not allowed on this type
14-
--> $DIR/construct_with_other_type.rs:34:40
20+
--> $DIR/construct_with_other_type.rs:35:40
1521
|
1622
LL | type Baa<'a> = &'a <T as Foo>::Bar<'a, 'static>;
1723
| ^^ lifetime parameter not allowed

src/test/ui/rfc1598-generic-associated-types/empty_generics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(generic_associated_types)]
12+
//~^ WARNING the feature `generic_associated_types` is incomplete
1213

1314
trait Foo {
1415
type Bar<,>;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
error: expected one of `>`, identifier, or lifetime, found `,`
2-
--> $DIR/empty_generics.rs:14:14
2+
--> $DIR/empty_generics.rs:15:14
33
|
44
LL | type Bar<,>;
55
| ^ expected one of `>`, identifier, or lifetime here
66

7+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
8+
--> $DIR/empty_generics.rs:11:12
9+
|
10+
LL | #![feature(generic_associated_types)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
12+
713
error: aborting due to previous error
814

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// run-pass
12+
13+
#![feature(generic_associated_types)]
14+
//~^ WARNING the feature `generic_associated_types` is incomplete
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
2+
--> $DIR/gat-incomplete-warning.rs:13:12
3+
|
4+
LL | #![feature(generic_associated_types)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
2+
--> $DIR/generic-associated-types-where.rs:11:12
3+
|
4+
LL | #![feature(generic_associated_types)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+

src/test/ui/rfc1598-generic-associated-types/generic_associated_type_undeclared_lifetimes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
// except according to those terms.
1010

1111
#![feature(generic_associated_types)]
12+
//~^ WARNING the feature `generic_associated_types` is incomplete
1213

1314
use std::ops::Deref;
1415

15-
//FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
16-
//follow-up PR
16+
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
17+
// follow-up PR.
1718

1819
trait Iterable {
1920
type Item<'a>;

src/test/ui/rfc1598-generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
2+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:11:12
3+
|
4+
LL | #![feature(generic_associated_types)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
17
error[E0261]: use of undeclared lifetime name `'b`
2-
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:22:37
8+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:23:37
39
|
410
LL | + Deref<Target = Self::Item<'b>>;
511
| ^^ undeclared lifetime
612

713
error[E0261]: use of undeclared lifetime name `'undeclared`
8-
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:26:41
14+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:27:41
915
|
1016
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
1117
| ^^^^^^^^^^^ undeclared lifetime
1218

1319
error[E0110]: lifetime parameters are not allowed on this type
14-
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:20:47
20+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:21:47
1521
|
1622
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>>
1723
| ^^ lifetime parameter not allowed
1824

1925
error[E0110]: lifetime parameters are not allowed on this type
20-
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:22:37
26+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:23:37
2127
|
2228
LL | + Deref<Target = Self::Item<'b>>;
2329
| ^^ lifetime parameter not allowed
2430

2531
error[E0110]: lifetime parameters are not allowed on this type
26-
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:26:41
32+
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:27:41
2733
|
2834
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
2935
| ^^^^^^^^^^^ lifetime parameter not allowed

src/test/ui/rfc1598-generic-associated-types/iterable.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
// except according to those terms.
1010

1111
#![feature(generic_associated_types)]
12+
//~^ WARNING the feature `generic_associated_types` is incomplete
1213

1314
use std::ops::Deref;
1415

15-
//FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
16-
//follow-up PR
16+
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
17+
// follow-up PR.
1718

1819
trait Iterable {
1920
type Item<'a>;

src/test/ui/rfc1598-generic-associated-types/iterable.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
2+
--> $DIR/iterable.rs:11:12
3+
|
4+
LL | #![feature(generic_associated_types)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
17
error[E0110]: lifetime parameters are not allowed on this type
2-
--> $DIR/iterable.rs:20:47
8+
--> $DIR/iterable.rs:21:47
39
|
410
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>>;
511
| ^^ lifetime parameter not allowed
612

713
error[E0110]: lifetime parameters are not allowed on this type
8-
--> $DIR/iterable.rs:49:53
14+
--> $DIR/iterable.rs:50:53
915
|
1016
LL | fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> {
1117
| ^^ lifetime parameter not allowed
1218

1319
error[E0110]: lifetime parameters are not allowed on this type
14-
--> $DIR/iterable.rs:54:60
20+
--> $DIR/iterable.rs:55:60
1521
|
1622
LL | fn get_first<'a, I: Iterable>(it: &'a I) -> Option<I::Item<'a>> {
1723
| ^^ lifetime parameter not allowed
1824

1925
error[E0110]: lifetime parameters are not allowed on this type
20-
--> $DIR/iterable.rs:23:41
26+
--> $DIR/iterable.rs:24:41
2127
|
2228
LL | fn iter<'a>(&'a self) -> Self::Iter<'a>;
2329
| ^^ lifetime parameter not allowed
2430

2531
error[E0110]: lifetime parameters are not allowed on this type
26-
--> $DIR/iterable.rs:32:41
32+
--> $DIR/iterable.rs:33:41
2733
|
2834
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
2935
| ^^ lifetime parameter not allowed
3036

3137
error[E0110]: lifetime parameters are not allowed on this type
32-
--> $DIR/iterable.rs:43:41
38+
--> $DIR/iterable.rs:44:41
3339
|
3440
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
3541
| ^^ lifetime parameter not allowed

src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
// except according to those terms.
1010

1111
#![feature(generic_associated_types)]
12+
//~^ WARNING the feature `generic_associated_types` is incomplete
1213
#![feature(associated_type_defaults)]
1314

14-
//FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
15-
//follow-up PR
15+
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
16+
// follow-up PR.
1617

17-
//FIXME(#44265): Update expected errors once E110 is resolved, now does not get past `trait Foo`
18+
// FIXME(#44265): Update expected errors once E110 is resolved, now does not get past `trait Foo`.
1819

1920
trait Foo {
2021
type A<'a>;

src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
2+
--> $DIR/parameter_number_and_kind.rs:11:12
3+
|
4+
LL | #![feature(generic_associated_types)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
17
error[E0110]: lifetime parameters are not allowed on this type
2-
--> $DIR/parameter_number_and_kind.rs:26:27
8+
--> $DIR/parameter_number_and_kind.rs:27:27
39
|
410
LL | type FOk<T> = Self::E<'static, T>;
511
| ^^^^^^^ lifetime parameter not allowed
612

713
error[E0109]: type parameters are not allowed on this type
8-
--> $DIR/parameter_number_and_kind.rs:26:36
14+
--> $DIR/parameter_number_and_kind.rs:27:36
915
|
1016
LL | type FOk<T> = Self::E<'static, T>;
1117
| ^ type parameter not allowed
1218

1319
error[E0110]: lifetime parameters are not allowed on this type
14-
--> $DIR/parameter_number_and_kind.rs:29:26
20+
--> $DIR/parameter_number_and_kind.rs:30:26
1521
|
1622
LL | type FErr1 = Self::E<'static, 'static>; // Error
1723
| ^^^^^^^ lifetime parameter not allowed
1824

1925
error[E0110]: lifetime parameters are not allowed on this type
20-
--> $DIR/parameter_number_and_kind.rs:31:29
26+
--> $DIR/parameter_number_and_kind.rs:32:29
2127
|
2228
LL | type FErr2<T> = Self::E<'static, T, u32>; // Error
2329
| ^^^^^^^ lifetime parameter not allowed
2430

2531
error[E0109]: type parameters are not allowed on this type
26-
--> $DIR/parameter_number_and_kind.rs:31:38
32+
--> $DIR/parameter_number_and_kind.rs:32:38
2733
|
2834
LL | type FErr2<T> = Self::E<'static, T, u32>; // Error
2935
| ^ type parameter not allowed

src/test/ui/rfc1598-generic-associated-types/pointer_family.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// except according to those terms.
1010

1111
#![feature(generic_associated_types)]
12+
//~^ WARNING the feature `generic_associated_types` is incomplete
1213

13-
//FIXME(#44265): "type parameter not allowed" errors will be addressed in a follow-up PR
14+
// FIXME(#44265): "type parameter not allowed" errors will be addressed in a follow-up PR.
1415

1516
use std::rc::Rc;
1617
use std::sync::Arc;

0 commit comments

Comments
 (0)