@@ -70,16 +70,16 @@ use rustc_data_structures::fx::FxHashMap;
70
70
use rustc_data_structures:: unhash:: UnhashMap ;
71
71
use rustc_hir as hir;
72
72
use rustc_hir:: def:: { DefKind , Res } ;
73
- use rustc_hir:: def_id:: DefId ;
73
+ use rustc_hir:: def_id:: { CrateNum , DefId } ;
74
74
use rustc_hir:: hir_id:: { HirIdMap , HirIdSet } ;
75
75
use rustc_hir:: intravisit:: { walk_expr, ErasedMap , FnKind , NestedVisitorMap , Visitor } ;
76
76
use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
77
77
use rustc_hir:: LangItem :: { OptionNone , ResultErr , ResultOk } ;
78
78
use rustc_hir:: {
79
- def, Arm , BindingAnnotation , Block , BlockCheckMode , Body , Constness , Destination , Expr , ExprKind , FnDecl ,
80
- ForeignItem , GenericArgs , HirId , Impl , ImplItem , ImplItemKind , IsAsync , Item , ItemKind , LangItem , Local ,
81
- MatchSource , Mutability , Node , Param , Pat , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind , TraitItem ,
82
- TraitItemKind , TraitRef , TyKind , UnOp ,
79
+ def, lang_items , Arm , BindingAnnotation , Block , BlockCheckMode , Body , Constness , Destination , Expr , ExprKind ,
80
+ FnDecl , ForeignItem , GenericArgs , HirId , Impl , ImplItem , ImplItemKind , IsAsync , Item , ItemKind , LangItem , Local ,
81
+ MatchSource , Mutability , Node , Param , Pat , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind , Target ,
82
+ TraitItem , TraitItemKind , TraitRef , TyKind , UnOp ,
83
83
} ;
84
84
use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
85
85
use rustc_middle:: hir:: exports:: Export ;
@@ -525,18 +525,34 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
525
525
. iter ( )
526
526
. find ( |item| item. ident . name . as_str ( ) == name)
527
527
}
528
+ fn find_primitive ( tcx : TyCtxt < ' _ > , name : & str ) -> Option < DefId > {
529
+ if let Some ( & ( index, Target :: Impl ) ) = lang_items:: ITEM_REFS . get ( & Symbol :: intern ( name) ) {
530
+ tcx. lang_items ( ) . items ( ) [ index]
531
+ } else {
532
+ None
533
+ }
534
+ }
535
+ fn find_crate ( tcx : TyCtxt < ' _ > , name : & str ) -> Option < DefId > {
536
+ tcx. crates ( ( ) )
537
+ . iter ( )
538
+ . find ( |& & num| tcx. crate_name ( num) . as_str ( ) == name)
539
+ . map ( CrateNum :: as_def_id)
540
+ }
528
541
529
- let ( krate , first, path) = match * path {
530
- [ krate , first, ref path @ ..] => ( krate , first, path) ,
542
+ let ( base , first, path) = match * path {
543
+ [ base , first, ref path @ ..] => ( base , first, path) ,
531
544
[ primitive] => {
532
545
return PrimTy :: from_name ( Symbol :: intern ( primitive) ) . map_or ( Res :: Err , Res :: PrimTy ) ;
533
546
} ,
534
547
_ => return Res :: Err ,
535
548
} ;
536
549
let tcx = cx. tcx ;
537
- let crates = tcx. crates ( ( ) ) ;
538
- let krate = try_res ! ( crates. iter( ) . find( |&&num| tcx. crate_name( num) . as_str( ) == krate) ) ;
539
- let first = try_res ! ( item_child_by_name( tcx, krate. as_def_id( ) , first) ) ;
550
+ let first = try_res ! (
551
+ find_primitive( tcx, base)
552
+ . or_else( || find_crate( tcx, base) )
553
+ . and_then( |id| item_child_by_name( tcx, id, first) )
554
+ ) ;
555
+
540
556
let last = path
541
557
. iter ( )
542
558
. copied ( )
0 commit comments