Skip to content

Commit 03240e1

Browse files
committed
review comments
1 parent 10a9ea4 commit 03240e1

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/librustc_errors/emitter.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,11 @@ impl EmitterWriter {
14751475
Some(ref sm) => sm,
14761476
None => return Ok(()),
14771477
};
1478-
if !suggestion.has_valid_spans(&**sm) {
1478+
1479+
// Render the replacements for each suggestion
1480+
let suggestions = suggestion.splice_lines(&**sm);
1481+
1482+
if suggestions.is_empty() {
14791483
// Suggestions coming from macros can have malformed spans. This is a heavy handed
14801484
// approach to avoid ICEs by ignoring the suggestion outright.
14811485
return Ok(());
@@ -1497,9 +1501,6 @@ impl EmitterWriter {
14971501
Some(Style::HeaderMsg),
14981502
);
14991503

1500-
// Render the replacements for each suggestion
1501-
let suggestions = suggestion.splice_lines(&**sm);
1502-
15031504
let mut row_num = 2;
15041505
let mut notice_capitalization = false;
15051506
for (complete, parts, only_capitalization) in suggestions.iter().take(MAX_SUGGESTIONS) {

src/librustc_errors/lib.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,6 @@ pub struct SubstitutionPart {
144144
}
145145

146146
impl CodeSuggestion {
147-
/// Suggestions coming from macros can have malformed spans. This is a heavy handed approach
148-
/// to avoid ICEs by ignoring the suggestion outright.
149-
pub fn has_valid_spans(&self, cm: &SourceMap) -> bool {
150-
!self.substitutions.iter().any(|subst| {
151-
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
152-
if invalid {
153-
debug!("malformed span in suggestion: {:?}", subst);
154-
}
155-
invalid
156-
})
157-
}
158-
159147
/// Returns the assembled code suggestions, whether they should be shown with an underline
160148
/// and whether the substitution only differs in capitalization.
161149
pub fn splice_lines(&self, cm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
@@ -187,6 +175,15 @@ impl CodeSuggestion {
187175

188176
self.substitutions
189177
.iter()
178+
.filter(|subst| {
179+
// Suggestions coming from macros can have malformed spans. This is a heavy
180+
// handed approach to avoid ICEs by ignoring the suggestion outright.
181+
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
182+
if invalid {
183+
debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
184+
}
185+
!invalid
186+
})
190187
.cloned()
191188
.map(|mut substitution| {
192189
// Assumption: all spans are in the same file, and all spans

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:359:17
13+
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356: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)