@@ -50,7 +50,7 @@ declare_lint! {
50
50
Warn ,
51
51
"`Deref` implementation usage with a supertrait trait object for output might be shadowed in the future" ,
52
52
@future_incompatible = FutureIncompatibleInfo {
53
- reason: FutureIncompatibilityReason :: FutureReleaseErrorDontReportInDeps ,
53
+ reason: FutureIncompatibilityReason :: FutureReleaseSemanticsChange ,
54
54
reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>" ,
55
55
} ;
56
56
}
@@ -59,12 +59,13 @@ declare_lint_pass!(DerefIntoDynSupertrait => [DEREF_INTO_DYN_SUPERTRAIT]);
59
59
60
60
impl < ' tcx > LateLintPass < ' tcx > for DerefIntoDynSupertrait {
61
61
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: Item < ' tcx > ) {
62
+ let tcx = cx. tcx ;
62
63
// `Deref` is being implemented for `t`
63
64
if let hir:: ItemKind :: Impl ( impl_) = item. kind
64
65
&& let Some ( trait_) = & impl_. of_trait
65
- && let t = cx . tcx . type_of ( item. owner_id ) . instantiate_identity ( )
66
+ && let t = tcx. type_of ( item. owner_id ) . instantiate_identity ( )
66
67
&& let opt_did @ Some ( did) = trait_. trait_def_id ( )
67
- && opt_did == cx . tcx . lang_items ( ) . deref_trait ( )
68
+ && opt_did == tcx. lang_items ( ) . deref_trait ( )
68
69
// `t` is `dyn t_principal`
69
70
&& let ty:: Dynamic ( data, _, ty:: Dyn ) = t. kind ( )
70
71
&& let Some ( t_principal) = data. principal ( )
@@ -73,17 +74,22 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
73
74
&& let ty:: Dynamic ( data, _, ty:: Dyn ) = target. kind ( )
74
75
&& let Some ( target_principal) = data. principal ( )
75
76
// `target_principal` is a supertrait of `t_principal`
76
- && supertraits ( cx. tcx , t_principal. with_self_ty ( cx. tcx , cx. tcx . types . trait_object_dummy_self ) )
77
- . any ( |sup| sup. map_bound ( |x| ty:: ExistentialTraitRef :: erase_self_ty ( cx. tcx , x) ) == target_principal)
77
+ && supertraits ( tcx, t_principal. with_self_ty ( tcx, tcx. types . trait_object_dummy_self ) )
78
+ . any ( |sup| {
79
+ tcx. erase_regions (
80
+ sup. map_bound ( |x| ty:: ExistentialTraitRef :: erase_self_ty ( tcx, x) ) ,
81
+ ) == tcx. erase_regions ( target_principal)
82
+ } )
78
83
{
84
+ let t = tcx. erase_regions ( t) ;
79
85
let label = impl_
80
86
. items
81
87
. iter ( )
82
88
. find_map ( |i| ( i. ident . name == sym:: Target ) . then_some ( i. span ) )
83
89
. map ( |label| SupertraitAsDerefTargetLabel { label } ) ;
84
90
cx. emit_spanned_lint (
85
91
DEREF_INTO_DYN_SUPERTRAIT ,
86
- cx . tcx . def_span ( item. owner_id . def_id ) ,
92
+ tcx. def_span ( item. owner_id . def_id ) ,
87
93
SupertraitAsDerefTarget { t, target_principal, label } ,
88
94
) ;
89
95
}
0 commit comments