Skip to content

Commit

Permalink
Move extra help to a span_label
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Mar 11, 2022
1 parent 8b66dc1 commit cc6487d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn report_error<'tcx, 'mir>(
) -> Option<i64> {
use InterpError::*;

let (title, helps) = match &e.kind() {
let (title, labels, helps) = match &e.kind() {
MachineStop(info) => {
let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
use TerminationInfo::*;
Expand All @@ -146,6 +146,7 @@ pub fn report_error<'tcx, 'mir>(
Deadlock => Some("deadlock"),
MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None,
};
let mut labels = vec![];
#[rustfmt::skip]
let helps = match info {
UnsupportedInIsolation(_) =>
Expand All @@ -154,17 +155,13 @@ pub fn report_error<'tcx, 'mir>(
(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")),
],
ExperimentalUb { url, help, .. } => {
let mut helps = Vec::new();
if let Some(help) = help {
helps.push((Some(ecx.cur_span().data()), help.clone()));
labels.push(help.clone());
}
helps.push(
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental"))
);
helps.push(
vec![
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental")),
(None, format!("see {} for further information", url))
);
helps
]
}
MultipleSymbolDefinitions { first, first_crate, second, second_crate, .. } =>
vec![
Expand All @@ -175,7 +172,7 @@ pub fn report_error<'tcx, 'mir>(
vec![(Some(*span), format!("the `{}` symbol is defined here", link_name))],
_ => vec![],
};
(title, helps)
(title, labels, helps)
}
_ => {
#[rustfmt::skip]
Expand Down Expand Up @@ -213,7 +210,7 @@ pub fn report_error<'tcx, 'mir>(
],
_ => vec![],
};
(Some(title), helps)
(Some(title), vec![], helps)
}
};

Expand All @@ -226,6 +223,7 @@ pub fn report_error<'tcx, 'mir>(
DiagLevel::Error,
&if let Some(title) = title { format!("{}: {}", title, msg) } else { msg.clone() },
msg,
labels,
helps,
&stacktrace,
);
Expand Down Expand Up @@ -270,6 +268,7 @@ fn report_msg<'tcx>(
diag_level: DiagLevel,
title: &str,
span_msg: String,
labels: Vec<String>,
mut helps: Vec<(Option<SpanData>, String)>,
stacktrace: &[FrameInfo<'tcx>],
) {
Expand All @@ -288,6 +287,12 @@ fn report_msg<'tcx>(
err.note(&span_msg);
err.note("(no span available)");
}

// Add extra labels to the primary span.
for label in labels {
err.span_label(span, label);
}

// Show help messages.
if !helps.is_empty() {
// Add visual separator before backtrace.
Expand Down Expand Up @@ -422,7 +427,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
_ => ("tracking was triggered", DiagLevel::Note),
};

report_msg(*this.tcx, diag_level, title, msg, vec![], &stacktrace);
report_msg(*this.tcx, diag_level, title, msg, vec![], vec![], &stacktrace);
}
});
}
Expand Down

0 comments on commit cc6487d

Please sign in to comment.