@@ -403,7 +403,7 @@ pub(crate) enum PathSource<'a> {
403403    // Paths in path patterns `Path`. 
404404    Pat , 
405405    // Paths in struct expressions and patterns `Path { .. }`. 
406-     Struct , 
406+     Struct ( Option < & ' a   Expr > ) , 
407407    // Paths in tuple struct patterns `Path(..)`. 
408408    TupleStruct ( Span ,  & ' a  [ Span ] ) , 
409409    // `m::A::B` in `<T as m::A>::B::C`. 
@@ -419,7 +419,7 @@ pub(crate) enum PathSource<'a> {
419419impl < ' a >  PathSource < ' a >  { 
420420    fn  namespace ( self )  -> Namespace  { 
421421        match  self  { 
422-             PathSource :: Type  | PathSource :: Trait ( _)  | PathSource :: Struct  => TypeNS , 
422+             PathSource :: Type  | PathSource :: Trait ( _)  | PathSource :: Struct ( _ )  => TypeNS , 
423423            PathSource :: Expr ( ..) 
424424            | PathSource :: Pat 
425425            | PathSource :: TupleStruct ( ..) 
@@ -435,7 +435,7 @@ impl<'a> PathSource<'a> {
435435            PathSource :: Type 
436436            | PathSource :: Expr ( ..) 
437437            | PathSource :: Pat 
438-             | PathSource :: Struct 
438+             | PathSource :: Struct ( _ ) 
439439            | PathSource :: TupleStruct ( ..) 
440440            | PathSource :: ReturnTypeNotation  => true , 
441441            PathSource :: Trait ( _) 
@@ -450,7 +450,7 @@ impl<'a> PathSource<'a> {
450450            PathSource :: Type  => "type" , 
451451            PathSource :: Trait ( _)  => "trait" , 
452452            PathSource :: Pat  => "unit struct, unit variant or constant" , 
453-             PathSource :: Struct  => "struct, variant or union type" , 
453+             PathSource :: Struct ( _ )  => "struct, variant or union type" , 
454454            PathSource :: TupleStruct ( ..)  => "tuple struct or tuple variant" , 
455455            PathSource :: TraitItem ( ns)  => match  ns { 
456456                TypeNS  => "associated type" , 
@@ -531,7 +531,7 @@ impl<'a> PathSource<'a> {
531531                    || matches ! ( res,  Res :: Def ( DefKind :: Const  | DefKind :: AssocConst ,  _) ) 
532532            } 
533533            PathSource :: TupleStruct ( ..)  => res. expected_in_tuple_struct_pat ( ) , 
534-             PathSource :: Struct  => matches ! ( 
534+             PathSource :: Struct ( _ )  => matches ! ( 
535535                res, 
536536                Res :: Def ( 
537537                    DefKind :: Struct 
@@ -571,8 +571,8 @@ impl<'a> PathSource<'a> {
571571            ( PathSource :: Trait ( _) ,  false )  => E0405 , 
572572            ( PathSource :: Type ,  true )  => E0573 , 
573573            ( PathSource :: Type ,  false )  => E0412 , 
574-             ( PathSource :: Struct ,  true )  => E0574 , 
575-             ( PathSource :: Struct ,  false )  => E0422 , 
574+             ( PathSource :: Struct ( _ ) ,  true )  => E0574 , 
575+             ( PathSource :: Struct ( _ ) ,  false )  => E0422 , 
576576            ( PathSource :: Expr ( ..) ,  true )  | ( PathSource :: Delegation ,  true )  => E0423 , 
577577            ( PathSource :: Expr ( ..) ,  false )  | ( PathSource :: Delegation ,  false )  => E0425 , 
578578            ( PathSource :: Pat  | PathSource :: TupleStruct ( ..) ,  true )  => E0532 , 
@@ -1454,11 +1454,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14541454        path :  & [ Segment ] , 
14551455        opt_ns :  Option < Namespace > ,  // `None` indicates a module path in import 
14561456        finalize :  Option < Finalize > , 
1457+         source :  PathSource < ' ast > , 
14571458    )  -> PathResult < ' ra >  { 
14581459        self . r . resolve_path_with_ribs ( 
14591460            path, 
14601461            opt_ns, 
14611462            & self . parent_scope , 
1463+             Some ( source) , 
14621464            finalize, 
14631465            Some ( & self . ribs ) , 
14641466            None , 
@@ -1961,7 +1963,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19611963                | PathSource :: ReturnTypeNotation  => false , 
19621964                PathSource :: Expr ( ..) 
19631965                | PathSource :: Pat 
1964-                 | PathSource :: Struct 
1966+                 | PathSource :: Struct ( _ ) 
19651967                | PathSource :: TupleStruct ( ..) 
19661968                | PathSource :: Delegation  => true , 
19671969            } ; 
@@ -3794,7 +3796,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
37943796                    self . smart_resolve_path ( pat. id ,  qself,  path,  PathSource :: Pat ) ; 
37953797                } 
37963798                PatKind :: Struct ( ref  qself,  ref  path,  ref  _fields,  ref  rest)  => { 
3797-                     self . smart_resolve_path ( pat. id ,  qself,  path,  PathSource :: Struct ) ; 
3799+                     self . smart_resolve_path ( pat. id ,  qself,  path,  PathSource :: Struct ( None ) ) ; 
37983800                    self . record_patterns_with_skipped_bindings ( pat,  rest) ; 
37993801                } 
38003802                PatKind :: Or ( ref  ps)  => { 
@@ -4200,6 +4202,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
42004202            qself, 
42014203            path, 
42024204            ns, 
4205+             source, 
42034206            path_span, 
42044207            source. defer_to_typeck ( ) , 
42054208            finalize, 
@@ -4245,7 +4248,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
42454248                    std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ; 
42464249                    std_path. extend ( path) ; 
42474250                    if  let  PathResult :: Module ( _)  | PathResult :: NonModule ( _)  =
4248-                         self . resolve_path ( & std_path,  Some ( ns) ,  None ) 
4251+                         self . resolve_path ( & std_path,  Some ( ns) ,  None ,  source ) 
42494252                    { 
42504253                        // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8` 
42514254                        let  item_span =
@@ -4316,6 +4319,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43164319        qself :  & Option < P < QSelf > > , 
43174320        path :  & [ Segment ] , 
43184321        primary_ns :  Namespace , 
4322+         source :  PathSource < ' ast > , 
43194323        span :  Span , 
43204324        defer_to_typeck :  bool , 
43214325        finalize :  Finalize , 
@@ -4324,7 +4328,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43244328
43254329        for  ( i,  & ns)  in  [ primary_ns,  TypeNS ,  ValueNS ] . iter ( ) . enumerate ( )  { 
43264330            if  i == 0  || ns != primary_ns { 
4327-                 match  self . resolve_qpath ( qself,  path,  ns,  finalize) ? { 
4331+                 match  self . resolve_qpath ( qself,  path,  ns,  source ,   finalize) ? { 
43284332                    Some ( partial_res) 
43294333                        if  partial_res. unresolved_segments ( )  == 0  || defer_to_typeck =>
43304334                    { 
@@ -4360,6 +4364,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43604364        qself :  & Option < P < QSelf > > , 
43614365        path :  & [ Segment ] , 
43624366        ns :  Namespace , 
4367+         source :  PathSource < ' ast > , 
43634368        finalize :  Finalize , 
43644369    )  -> Result < Option < PartialRes > ,  Spanned < ResolutionError < ' ra > > >  { 
43654370        debug ! ( 
@@ -4421,7 +4426,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44214426            ) ) ) ; 
44224427        } 
44234428
4424-         let  result = match  self . resolve_path ( path,  Some ( ns) ,  Some ( finalize) )  { 
4429+         let  result = match  self . resolve_path ( path,  Some ( ns) ,  Some ( finalize) ,  source )  { 
44254430            PathResult :: NonModule ( path_res)  => path_res, 
44264431            PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) )  if  !module. is_normal ( )  => { 
44274432                PartialRes :: new ( module. res ( ) . unwrap ( ) ) 
@@ -4642,7 +4647,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46424647            } 
46434648
46444649            ExprKind :: Struct ( ref  se)  => { 
4645-                 self . smart_resolve_path ( expr. id ,  & se. qself ,  & se. path ,  PathSource :: Struct ) ; 
4650+                 self . smart_resolve_path ( expr. id ,  & se. qself ,  & se. path ,  PathSource :: Struct ( parent ) ) ; 
46464651                // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the 
46474652                // parent in for accurate suggestions when encountering `Foo { bar }` that should 
46484653                // have been `Foo { bar: self.bar }`. 
0 commit comments