@@ -81,7 +81,7 @@ pub struct LoweringContext<'a> {
8181}
8282
8383pub trait Resolver {
84- // Resolve a global hir path generated by the lowerer when expanding `for`, `if let`, etc.
84+ // Resolve a hir path generated by the lowerer when expanding `for`, `if let`, etc.
8585 fn resolve_hir_path ( & mut self , path : & mut hir:: Path , is_value : bool ) ;
8686
8787 // Obtain the resolution for a node id
@@ -337,7 +337,6 @@ impl<'a> LoweringContext<'a> {
337337
338338 let proj_start = p. segments . len ( ) - resolution. depth ;
339339 let path = P ( hir:: Path {
340- global : p. global ,
341340 def : resolution. base_def ,
342341 segments : p. segments [ ..proj_start] . iter ( ) . enumerate ( ) . map ( |( i, segment) | {
343342 let param_mode = match ( qself_position, param_mode) {
@@ -404,12 +403,17 @@ impl<'a> LoweringContext<'a> {
404403 id : NodeId ,
405404 p : & Path ,
406405 name : Option < Name > ,
407- param_mode : ParamMode )
406+ param_mode : ParamMode ,
407+ defaults_to_global : bool )
408408 -> hir:: Path {
409+ let mut segments = p. segments . iter ( ) ;
410+ if defaults_to_global && p. is_global ( ) {
411+ segments. next ( ) ;
412+ }
413+
409414 hir:: Path {
410- global : p. global ,
411415 def : self . expect_full_def ( id) ,
412- segments : p . segments . iter ( ) . map ( |segment| {
416+ segments : segments. map ( |segment| {
413417 self . lower_path_segment ( segment, param_mode)
414418 } ) . chain ( name. map ( |name| {
415419 hir:: PathSegment {
@@ -424,9 +428,10 @@ impl<'a> LoweringContext<'a> {
424428 fn lower_path ( & mut self ,
425429 id : NodeId ,
426430 p : & Path ,
427- param_mode : ParamMode )
431+ param_mode : ParamMode ,
432+ defaults_to_global : bool )
428433 -> hir:: Path {
429- self . lower_path_extra ( id, p, None , param_mode)
434+ self . lower_path_extra ( id, p, None , param_mode, defaults_to_global )
430435 }
431436
432437 fn lower_path_segment ( & mut self ,
@@ -602,8 +607,8 @@ impl<'a> LoweringContext<'a> {
602607 // Check if the where clause type is a plain type parameter.
603608 match bound_pred. bounded_ty . node {
604609 TyKind :: Path ( None , ref path)
605- if !path . global && path. segments . len ( ) == 1 &&
606- bound_pred. bound_lifetimes . is_empty ( ) => {
610+ if path. segments . len ( ) == 1 &&
611+ bound_pred. bound_lifetimes . is_empty ( ) => {
607612 if let Some ( Def :: TyParam ( def_id) ) =
608613 self . resolver . get_resolution ( bound_pred. bounded_ty . id )
609614 . map ( |d| d. base_def ) {
@@ -677,7 +682,7 @@ impl<'a> LoweringContext<'a> {
677682 span} ) => {
678683 hir:: WherePredicate :: EqPredicate ( hir:: WhereEqPredicate {
679684 id : id,
680- path : self . lower_path ( id, path, ParamMode :: Explicit ) ,
685+ path : self . lower_path ( id, path, ParamMode :: Explicit , false ) ,
681686 ty : self . lower_ty ( ty) ,
682687 span : span,
683688 } )
@@ -707,7 +712,7 @@ impl<'a> LoweringContext<'a> {
707712
708713 fn lower_trait_ref ( & mut self , p : & TraitRef ) -> hir:: TraitRef {
709714 hir:: TraitRef {
710- path : self . lower_path ( p. ref_id , & p. path , ParamMode :: Explicit ) ,
715+ path : self . lower_path ( p. ref_id , & p. path , ParamMode :: Explicit , false ) ,
711716 ref_id : p. ref_id ,
712717 }
713718 }
@@ -800,7 +805,7 @@ impl<'a> LoweringContext<'a> {
800805 } ;
801806
802807 let mut path = self . lower_path_extra ( import. id , path, suffix,
803- ParamMode :: Explicit ) ;
808+ ParamMode :: Explicit , true ) ;
804809 path. span = span;
805810 self . items . insert ( import. id , hir:: Item {
806811 id : import. id ,
@@ -814,7 +819,7 @@ impl<'a> LoweringContext<'a> {
814819 path
815820 }
816821 } ;
817- let path = P ( self . lower_path ( id, path, ParamMode :: Explicit ) ) ;
822+ let path = P ( self . lower_path ( id, path, ParamMode :: Explicit , true ) ) ;
818823 let kind = match view_path. node {
819824 ViewPathSimple ( ident, _) => {
820825 * name = ident. name ;
@@ -1135,7 +1140,6 @@ impl<'a> LoweringContext<'a> {
11351140 Some ( def) => {
11361141 hir:: PatKind :: Path ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
11371142 span : pth1. span ,
1138- global : false ,
11391143 def : def,
11401144 segments : hir_vec ! [
11411145 hir:: PathSegment :: from_name( pth1. node. name)
@@ -1878,7 +1882,7 @@ impl<'a> LoweringContext<'a> {
18781882 Visibility :: Crate ( _) => hir:: Visibility :: Crate ,
18791883 Visibility :: Restricted { ref path, id } => {
18801884 hir:: Visibility :: Restricted {
1881- path : P ( self . lower_path ( id, path, ParamMode :: Explicit ) ) ,
1885+ path : P ( self . lower_path ( id, path, ParamMode :: Explicit , true ) ) ,
18821886 id : id
18831887 }
18841888 }
@@ -1971,7 +1975,6 @@ impl<'a> LoweringContext<'a> {
19711975
19721976 let expr_path = hir:: ExprPath ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
19731977 span : span,
1974- global : false ,
19751978 def : def,
19761979 segments : hir_vec ! [ hir:: PathSegment :: from_name( id) ] ,
19771980 } ) ) ) ;
@@ -2139,17 +2142,12 @@ impl<'a> LoweringContext<'a> {
21392142 /// `fld.cx.use_std`, and `::core::b::c::d` otherwise.
21402143 /// The path is also resolved according to `is_value`.
21412144 fn std_path ( & mut self , span : Span , components : & [ & str ] , is_value : bool ) -> hir:: Path {
2142- let idents = self . crate_root . iter ( ) . chain ( components) ;
2143-
2144- let segments: Vec < _ > = idents. map ( |name| {
2145- hir:: PathSegment :: from_name ( Symbol :: intern ( name) )
2146- } ) . collect ( ) ;
2147-
21482145 let mut path = hir:: Path {
21492146 span : span,
2150- global : true ,
21512147 def : Def :: Err ,
2152- segments : segments. into ( ) ,
2148+ segments : iter:: once ( keywords:: CrateRoot . name ( ) ) . chain ( {
2149+ self . crate_root . into_iter ( ) . chain ( components. iter ( ) . cloned ( ) ) . map ( Symbol :: intern)
2150+ } ) . map ( hir:: PathSegment :: from_name) . collect ( ) ,
21532151 } ;
21542152
21552153 self . resolver . resolve_hir_path ( & mut path, is_value) ;
0 commit comments