Skip to content

Warn if the user tries to use GATs #53364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,11 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
err.emit();
}

// Some features are known to be incomplete and using them is likely to have
// unanticipated results, such as compiler crashes. We warn the user about these
// to alert them.
let incomplete_features = ["generic_associated_types"];

let mut features = Features::new();
let mut edition_enabled_features = FxHashMap();

Expand Down Expand Up @@ -1955,6 +1960,16 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
continue
};

if incomplete_features.iter().any(|f| *f == name.as_str()) {
span_handler.struct_span_warn(
mi.span,
&format!(
"the feature `{}` is incomplete and may cause the compiler to crash",
name
)
).emit();
}

if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
if *edition <= crate_edition {
continue
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/rfc1598-generic-associated-types/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
// except according to those terms.

#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete
#![feature(associated_type_defaults)]

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

// A Collection trait and collection families. Based on
// http://smallcultfollowing.com/babysteps/blog/2016/11/03/
Expand Down
16 changes: 11 additions & 5 deletions src/test/ui/rfc1598-generic-associated-types/collections.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/collections.rs:11:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0109]: type parameters are not allowed on this type
--> $DIR/collections.rs:65:90
--> $DIR/collections.rs:66:90
|
LL | fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
| ^^^ type parameter not allowed

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

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

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

error[E0110]: lifetime parameters are not allowed on this type
--> $DIR/collections.rs:59:50
--> $DIR/collections.rs:60:50
|
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
| ^^^^^ lifetime parameter not allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
// except according to those terms.

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

use std::ops::Deref;

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

trait Foo {
type Bar<'a, 'b>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/construct_with_other_type.rs:11:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

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

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

error[E0110]: lifetime parameters are not allowed on this type
--> $DIR/construct_with_other_type.rs:34:40
--> $DIR/construct_with_other_type.rs:35:40
|
LL | type Baa<'a> = &'a <T as Foo>::Bar<'a, 'static>;
| ^^ lifetime parameter not allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

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

trait Foo {
type Bar<,>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
error: expected one of `>`, identifier, or lifetime, found `,`
--> $DIR/empty_generics.rs:14:14
--> $DIR/empty_generics.rs:15:14
|
LL | type Bar<,>;
| ^ expected one of `>`, identifier, or lifetime here

warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/empty_generics.rs:11:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass

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

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/gat-incomplete-warning.rs:13:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/generic-associated-types-where.rs:11:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
// except according to those terms.

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

use std::ops::Deref;

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

trait Iterable {
type Item<'a>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:11:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:22:37
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:23:37
|
LL | + Deref<Target = Self::Item<'b>>;
| ^^ undeclared lifetime

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

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

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

error[E0110]: lifetime parameters are not allowed on this type
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:26:41
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:27:41
|
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
| ^^^^^^^^^^^ lifetime parameter not allowed
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/rfc1598-generic-associated-types/iterable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
// except according to those terms.

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

use std::ops::Deref;

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

trait Iterable {
type Item<'a>;
Expand Down
18 changes: 12 additions & 6 deletions src/test/ui/rfc1598-generic-associated-types/iterable.stderr
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/iterable.rs:11:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0110]: lifetime parameters are not allowed on this type
--> $DIR/iterable.rs:20:47
--> $DIR/iterable.rs:21:47
|
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>>;
| ^^ lifetime parameter not allowed

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

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

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

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

error[E0110]: lifetime parameters are not allowed on this type
--> $DIR/iterable.rs:43:41
--> $DIR/iterable.rs:44:41
|
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
| ^^ lifetime parameter not allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
// except according to those terms.

#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete
#![feature(associated_type_defaults)]

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

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

trait Foo {
type A<'a>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
warning: the feature `generic_associated_types` is incomplete and may cause the compiler to crash
--> $DIR/parameter_number_and_kind.rs:11:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0110]: lifetime parameters are not allowed on this type
--> $DIR/parameter_number_and_kind.rs:26:27
--> $DIR/parameter_number_and_kind.rs:27:27
|
LL | type FOk<T> = Self::E<'static, T>;
| ^^^^^^^ lifetime parameter not allowed

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

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

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

error[E0109]: type parameters are not allowed on this type
--> $DIR/parameter_number_and_kind.rs:31:38
--> $DIR/parameter_number_and_kind.rs:32:38
|
LL | type FErr2<T> = Self::E<'static, T, u32>; // Error
| ^ type parameter not allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
// except according to those terms.

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

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

use std::rc::Rc;
use std::sync::Arc;
Expand Down
Loading