Skip to content

Commit 19122ab

Browse files
committed
add and use struct_help
1 parent 89a184a commit 19122ab

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/librustc_errors/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ impl Handler {
619619
DiagnosticBuilder::new(self, Level::Fatal, msg)
620620
}
621621

622+
/// Construct a builder at the `Help` level with the `msg`.
623+
pub fn struct_help(&self, msg: &str) -> DiagnosticBuilder<'_> {
624+
DiagnosticBuilder::new(self, Level::Help, msg)
625+
}
626+
622627
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: &str) -> FatalError {
623628
self.emit_diag_at_span(Diagnostic::new(Fatal, msg), span);
624629
FatalError

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/outlives_suggestion.rs

+16-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
66
use log::debug;
77
use rustc::{hir::def_id::DefId, infer::InferCtxt, mir::Body, ty::RegionVid};
88
use rustc_data_structures::fx::FxHashSet;
9-
use rustc_errors::{Diagnostic, DiagnosticBuilder, Level};
9+
use rustc_errors::{Diagnostic, DiagnosticBuilder};
1010

1111
use smallvec::SmallVec;
1212

@@ -258,29 +258,24 @@ impl OutlivesSuggestionBuilder {
258258
// If there is exactly one suggestable constraints, then just suggest it. Otherwise, emit a
259259
// list of diagnostics.
260260
let mut diag = if suggested.len() == 1 {
261-
DiagnosticBuilder::new(
262-
infcx.tcx.sess.diagnostic(),
263-
Level::Help,
264-
&match suggested.last().unwrap() {
265-
SuggestedConstraint::Outlives(a, bs) => {
266-
let bs: SmallVec<[String; 2]> =
267-
bs.iter().map(|r| format!("{}", r)).collect();
268-
format!("add bound `{}: {}`", a, bs.join(" + "))
269-
}
261+
infcx.tcx.sess.diagnostic().struct_help(&match suggested.last().unwrap() {
262+
SuggestedConstraint::Outlives(a, bs) => {
263+
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| format!("{}", r)).collect();
264+
format!("add bound `{}: {}`", a, bs.join(" + "))
265+
}
270266

271-
SuggestedConstraint::Equal(a, b) => {
272-
format!("`{}` and `{}` must be the same: replace one with the other", a, b)
273-
}
274-
SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
275-
},
276-
)
267+
SuggestedConstraint::Equal(a, b) => {
268+
format!("`{}` and `{}` must be the same: replace one with the other", a, b)
269+
}
270+
SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
271+
})
277272
} else {
278273
// Create a new diagnostic.
279-
let mut diag = DiagnosticBuilder::new(
280-
infcx.tcx.sess.diagnostic(),
281-
Level::Help,
282-
"the following changes may resolve your lifetime errors",
283-
);
274+
let mut diag = infcx
275+
.tcx
276+
.sess
277+
.diagnostic()
278+
.struct_help("the following changes may resolve your lifetime errors");
284279

285280
// Add suggestions.
286281
for constraint in suggested {

0 commit comments

Comments
 (0)