Remove LintDiagnostic::msg
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
This commit is contained in:
parent
366ef95407
commit
06bc4fc671
44 changed files with 430 additions and 488 deletions
|
@ -13,7 +13,7 @@ use super::elaborate;
|
|||
use crate::infer::TyCtxtInferExt;
|
||||
use crate::traits::query::evaluate_obligation::InferCtxtExt;
|
||||
use crate::traits::{self, Obligation, ObligationCause};
|
||||
use rustc_errors::{DelayDm, FatalError, MultiSpan};
|
||||
use rustc_errors::{FatalError, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::query::Providers;
|
||||
|
@ -162,41 +162,36 @@ fn lint_object_unsafe_trait(
|
|||
) {
|
||||
// Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
|
||||
// It's also hard to get a use site span, so we use the method definition span.
|
||||
tcx.node_span_lint(
|
||||
WHERE_CLAUSES_OBJECT_SAFETY,
|
||||
hir::CRATE_HIR_ID,
|
||||
span,
|
||||
DelayDm(|| format!("the trait `{}` cannot be made into an object", tcx.def_path_str(trait_def_id))),
|
||||
|err| {
|
||||
let node = tcx.hir().get_if_local(trait_def_id);
|
||||
let mut spans = MultiSpan::from_span(span);
|
||||
if let Some(hir::Node::Item(item)) = node {
|
||||
spans.push_span_label(
|
||||
item.ident.span,
|
||||
"this trait cannot be made into an object...",
|
||||
);
|
||||
spans.push_span_label(span, format!("...because {}", violation.error_msg()));
|
||||
} else {
|
||||
spans.push_span_label(
|
||||
span,
|
||||
format!(
|
||||
"the trait cannot be made into an object because {}",
|
||||
violation.error_msg()
|
||||
),
|
||||
);
|
||||
};
|
||||
err.span_note(
|
||||
spans,
|
||||
"for a trait to be \"object safe\" it needs to allow building a vtable to allow the \
|
||||
tcx.node_span_lint(WHERE_CLAUSES_OBJECT_SAFETY, hir::CRATE_HIR_ID, span, |err| {
|
||||
err.primary_message(format!(
|
||||
"the trait `{}` cannot be made into an object",
|
||||
tcx.def_path_str(trait_def_id)
|
||||
));
|
||||
let node = tcx.hir().get_if_local(trait_def_id);
|
||||
let mut spans = MultiSpan::from_span(span);
|
||||
if let Some(hir::Node::Item(item)) = node {
|
||||
spans.push_span_label(item.ident.span, "this trait cannot be made into an object...");
|
||||
spans.push_span_label(span, format!("...because {}", violation.error_msg()));
|
||||
} else {
|
||||
spans.push_span_label(
|
||||
span,
|
||||
format!(
|
||||
"the trait cannot be made into an object because {}",
|
||||
violation.error_msg()
|
||||
),
|
||||
);
|
||||
};
|
||||
err.span_note(
|
||||
spans,
|
||||
"for a trait to be \"object safe\" it needs to allow building a vtable to allow the \
|
||||
call to be resolvable dynamically; for more information visit \
|
||||
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
|
||||
);
|
||||
if node.is_some() {
|
||||
// Only provide the help if its a local trait, otherwise it's not
|
||||
violation.solution().add_to(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
);
|
||||
if node.is_some() {
|
||||
// Only provide the help if its a local trait, otherwise it's not
|
||||
violation.solution().add_to(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn sized_trait_bound_spans<'tcx>(
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::traits::{
|
|||
self, coherence, FutureCompatOverlapErrorKind, ObligationCause, ObligationCtxt,
|
||||
};
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{codes::*, DelayDm, Diag, EmissionGuarantee};
|
||||
use rustc_errors::{codes::*, Diag, EmissionGuarantee};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
|
||||
|
@ -449,7 +449,7 @@ fn report_conflicting_impls<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
let msg = DelayDm(|| {
|
||||
let msg = || {
|
||||
format!(
|
||||
"conflicting implementations of trait `{}`{}{}",
|
||||
overlap.trait_ref.print_trait_sugared(),
|
||||
|
@ -459,7 +459,7 @@ fn report_conflicting_impls<'tcx>(
|
|||
_ => "",
|
||||
}
|
||||
)
|
||||
});
|
||||
};
|
||||
|
||||
// Don't report overlap errors if the header references error
|
||||
if let Err(err) = (overlap.trait_ref, overlap.self_ty).error_reported() {
|
||||
|
@ -471,7 +471,7 @@ fn report_conflicting_impls<'tcx>(
|
|||
let reported = if overlap.with_impl.is_local()
|
||||
|| tcx.ensure().orphan_check_impl(impl_def_id).is_ok()
|
||||
{
|
||||
let mut err = tcx.dcx().struct_span_err(impl_span, msg);
|
||||
let mut err = tcx.dcx().struct_span_err(impl_span, msg());
|
||||
err.code(E0119);
|
||||
decorate(tcx, &overlap, impl_span, &mut err);
|
||||
err.emit()
|
||||
|
@ -485,15 +485,10 @@ fn report_conflicting_impls<'tcx>(
|
|||
FutureCompatOverlapErrorKind::OrderDepTraitObjects => ORDER_DEPENDENT_TRAIT_OBJECTS,
|
||||
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
|
||||
};
|
||||
tcx.node_span_lint(
|
||||
lint,
|
||||
tcx.local_def_id_to_hir_id(impl_def_id),
|
||||
impl_span,
|
||||
msg,
|
||||
|err| {
|
||||
decorate(tcx, &overlap, impl_span, err);
|
||||
},
|
||||
);
|
||||
tcx.node_span_lint(lint, tcx.local_def_id_to_hir_id(impl_def_id), impl_span, |err| {
|
||||
err.primary_message(msg());
|
||||
decorate(tcx, &overlap, impl_span, err);
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue