reduce diversity in linting methods

This commit is contained in:
Mazdak Farrokhzad 2020-01-09 03:28:45 +01:00
parent b93addba7a
commit c151782d76
4 changed files with 19 additions and 41 deletions

View File

@ -179,7 +179,7 @@ fn object_safety_violations_for_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.lint_node_note(
tcx.struct_span_lint_hir(
WHERE_CLAUSES_OBJECT_SAFETY,
hir::CRATE_HIR_ID,
*span,
@ -187,8 +187,9 @@ fn object_safety_violations_for_trait(
"the trait `{}` cannot be made into an object",
tcx.def_path_str(trait_def_id)
),
&violation.error_msg(),
);
)
.note(&violation.error_msg())
.emit();
false
} else {
true

View File

@ -2562,32 +2562,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.struct_span_lint_hir(lint, hir_id, span.into(), msg).emit()
}
pub fn lint_hir_note(
self,
lint: &'static Lint,
hir_id: HirId,
span: impl Into<MultiSpan>,
msg: &str,
note: &str,
) {
let mut err = self.struct_span_lint_hir(lint, hir_id, span.into(), msg);
err.note(note);
err.emit()
}
pub fn lint_node_note(
self,
lint: &'static Lint,
id: hir::HirId,
span: impl Into<MultiSpan>,
msg: &str,
note: &str,
) {
let mut err = self.struct_span_lint_hir(lint, id, span.into(), msg);
err.note(note);
err.emit()
}
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
/// It stops at `bound` and just returns it if reached.
pub fn maybe_lint_level_root_bounded(

View File

@ -648,17 +648,17 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
tcx.unsafe_derive_on_repr_packed(impl_def_id);
} else {
tcx.lint_node_note(
tcx.struct_span_lint_hir(
SAFE_PACKED_BORROWS,
lint_hir_id,
source_info.span,
&format!(
"{} is unsafe and requires unsafe function or block \
(error E0133)",
"{} is unsafe and requires unsafe function or block (error E0133)",
description
),
&details.as_str(),
);
)
.note(&details.as_str())
.emit();
}
}
}

View File

@ -1513,13 +1513,16 @@ impl<'tcx> Liveness<'_, 'tcx> {
if ln == self.s.exit_ln { false } else { self.assigned_on_exit(ln, var).is_some() };
if is_assigned {
self.ir.tcx.lint_hir_note(
lint::builtin::UNUSED_VARIABLES,
hir_id,
spans,
&format!("variable `{}` is assigned to, but never used", name),
&format!("consider using `_{}` instead", name),
);
self.ir
.tcx
.struct_span_lint_hir(
lint::builtin::UNUSED_VARIABLES,
hir_id,
spans,
&format!("variable `{}` is assigned to, but never used", name),
)
.note(&format!("consider using `_{}` instead", name))
.emit();
} else {
let mut err = self.ir.tcx.struct_span_lint_hir(
lint::builtin::UNUSED_VARIABLES,