Skip to content

Commit 5d2f31c

Browse files
committed
Continue evaluating after missing for in impl Trait for Foo
1 parent d8610b3 commit 5d2f31c

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6055,7 +6055,13 @@ impl<'a> Parser<'a> {
60556055
Some(ty_second) => {
60566056
// impl Trait for Type
60576057
if !has_for {
6058-
self.span_err(missing_for_span, "missing `for` in a trait impl");
6058+
self.struct_span_err(missing_for_span, "missing `for` in a trait impl")
6059+
.span_suggestion_short_with_applicability(
6060+
missing_for_span,
6061+
"add `for` here",
6062+
" for ".to_string(),
6063+
Applicability::MachineApplicable,
6064+
).emit();
60596065
}
60606066

60616067
let ty_first = ty_first.into_inner();

src/test/ui/parser/impl-parsing.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error: missing `for` in a trait impl
22
--> $DIR/impl-parsing.rs:6:11
33
|
44
LL | impl Trait Type {} //~ ERROR missing `for` in a trait impl
5-
| ^
5+
| ^ help: add `for` here
66

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

1313
error: expected a trait, found type
1414
--> $DIR/impl-parsing.rs:8:6

src/test/ui/parser/issue-27255.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
impl A .. {} //~ ERROR
1+
trait A {}
2+
3+
impl A .. {}
4+
//~^ ERROR missing `for` in a trait impl
5+
//~| ERROR `impl Trait for .. {}` is an obsolete syntax
6+
7+
impl A usize {}
8+
//~^ ERROR missing `for` in a trait impl
29

310
fn main() {}

src/test/ui/parser/issue-27255.stderr

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
error: missing `for` in a trait impl
2-
--> $DIR/issue-27255.rs:1:7
2+
--> $DIR/issue-27255.rs:3:7
33
|
4-
LL | impl A .. {} //~ ERROR
5-
| ^
4+
LL | impl A .. {}
5+
| ^ help: add `for` here
66

7-
error: aborting due to previous error
7+
error: missing `for` in a trait impl
8+
--> $DIR/issue-27255.rs:7:7
9+
|
10+
LL | impl A usize {}
11+
| ^^^^^^ help: add `for` here
12+
13+
error: `impl Trait for .. {}` is an obsolete syntax
14+
--> $DIR/issue-27255.rs:3:1
15+
|
16+
LL | impl A .. {}
17+
| ^^^^^^^^^^^^
18+
|
19+
= help: use `auto trait Trait {}` instead
20+
21+
error: aborting due to 3 previous errors
822

0 commit comments

Comments
 (0)