Skip to content

Commit 0b68b78

Browse files
authored
Rollup merge of rust-lang#68530 - estebank:abolish-ice, r=petrochenkov
Do not ICE on multipart suggestions touching multiple files When encountering a multipart suggestion with spans belonging to different contexts, skip that suggestion. Fix rust-lang#68449. Similar to rust-lang#68256.
2 parents a24c77d + b626202 commit 0b68b78

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Diff for: src/librustc_errors/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,17 @@ impl CodeSuggestion {
185185
!invalid
186186
})
187187
.cloned()
188-
.map(|mut substitution| {
188+
.filter_map(|mut substitution| {
189189
// Assumption: all spans are in the same file, and all spans
190190
// are disjoint. Sort in ascending order.
191191
substitution.parts.sort_by_key(|part| part.span.lo());
192192

193193
// Find the bounding span.
194-
let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
195-
let hi = substitution.parts.iter().map(|part| part.span.hi()).max().unwrap();
194+
let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?;
195+
let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?;
196196
let bounding_span = Span::with_root_ctxt(lo, hi);
197-
let lines = cm.span_to_lines(bounding_span).unwrap();
197+
// The different spans might belong to different contexts, if so ignore suggestion.
198+
let lines = cm.span_to_lines(bounding_span).ok()?;
198199
assert!(!lines.lines.is_empty());
199200

200201
// To build up the result, we do this for each span:
@@ -244,7 +245,7 @@ impl CodeSuggestion {
244245
while buf.ends_with('\n') {
245246
buf.pop();
246247
}
247-
(buf, substitution.parts, only_capitalization)
248+
Some((buf, substitution.parts, only_capitalization))
248249
})
249250
.collect()
250251
}

Diff for: src/test/ui/consts/miri_unleashed/mutable_const2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: internal compiler error: mutable allocation in constant
1010
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17
13+
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:357:17
1414
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1515

1616
error: internal compiler error: unexpected panic

0 commit comments

Comments
 (0)