add and use struct_help
This commit is contained in:
parent
89a184a399
commit
19122ab981
2 changed files with 21 additions and 21 deletions
|
@ -619,6 +619,11 @@ impl Handler {
|
|||
DiagnosticBuilder::new(self, Level::Fatal, msg)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Help` level with the `msg`.
|
||||
pub fn struct_help(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
||||
DiagnosticBuilder::new(self, Level::Help, msg)
|
||||
}
|
||||
|
||||
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: &str) -> FatalError {
|
||||
self.emit_diag_at_span(Diagnostic::new(Fatal, msg), span);
|
||||
FatalError
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::collections::BTreeMap;
|
|||
use log::debug;
|
||||
use rustc::{hir::def_id::DefId, infer::InferCtxt, mir::Body, ty::RegionVid};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{Diagnostic, DiagnosticBuilder, Level};
|
||||
use rustc_errors::{Diagnostic, DiagnosticBuilder};
|
||||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
|
@ -258,29 +258,24 @@ impl OutlivesSuggestionBuilder {
|
|||
// If there is exactly one suggestable constraints, then just suggest it. Otherwise, emit a
|
||||
// list of diagnostics.
|
||||
let mut diag = if suggested.len() == 1 {
|
||||
DiagnosticBuilder::new(
|
||||
infcx.tcx.sess.diagnostic(),
|
||||
Level::Help,
|
||||
&match suggested.last().unwrap() {
|
||||
SuggestedConstraint::Outlives(a, bs) => {
|
||||
let bs: SmallVec<[String; 2]> =
|
||||
bs.iter().map(|r| format!("{}", r)).collect();
|
||||
format!("add bound `{}: {}`", a, bs.join(" + "))
|
||||
}
|
||||
infcx.tcx.sess.diagnostic().struct_help(&match suggested.last().unwrap() {
|
||||
SuggestedConstraint::Outlives(a, bs) => {
|
||||
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| format!("{}", r)).collect();
|
||||
format!("add bound `{}: {}`", a, bs.join(" + "))
|
||||
}
|
||||
|
||||
SuggestedConstraint::Equal(a, b) => {
|
||||
format!("`{}` and `{}` must be the same: replace one with the other", a, b)
|
||||
}
|
||||
SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
|
||||
},
|
||||
)
|
||||
SuggestedConstraint::Equal(a, b) => {
|
||||
format!("`{}` and `{}` must be the same: replace one with the other", a, b)
|
||||
}
|
||||
SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
|
||||
})
|
||||
} else {
|
||||
// Create a new diagnostic.
|
||||
let mut diag = DiagnosticBuilder::new(
|
||||
infcx.tcx.sess.diagnostic(),
|
||||
Level::Help,
|
||||
"the following changes may resolve your lifetime errors",
|
||||
);
|
||||
let mut diag = infcx
|
||||
.tcx
|
||||
.sess
|
||||
.diagnostic()
|
||||
.struct_help("the following changes may resolve your lifetime errors");
|
||||
|
||||
// Add suggestions.
|
||||
for constraint in suggested {
|
||||
|
|
Loading…
Add table
Reference in a new issue