File tree 4 files changed +52
-1
lines changed
compiler/rustc_parse/src/parser
4 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -493,7 +493,20 @@ impl<'a> Parser<'a> {
493
493
let ty_first = if self . token . is_keyword ( kw:: For ) && self . look_ahead ( 1 , |t| t != & token:: Lt )
494
494
{
495
495
let span = self . prev_token . span . between ( self . token . span ) ;
496
- self . struct_span_err ( span, "missing trait in a trait impl" ) . emit ( ) ;
496
+ self . struct_span_err ( span, "missing trait in a trait impl" )
497
+ . span_suggestion (
498
+ span,
499
+ "add a trait here" ,
500
+ " Trait " . into ( ) ,
501
+ Applicability :: HasPlaceholders ,
502
+ )
503
+ . span_suggestion (
504
+ span. to ( self . token . span ) ,
505
+ "for an inherent impl, drop this `for`" ,
506
+ "" . into ( ) ,
507
+ Applicability :: MaybeIncorrect ,
508
+ )
509
+ . emit ( ) ;
497
510
P ( Ty {
498
511
kind : TyKind :: Path ( None , err_path ( span) ) ,
499
512
span,
Original file line number Diff line number Diff line change @@ -3,6 +3,16 @@ error: missing trait in a trait impl
3
3
|
4
4
LL | impl for T {}
5
5
| ^
6
+ |
7
+ help: add a trait here
8
+ |
9
+ LL | impl Trait for T {}
10
+ | +++++
11
+ help: for an inherent impl, drop this `for`
12
+ |
13
+ LL - impl for T {}
14
+ LL + impl T {}
15
+ |
6
16
7
17
error: aborting due to previous error
8
18
Original file line number Diff line number Diff line change
1
+ // Regression test for #88818 (improve error message for missing trait
2
+ // in `impl for X`).
3
+
4
+ struct S { }
5
+ impl for S { }
6
+ //~^ ERROR: missing trait in a trait impl
7
+ //~| HELP: add a trait here
8
+ //~| HELP: for an inherent impl, drop this `for`
9
+
10
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: missing trait in a trait impl
2
+ --> $DIR/issue-88818.rs:5:5
3
+ |
4
+ LL | impl for S { }
5
+ | ^
6
+ |
7
+ help: add a trait here
8
+ |
9
+ LL | impl Trait for S { }
10
+ | +++++
11
+ help: for an inherent impl, drop this `for`
12
+ |
13
+ LL - impl for S { }
14
+ LL + impl S { }
15
+ |
16
+
17
+ error: aborting due to previous error
18
+
You can’t perform that action at this time.
0 commit comments