reduce diversity in linting methods
This commit is contained in:
parent
b93addba7a
commit
c151782d76
4 changed files with 19 additions and 41 deletions
|
@ -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.
|
// 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.
|
// 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,
|
WHERE_CLAUSES_OBJECT_SAFETY,
|
||||||
hir::CRATE_HIR_ID,
|
hir::CRATE_HIR_ID,
|
||||||
*span,
|
*span,
|
||||||
|
@ -187,8 +187,9 @@ fn object_safety_violations_for_trait(
|
||||||
"the trait `{}` cannot be made into an object",
|
"the trait `{}` cannot be made into an object",
|
||||||
tcx.def_path_str(trait_def_id)
|
tcx.def_path_str(trait_def_id)
|
||||||
),
|
),
|
||||||
&violation.error_msg(),
|
)
|
||||||
);
|
.note(&violation.error_msg())
|
||||||
|
.emit();
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
|
|
@ -2562,32 +2562,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.struct_span_lint_hir(lint, hir_id, span.into(), msg).emit()
|
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.
|
/// 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.
|
/// It stops at `bound` and just returns it if reached.
|
||||||
pub fn maybe_lint_level_root_bounded(
|
pub fn maybe_lint_level_root_bounded(
|
||||||
|
|
|
@ -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) {
|
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
|
||||||
tcx.unsafe_derive_on_repr_packed(impl_def_id);
|
tcx.unsafe_derive_on_repr_packed(impl_def_id);
|
||||||
} else {
|
} else {
|
||||||
tcx.lint_node_note(
|
tcx.struct_span_lint_hir(
|
||||||
SAFE_PACKED_BORROWS,
|
SAFE_PACKED_BORROWS,
|
||||||
lint_hir_id,
|
lint_hir_id,
|
||||||
source_info.span,
|
source_info.span,
|
||||||
&format!(
|
&format!(
|
||||||
"{} is unsafe and requires unsafe function or block \
|
"{} is unsafe and requires unsafe function or block (error E0133)",
|
||||||
(error E0133)",
|
|
||||||
description
|
description
|
||||||
),
|
),
|
||||||
&details.as_str(),
|
)
|
||||||
);
|
.note(&details.as_str())
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 ln == self.s.exit_ln { false } else { self.assigned_on_exit(ln, var).is_some() };
|
||||||
|
|
||||||
if is_assigned {
|
if is_assigned {
|
||||||
self.ir.tcx.lint_hir_note(
|
self.ir
|
||||||
lint::builtin::UNUSED_VARIABLES,
|
.tcx
|
||||||
hir_id,
|
.struct_span_lint_hir(
|
||||||
spans,
|
lint::builtin::UNUSED_VARIABLES,
|
||||||
&format!("variable `{}` is assigned to, but never used", name),
|
hir_id,
|
||||||
&format!("consider using `_{}` instead", name),
|
spans,
|
||||||
);
|
&format!("variable `{}` is assigned to, but never used", name),
|
||||||
|
)
|
||||||
|
.note(&format!("consider using `_{}` instead", name))
|
||||||
|
.emit();
|
||||||
} else {
|
} else {
|
||||||
let mut err = self.ir.tcx.struct_span_lint_hir(
|
let mut err = self.ir.tcx.struct_span_lint_hir(
|
||||||
lint::builtin::UNUSED_VARIABLES,
|
lint::builtin::UNUSED_VARIABLES,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue