Skip to content

Commit

Permalink
Rollup merge of rust-lang#58387 - alexreg:fix-trait-alias-2, r=centril
Browse files Browse the repository at this point in the history
Disallow `auto` trait alias syntax

See rust-lang#41517 (comment).

r? @Centril

CC @topecongiro @nikomatsakis
  • Loading branch information
Centril authored Feb 13, 2019
2 parents 5aa260a + 370f1f2 commit a5e869e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6538,8 +6538,14 @@ impl<'a> Parser<'a> {
let bounds = self.parse_generic_bounds()?;
tps.where_clause = self.parse_where_clause()?;
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 {
let msg = "trait aliases cannot be unsafe";
let msg = "trait aliases cannot be `unsafe`";
self.struct_span_err(self.prev_span, msg)
.span_label(self.prev_span, msg)
.emit();
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/traits/trait-alias-syntax.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions src/test/ui/traits/trait-alias-syntax.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a5e869e

Please sign in to comment.