]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_lint/src/traits.rs
Rollup merge of #107656 - jonhoo:bump-rust-installer, r=Mark-Simulacrum
[rust.git] / compiler / rustc_lint / src / traits.rs
index 1b21c2dac37887ab548d04826e62b5ec96e6ffde..7ea1a138b7e60252e771b4ddffa896577a0c48b1 100644 (file)
@@ -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 });
             }
         }
     }