Skip to content

Commit cc6487d

Browse files
committed
Move extra help to a span_label
1 parent 8b66dc1 commit cc6487d

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/diagnostics.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn report_error<'tcx, 'mir>(
134134
) -> Option<i64> {
135135
use InterpError::*;
136136

137-
let (title, helps) = match &e.kind() {
137+
let (title, labels, helps) = match &e.kind() {
138138
MachineStop(info) => {
139139
let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
140140
use TerminationInfo::*;
@@ -146,6 +146,7 @@ pub fn report_error<'tcx, 'mir>(
146146
Deadlock => Some("deadlock"),
147147
MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None,
148148
};
149+
let mut labels = vec![];
149150
#[rustfmt::skip]
150151
let helps = match info {
151152
UnsupportedInIsolation(_) =>
@@ -154,17 +155,13 @@ pub fn report_error<'tcx, 'mir>(
154155
(None, format!("or pass `-Zmiri-isolation-error=warn to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
155156
],
156157
ExperimentalUb { url, help, .. } => {
157-
let mut helps = Vec::new();
158158
if let Some(help) = help {
159-
helps.push((Some(ecx.cur_span().data()), help.clone()));
159+
labels.push(help.clone());
160160
}
161-
helps.push(
162-
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental"))
163-
);
164-
helps.push(
161+
vec![
162+
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental")),
165163
(None, format!("see {} for further information", url))
166-
);
167-
helps
164+
]
168165
}
169166
MultipleSymbolDefinitions { first, first_crate, second, second_crate, .. } =>
170167
vec![
@@ -175,7 +172,7 @@ pub fn report_error<'tcx, 'mir>(
175172
vec![(Some(*span), format!("the `{}` symbol is defined here", link_name))],
176173
_ => vec![],
177174
};
178-
(title, helps)
175+
(title, labels, helps)
179176
}
180177
_ => {
181178
#[rustfmt::skip]
@@ -213,7 +210,7 @@ pub fn report_error<'tcx, 'mir>(
213210
],
214211
_ => vec![],
215212
};
216-
(Some(title), helps)
213+
(Some(title), vec![], helps)
217214
}
218215
};
219216

@@ -226,6 +223,7 @@ pub fn report_error<'tcx, 'mir>(
226223
DiagLevel::Error,
227224
&if let Some(title) = title { format!("{}: {}", title, msg) } else { msg.clone() },
228225
msg,
226+
labels,
229227
helps,
230228
&stacktrace,
231229
);
@@ -270,6 +268,7 @@ fn report_msg<'tcx>(
270268
diag_level: DiagLevel,
271269
title: &str,
272270
span_msg: String,
271+
labels: Vec<String>,
273272
mut helps: Vec<(Option<SpanData>, String)>,
274273
stacktrace: &[FrameInfo<'tcx>],
275274
) {
@@ -288,6 +287,12 @@ fn report_msg<'tcx>(
288287
err.note(&span_msg);
289288
err.note("(no span available)");
290289
}
290+
291+
// Add extra labels to the primary span.
292+
for label in labels {
293+
err.span_label(span, label);
294+
}
295+
291296
// Show help messages.
292297
if !helps.is_empty() {
293298
// Add visual separator before backtrace.
@@ -422,7 +427,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
422427
_ => ("tracking was triggered", DiagLevel::Note),
423428
};
424429

425-
report_msg(*this.tcx, diag_level, title, msg, vec![], &stacktrace);
430+
report_msg(*this.tcx, diag_level, title, msg, vec![], vec![], &stacktrace);
426431
}
427432
});
428433
}

0 commit comments

Comments
 (0)