@@ -13,7 +13,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1313use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
1414use rustc_hir:: def_id:: DefId ;
1515use rustc_hir:: ItemKind ;
16- use rustc_span:: symbol:: { sym, Ident } ;
16+ use rustc_span:: symbol:: sym;
1717use rustc_span:: Span ;
1818use syntax:: ast;
1919
@@ -180,15 +180,12 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
180180 check_associated_item ( tcx, trait_item. hir_id , trait_item. span , method_sig) ;
181181}
182182
183- fn could_be_self ( trait_name : Ident , ty : & hir:: Ty < ' _ > ) -> bool {
183+ fn could_be_self ( trait_def_id : DefId , ty : & hir:: Ty < ' _ > ) -> bool {
184184 match ty. kind {
185- hir:: TyKind :: TraitObject ( [ trait_ref] , ..) => {
186- let mut p = trait_ref. trait_ref . path . segments . iter ( ) . map ( |s| s. ident ) ;
187- match ( p. next ( ) , p. next ( ) ) {
188- ( Some ( ident) , None ) => ident == trait_name,
189- _ => false ,
190- }
191- }
185+ hir:: TyKind :: TraitObject ( [ trait_ref] , ..) => match trait_ref. trait_ref . path . segments {
186+ [ s] => s. res . and_then ( |r| r. opt_def_id ( ) ) == Some ( trait_def_id) ,
187+ _ => false ,
188+ } ,
192189 _ => false ,
193190 }
194191}
@@ -206,18 +203,18 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
206203 let mut trait_should_be_self = vec ! [ ] ;
207204 match & item. kind {
208205 hir:: TraitItemKind :: Const ( ty, _) | hir:: TraitItemKind :: Type ( _, Some ( ty) )
209- if could_be_self ( trait_name , ty) =>
206+ if could_be_self ( trait_def_id , ty) =>
210207 {
211208 trait_should_be_self. push ( ty. span )
212209 }
213210 hir:: TraitItemKind :: Method ( sig, _) => {
214211 for ty in sig. decl . inputs {
215- if could_be_self ( trait_name , ty) {
212+ if could_be_self ( trait_def_id , ty) {
216213 trait_should_be_self. push ( ty. span ) ;
217214 }
218215 }
219216 match sig. decl . output {
220- hir:: FunctionRetTy :: Return ( ty) if could_be_self ( trait_name , ty) => {
217+ hir:: FunctionRetTy :: Return ( ty) if could_be_self ( trait_def_id , ty) => {
221218 trait_should_be_self. push ( ty. span ) ;
222219 }
223220 _ => { }
0 commit comments