File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
compiler/rustc_resolve/src Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -454,22 +454,20 @@ impl<'a> Resolver<'a> {
454
454
// edit:
455
455
// only do this if the const and usage of the non-constant value are on the same line
456
456
// the further the two are apart, the higher the chance of the suggestion being wrong
457
- // also make sure that this line isn't the first one (ICE #90878)
457
+ // also make sure that the pos for the suggestion is not 0 (ICE #90878)
458
458
459
459
let sp =
460
460
self . session . source_map ( ) . span_extend_to_prev_str ( ident. span , current, true ) ;
461
461
462
- let is_first_line = self
463
- . session
464
- . source_map ( )
465
- . lookup_line ( sp. lo ( ) )
466
- . map ( |file_and_line| file_and_line. line == 0 )
467
- . unwrap_or ( true ) ;
462
+ let pos_for_suggestion = sp. lo ( ) . 0 . saturating_sub ( current. len ( ) as u32 ) ;
468
463
469
- if sp. lo ( ) . 0 == 0 || self . session . source_map ( ) . is_multiline ( sp) || is_first_line {
464
+ if sp. lo ( ) . 0 == 0
465
+ || pos_for_suggestion == 0
466
+ || self . session . source_map ( ) . is_multiline ( sp)
467
+ {
470
468
err. span_label ( ident. span , & format ! ( "this would need to be a `{}`" , sugg) ) ;
471
469
} else {
472
- let sp = sp. with_lo ( BytePos ( sp . lo ( ) . 0 - current . len ( ) as u32 ) ) ;
470
+ let sp = sp. with_lo ( BytePos ( pos_for_suggestion ) ) ;
473
471
err. span_suggestion (
474
472
sp,
475
473
& format ! ( "consider using `{}` instead of `{}`" , sugg, current) ,
You can’t perform that action at this time.
0 commit comments