Skip to content

Commit 7c7f58d

Browse files
committed
Fix case where ICE #90878 was still triggered by a leading newline
I cannot provide a test for that thanks to tidy.
1 parent d64aea6 commit 7c7f58d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -454,22 +454,20 @@ impl<'a> Resolver<'a> {
454454
// edit:
455455
// only do this if the const and usage of the non-constant value are on the same line
456456
// 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)
458458

459459
let sp =
460460
self.session.source_map().span_extend_to_prev_str(ident.span, current, true);
461461

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);
468463

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+
{
470468
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
471469
} 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));
473471
err.span_suggestion(
474472
sp,
475473
&format!("consider using `{}` instead of `{}`", sugg, current),

0 commit comments

Comments
 (0)