@@ -13,7 +13,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
13
13
use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
14
14
use rustc_hir:: def_id:: DefId ;
15
15
use rustc_hir:: ItemKind ;
16
- use rustc_span:: symbol:: { sym, Ident } ;
16
+ use rustc_span:: symbol:: sym;
17
17
use rustc_span:: Span ;
18
18
use syntax:: ast;
19
19
@@ -180,15 +180,12 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
180
180
check_associated_item ( tcx, trait_item. hir_id , trait_item. span , method_sig) ;
181
181
}
182
182
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 {
184
184
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
+ } ,
192
189
_ => false ,
193
190
}
194
191
}
@@ -206,18 +203,18 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
206
203
let mut trait_should_be_self = vec ! [ ] ;
207
204
match & item. kind {
208
205
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) =>
210
207
{
211
208
trait_should_be_self. push ( ty. span )
212
209
}
213
210
hir:: TraitItemKind :: Method ( sig, _) => {
214
211
for ty in sig. decl . inputs {
215
- if could_be_self ( trait_name , ty) {
212
+ if could_be_self ( trait_def_id , ty) {
216
213
trait_should_be_self. push ( ty. span ) ;
217
214
}
218
215
}
219
216
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) => {
221
218
trait_should_be_self. push ( ty. span ) ;
222
219
}
223
220
_ => { }
0 commit comments