@@ -845,6 +845,10 @@ impl<'a> ModuleS<'a> {
845845            _ => false , 
846846        } 
847847    } 
848+ 
849+     fn  is_local ( & self )  -> bool  { 
850+         self . normal_ancestor_id . is_some ( ) 
851+     } 
848852} 
849853
850854impl < ' a >  fmt:: Debug  for  ModuleS < ' a >  { 
@@ -1580,14 +1584,7 @@ impl<'a> Resolver<'a> {
15801584fn  resolve_module_prefix ( & mut  self ,  module_path :  & [ Ident ] ,  span :  Option < Span > ) 
15811585                             -> ResolveResult < ModulePrefixResult < ' a > >  { 
15821586        if  & * module_path[ 0 ] . name . as_str ( )  == "$crate"  { 
1583-             let  mut  ctxt = module_path[ 0 ] . ctxt ; 
1584-             while  ctxt. source ( ) . 0  != SyntaxContext :: empty ( )  { 
1585-                 ctxt = ctxt. source ( ) . 0 ; 
1586-             } 
1587-             let  module = self . invocations [ & ctxt. source ( ) . 1 ] . module . get ( ) ; 
1588-             let  crate_root =
1589-                 if  module. def_id ( ) . unwrap ( ) . is_local ( )  {  self . graph_root  }  else  {  module } ; 
1590-             return  Success ( PrefixFound ( crate_root,  1 ) ) 
1587+             return  Success ( PrefixFound ( self . resolve_crate_var ( module_path[ 0 ] . ctxt ) ,  1 ) ) ; 
15911588        } 
15921589
15931590        // Start at the current module if we see `self` or `super`, or at the 
@@ -1620,6 +1617,14 @@ impl<'a> Resolver<'a> {
16201617        return  Success ( PrefixFound ( containing_module,  i) ) ; 
16211618    } 
16221619
1620+     fn  resolve_crate_var ( & mut  self ,  mut  crate_var_ctxt :  SyntaxContext )  -> Module < ' a >  { 
1621+         while  crate_var_ctxt. source ( ) . 0  != SyntaxContext :: empty ( )  { 
1622+             crate_var_ctxt = crate_var_ctxt. source ( ) . 0 ; 
1623+         } 
1624+         let  module = self . invocations [ & crate_var_ctxt. source ( ) . 1 ] . module . get ( ) ; 
1625+         if  module. is_local ( )  {  self . graph_root  }  else  {  module } 
1626+     } 
1627+ 
16231628    // AST resolution 
16241629    // 
16251630    // We maintain a list of value ribs and type ribs. 
@@ -2569,7 +2574,8 @@ impl<'a> Resolver<'a> {
25692574        let  unqualified_def = resolve_identifier_with_fallback ( self ,  None ) ; 
25702575        let  qualified_binding = self . resolve_module_relative_path ( span,  segments,  namespace) ; 
25712576        match  ( qualified_binding,  unqualified_def)  { 
2572-             ( Ok ( binding) ,  Some ( ref  ud) )  if  binding. def ( )  == ud. def  => { 
2577+             ( Ok ( binding) ,  Some ( ref  ud) )  if  binding. def ( )  == ud. def  &&
2578+                                            segments[ 0 ] . identifier . name . as_str ( )  != "$crate"  => { 
25732579                self . session 
25742580                    . add_lint ( lint:: builtin:: UNUSED_QUALIFICATIONS , 
25752581                              id, 
0 commit comments