about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWesley Norris <repnop@outlook.com>2019-03-04 20:00:28 -0500
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-03-07 23:18:12 +0300
commit00887f39d199bc63730d0dd19f8726451fdd5758 (patch)
tree7b8d24073bfab72719ca5b2537c85c90dcf569c6
parent88f755f8a84df1d9e6b17cf10c96ae8b93481b2e (diff)
downloadrust-00887f39d199bc63730d0dd19f8726451fdd5758.tar.gz
rust-00887f39d199bc63730d0dd19f8726451fdd5758.zip
Adds diagnostic message and UI test.
-rw-r--r--src/libsyntax/parse/parser.rs10
-rw-r--r--src/test/ui/issues/issue-56031.rs5
-rw-r--r--src/test/ui/issues/issue-56031.stderr10
3 files changed, 24 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index fd5038a8614..330be1133ca 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -6716,8 +6716,16 @@ impl<'a> Parser<'a> {
             ast::ImplPolarity::Positive
         };
 
+        let possible_missing_trait = self.look_ahead(0, |t| t.is_keyword(keywords::For));
+
         // Parse both types and traits as a type, then reinterpret if necessary.
-        let ty_first = self.parse_ty()?;
+        let ty_first = self.parse_ty().map_err(|mut err| {
+            if possible_missing_trait {
+                err.help("did you forget a trait name after `impl`?");
+            }
+
+            err
+        })?;
 
         // If `for` is missing we try to recover.
         let has_for = self.eat_keyword(keywords::For);
diff --git a/src/test/ui/issues/issue-56031.rs b/src/test/ui/issues/issue-56031.rs
new file mode 100644
index 00000000000..7dbda3e46d1
--- /dev/null
+++ b/src/test/ui/issues/issue-56031.rs
@@ -0,0 +1,5 @@
+struct T;
+
+impl for T {}
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-56031.stderr b/src/test/ui/issues/issue-56031.stderr
new file mode 100644
index 00000000000..dd4f95341ff
--- /dev/null
+++ b/src/test/ui/issues/issue-56031.stderr
@@ -0,0 +1,10 @@
+error: expected `<`, found `T`
+  --> $DIR/issue-56031.rs:3:10
+   |
+LL | impl for T {}
+   |          ^ expected `<` here
+   |
+   = help: did you forget a trait name after `impl`?
+
+error: aborting due to previous error
+