|
1 | | -use crate::{LateContext, LateLintPass, LintContext}; |
| 1 | +use crate::{ |
| 2 | + lints::{SupertraitAsDerefTarget, SupertraitAsDerefTargetLabel}, |
| 3 | + LateContext, LateLintPass, LintContext, |
| 4 | +}; |
2 | 5 |
|
3 | | -use rustc_errors::DelayDm; |
4 | 6 | use rustc_hir as hir; |
5 | 7 | use rustc_middle::{traits::util::supertraits, ty}; |
6 | 8 | use rustc_span::sym; |
@@ -71,22 +73,14 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait { |
71 | 73 | && supertraits(cx.tcx, t_principal.with_self_ty(cx.tcx, cx.tcx.types.trait_object_dummy_self)) |
72 | 74 | .any(|sup| sup.map_bound(|x| ty::ExistentialTraitRef::erase_self_ty(cx.tcx, x)) == target_principal) |
73 | 75 | { |
74 | | - cx.struct_span_lint( |
75 | | - DEREF_INTO_DYN_SUPERTRAIT, |
76 | | - cx.tcx.def_span(item.owner_id.def_id), |
77 | | - DelayDm(|| { |
78 | | - format!( |
79 | | - "`{t}` implements `Deref` with supertrait `{target_principal}` as target" |
80 | | - ) |
81 | | - }), |
82 | | - |lint| { |
83 | | - if let Some(target_span) = impl_.items.iter().find_map(|i| (i.ident.name == sym::Target).then_some(i.span)) { |
84 | | - lint.span_label(target_span, "target type is set here"); |
85 | | - } |
86 | | - |
87 | | - lint |
88 | | - }, |
89 | | - ) |
| 76 | + let label = impl_.items.iter().find_map(|i| (i.ident.name == sym::Target).then_some(i.span)).map(|label| SupertraitAsDerefTargetLabel { |
| 77 | + label, |
| 78 | + }); |
| 79 | + cx.emit_spanned_lint(DEREF_INTO_DYN_SUPERTRAIT, cx.tcx.def_span(item.owner_id.def_id), SupertraitAsDerefTarget { |
| 80 | + t, |
| 81 | + target_principal: target_principal.to_string(), |
| 82 | + label, |
| 83 | + }); |
90 | 84 | } |
91 | 85 | } |
92 | 86 | } |
0 commit comments