File tree 4 files changed +43
-4
lines changed
compiler/rustc_parse/src/parser
4 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -698,11 +698,22 @@ impl<'a> Parser<'a> {
698
698
let semicolon_span = self . token . span ;
699
699
// We have to bail or we'll potentially never make progress.
700
700
let non_item_span = self . token . span ;
701
- self . consume_block ( Delimiter :: Brace , ConsumeClosingDelim :: Yes ) ;
701
+ let is_let = self . token . is_keyword ( kw:: Let ) ;
702
+
702
703
let mut err = self . struct_span_err ( non_item_span, "non-item in item list" ) ;
703
- err. span_label ( open_brace_span, "item list starts here" )
704
- . span_label ( non_item_span, "non-item starts here" )
705
- . span_label ( self . prev_token . span , "item list ends here" ) ;
704
+ self . consume_block ( Delimiter :: Brace , ConsumeClosingDelim :: Yes ) ;
705
+ if is_let {
706
+ err. span_suggestion (
707
+ non_item_span,
708
+ "consider using `const` instead of `let` for associated const" ,
709
+ "const" ,
710
+ Applicability :: MachineApplicable ,
711
+ ) ;
712
+ } else {
713
+ err. span_label ( open_brace_span, "item list starts here" )
714
+ . span_label ( non_item_span, "non-item starts here" )
715
+ . span_label ( self . prev_token . span , "item list ends here" ) ;
716
+ }
706
717
if is_unnecessary_semicolon {
707
718
err. span_suggestion (
708
719
semicolon_span,
Original file line number Diff line number Diff line change
1
+ // Issue: 101797, Suggest associated const for incorrect use of let in traits
2
+ // run-rustfix
3
+ trait Trait {
4
+ const _X: i32;
5
+ //~^ ERROR non-item in item list
6
+ }
7
+
8
+ fn main() {
9
+
10
+ }
Original file line number Diff line number Diff line change
1
+ // Issue: 101797, Suggest associated const for incorrect use of let in traits
2
+ // run-rustfix
3
+ trait Trait {
4
+ let _X: i32 ;
5
+ //~^ ERROR non-item in item list
6
+ }
7
+
8
+ fn main ( ) {
9
+
10
+ }
Original file line number Diff line number Diff line change
1
+ error: non-item in item list
2
+ --> $DIR/suggest-assoc-const.rs:4:5
3
+ |
4
+ LL | let _X: i32;
5
+ | ^^^ help: consider using `const` instead of `let` for associated const: `const`
6
+
7
+ error: aborting due to previous error
8
+
You can’t perform that action at this time.
0 commit comments