about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2021-11-16 22:16:47 +0100
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2021-11-16 22:16:47 +0100
commit7c7f58d5b7b5b453fde743bb058aa5770a37e57f (patch)
tree7eb51bd364170d8694e684292dfe64297c28dd7e
parentd64aea65ad3b994ed0e1503f836d82a9896ab468 (diff)
downloadrust-7c7f58d5b7b5b453fde743bb058aa5770a37e57f.tar.gz
rust-7c7f58d5b7b5b453fde743bb058aa5770a37e57f.zip
Fix case where ICE #90878 was still triggered by a leading newline
I cannot provide a test for that thanks to tidy.
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index e9680aae3f8..2e4cb4ff727 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -454,22 +454,20 @@ impl<'a> Resolver<'a> {
                 // edit:
                 // only do this if the const and usage of the non-constant value are on the same line
                 // the further the two are apart, the higher the chance of the suggestion being wrong
-                // also make sure that this line isn't the first one (ICE #90878)
+                // also make sure that the pos for the suggestion is not 0 (ICE #90878)
 
                 let sp =
                     self.session.source_map().span_extend_to_prev_str(ident.span, current, true);
 
-                let is_first_line = self
-                    .session
-                    .source_map()
-                    .lookup_line(sp.lo())
-                    .map(|file_and_line| file_and_line.line == 0)
-                    .unwrap_or(true);
+                let pos_for_suggestion = sp.lo().0.saturating_sub(current.len() as u32);
 
-                if sp.lo().0 == 0 || self.session.source_map().is_multiline(sp) || is_first_line {
+                if sp.lo().0 == 0
+                    || pos_for_suggestion == 0
+                    || self.session.source_map().is_multiline(sp)
+                {
                     err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
                 } else {
-                    let sp = sp.with_lo(BytePos(sp.lo().0 - current.len() as u32));
+                    let sp = sp.with_lo(BytePos(pos_for_suggestion));
                     err.span_suggestion(
                         sp,
                         &format!("consider using `{}` instead of `{}`", sugg, current),