Skip to content
Permalink
Browse files

reduce diversity in linting methods

  • Loading branch information
Centril committed Jan 9, 2020
1 parent b93addb commit c151782d76d1d664c1e55dd7ec2b44d3a18867c2
@@ -179,16 +179,17 @@ 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,
&format!(
"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
@@ -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(
@@ -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();
}
}
}
@@ -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,

0 comments on commit c151782

Please sign in to comment.
You can’t perform that action at this time.