Rollup merge of #58387 - alexreg:fix-trait-alias-2, r=centril
Disallow `auto` trait alias syntax See https://github.com/rust-lang/rust/issues/41517#issuecomment-462567679. r? @Centril CC @topecongiro @nikomatsakis
This commit is contained in:
commit
a5e869eb62
3 changed files with 28 additions and 1 deletions
|
@ -6538,8 +6538,14 @@ impl<'a> Parser<'a> {
|
||||||
let bounds = self.parse_generic_bounds()?;
|
let bounds = self.parse_generic_bounds()?;
|
||||||
tps.where_clause = self.parse_where_clause()?;
|
tps.where_clause = self.parse_where_clause()?;
|
||||||
self.expect(&token::Semi)?;
|
self.expect(&token::Semi)?;
|
||||||
|
if is_auto == IsAuto::Yes {
|
||||||
|
let msg = "trait aliases cannot be `auto`";
|
||||||
|
self.struct_span_err(self.prev_span, msg)
|
||||||
|
.span_label(self.prev_span, msg)
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
if unsafety != Unsafety::Normal {
|
if unsafety != Unsafety::Normal {
|
||||||
let msg = "trait aliases cannot be unsafe";
|
let msg = "trait aliases cannot be `unsafe`";
|
||||||
self.struct_span_err(self.prev_span, msg)
|
self.struct_span_err(self.prev_span, msg)
|
||||||
.span_label(self.prev_span, msg)
|
.span_label(self.prev_span, msg)
|
||||||
.emit();
|
.emit();
|
||||||
|
|
7
src/test/ui/traits/trait-alias-syntax.rs
Normal file
7
src/test/ui/traits/trait-alias-syntax.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#![feature(trait_alias)]
|
||||||
|
|
||||||
|
trait Foo {}
|
||||||
|
auto trait A = Foo; //~ ERROR trait aliases cannot be `auto`
|
||||||
|
unsafe trait B = Foo; //~ ERROR trait aliases cannot be `unsafe`
|
||||||
|
|
||||||
|
fn main() {}
|
14
src/test/ui/traits/trait-alias-syntax.stderr
Normal file
14
src/test/ui/traits/trait-alias-syntax.stderr
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
error: trait aliases cannot be `auto`
|
||||||
|
--> $DIR/trait-alias-syntax.rs:4:19
|
||||||
|
|
|
||||||
|
LL | auto trait A = Foo; //~ ERROR trait aliases cannot be `auto`
|
||||||
|
| ^ trait aliases cannot be `auto`
|
||||||
|
|
||||||
|
error: trait aliases cannot be `unsafe`
|
||||||
|
--> $DIR/trait-alias-syntax.rs:5:21
|
||||||
|
|
|
||||||
|
LL | unsafe trait B = Foo; //~ ERROR trait aliases cannot be `unsafe`
|
||||||
|
| ^ trait aliases cannot be `unsafe`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue