X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_lint%2Fsrc%2Ftraits.rs;h=7ea1a138b7e60252e771b4ddffa896577a0c48b1;hb=6c991b07403a3234dd1ec0ac973b8ef97055e605;hp=1b21c2dac37887ab548d04826e62b5ec96e6ffde;hpb=d1193ad1e6f05271b442a96d6ea7de18b66163a0;p=rust.git diff --git a/compiler/rustc_lint/src/traits.rs b/compiler/rustc_lint/src/traits.rs index 1b21c2dac37..7ea1a138b7e 100644 --- a/compiler/rustc_lint/src/traits.rs +++ b/compiler/rustc_lint/src/traits.rs @@ -1,7 +1,7 @@ +use crate::lints::{DropGlue, DropTraitConstraintsDiag}; use crate::LateContext; use crate::LateLintPass; use crate::LintContext; -use rustc_errors::fluent; use rustc_hir as hir; use rustc_span::symbol::sym; @@ -101,17 +101,13 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { if trait_predicate.trait_ref.self_ty().is_impl_trait() { continue; } - let Some(needs_drop) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { - continue; + let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { + return }; - cx.struct_span_lint( + cx.emit_spanned_lint( DROP_BOUNDS, span, - fluent::lint_drop_trait_constraints, - |lint| { - lint.set_arg("predicate", predicate) - .set_arg("needs_drop", cx.tcx.def_path_str(needs_drop)) - }, + DropTraitConstraintsDiag { predicate, tcx: cx.tcx, def_id }, ); } } @@ -123,12 +119,11 @@ fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx>) { }; for bound in &bounds[..] { let def_id = bound.trait_ref.trait_def_id(); - if cx.tcx.lang_items().drop_trait() == def_id - && let Some(needs_drop) = cx.tcx.get_diagnostic_item(sym::needs_drop) - { - cx.struct_span_lint(DYN_DROP, bound.span, fluent::lint_drop_glue, |lint| { - lint.set_arg("needs_drop", cx.tcx.def_path_str(needs_drop)) - }); + if cx.tcx.lang_items().drop_trait() == def_id { + let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { + return + }; + cx.emit_spanned_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id }); } } }