Skip to content

Commit

Permalink
Continue evaluating after missing for in impl Trait for Foo
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 12, 2019
1 parent d8610b3 commit 5d2f31c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -6055,7 +6055,13 @@ impl<'a> Parser<'a> {
Some(ty_second) => {
// impl Trait for Type
if !has_for {
self.span_err(missing_for_span, "missing `for` in a trait impl");
self.struct_span_err(missing_for_span, "missing `for` in a trait impl")
.span_suggestion_short_with_applicability(
missing_for_span,
"add `for` here",
" for ".to_string(),
Applicability::MachineApplicable,
).emit();
}

let ty_first = ty_first.into_inner();
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/impl-parsing.stderr
Expand Up @@ -2,13 +2,13 @@ error: missing `for` in a trait impl
--> $DIR/impl-parsing.rs:6:11
|
LL | impl Trait Type {} //~ ERROR missing `for` in a trait impl
| ^
| ^ help: add `for` here

error: missing `for` in a trait impl
--> $DIR/impl-parsing.rs:7:11
|
LL | impl Trait .. {} //~ ERROR missing `for` in a trait impl
| ^
| ^ help: add `for` here

error: expected a trait, found type
--> $DIR/impl-parsing.rs:8:6
Expand Down
9 changes: 8 additions & 1 deletion src/test/ui/parser/issue-27255.rs
@@ -1,3 +1,10 @@
impl A .. {} //~ ERROR
trait A {}

impl A .. {}
//~^ ERROR missing `for` in a trait impl
//~| ERROR `impl Trait for .. {}` is an obsolete syntax

impl A usize {}
//~^ ERROR missing `for` in a trait impl

fn main() {}
22 changes: 18 additions & 4 deletions src/test/ui/parser/issue-27255.stderr
@@ -1,8 +1,22 @@
error: missing `for` in a trait impl
--> $DIR/issue-27255.rs:1:7
--> $DIR/issue-27255.rs:3:7
|
LL | impl A .. {} //~ ERROR
| ^
LL | impl A .. {}
| ^ help: add `for` here

error: aborting due to previous error
error: missing `for` in a trait impl
--> $DIR/issue-27255.rs:7:7
|
LL | impl A usize {}
| ^^^^^^ help: add `for` here

error: `impl Trait for .. {}` is an obsolete syntax
--> $DIR/issue-27255.rs:3:1
|
LL | impl A .. {}
| ^^^^^^^^^^^^
|
= help: use `auto trait Trait {}` instead

error: aborting due to 3 previous errors

0 comments on commit 5d2f31c

Please sign in to comment.