From aafbf742c2d93686e1a1b24c7c9ce3f0f9cc8921 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Tue, 12 Feb 2019 01:50:33 +0000 Subject: [PATCH 1/2] Disallow `auto` trait alias syntax. --- src/libsyntax/parse/parser.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 69d6407d506fb..8e22ac7ae0268 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6534,8 +6534,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(); From 370f1f26ce95defb2cf3cca838e74d9dc43e4829 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Tue, 12 Feb 2019 01:50:45 +0000 Subject: [PATCH 2/2] Added tests. --- src/test/ui/traits/trait-alias-syntax.rs | 7 +++++++ src/test/ui/traits/trait-alias-syntax.stderr | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/ui/traits/trait-alias-syntax.rs create mode 100644 src/test/ui/traits/trait-alias-syntax.stderr diff --git a/src/test/ui/traits/trait-alias-syntax.rs b/src/test/ui/traits/trait-alias-syntax.rs new file mode 100644 index 0000000000000..5948d45b6987f --- /dev/null +++ b/src/test/ui/traits/trait-alias-syntax.rs @@ -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() {} diff --git a/src/test/ui/traits/trait-alias-syntax.stderr b/src/test/ui/traits/trait-alias-syntax.stderr new file mode 100644 index 0000000000000..fc96f6274393d --- /dev/null +++ b/src/test/ui/traits/trait-alias-syntax.stderr @@ -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 +