@@ -425,7 +425,7 @@ pub(crate) enum PathSource<'a, 'ast, 'ra> {
425425 /// Paths in path patterns `Path`.
426426 Pat ,
427427 /// Paths in struct expressions and patterns `Path { .. }`.
428- Struct ,
428+ Struct ( Option < & ' a Expr > ) ,
429429 /// Paths in tuple struct patterns `Path(..)`.
430430 TupleStruct ( Span , & ' ra [ Span ] ) ,
431431 /// `m::A::B` in `<T as m::A>::B::C`.
@@ -448,7 +448,7 @@ impl PathSource<'_, '_, '_> {
448448 match self {
449449 PathSource :: Type
450450 | PathSource :: Trait ( _)
451- | PathSource :: Struct
451+ | PathSource :: Struct ( _ )
452452 | PathSource :: DefineOpaques => TypeNS ,
453453 PathSource :: Expr ( ..)
454454 | PathSource :: Pat
@@ -465,7 +465,7 @@ impl PathSource<'_, '_, '_> {
465465 PathSource :: Type
466466 | PathSource :: Expr ( ..)
467467 | PathSource :: Pat
468- | PathSource :: Struct
468+ | PathSource :: Struct ( _ )
469469 | PathSource :: TupleStruct ( ..)
470470 | PathSource :: ReturnTypeNotation => true ,
471471 PathSource :: Trait ( _)
@@ -482,7 +482,7 @@ impl PathSource<'_, '_, '_> {
482482 PathSource :: Type => "type" ,
483483 PathSource :: Trait ( _) => "trait" ,
484484 PathSource :: Pat => "unit struct, unit variant or constant" ,
485- PathSource :: Struct => "struct, variant or union type" ,
485+ PathSource :: Struct ( _ ) => "struct, variant or union type" ,
486486 PathSource :: TraitItem ( ValueNS , PathSource :: TupleStruct ( ..) )
487487 | PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
488488 PathSource :: TraitItem ( ns, _) => match ns {
@@ -577,7 +577,7 @@ impl PathSource<'_, '_, '_> {
577577 || matches ! ( res, Res :: Def ( DefKind :: Const | DefKind :: AssocConst , _) )
578578 }
579579 PathSource :: TupleStruct ( ..) => res. expected_in_tuple_struct_pat ( ) ,
580- PathSource :: Struct => matches ! (
580+ PathSource :: Struct ( _ ) => matches ! (
581581 res,
582582 Res :: Def (
583583 DefKind :: Struct
@@ -617,8 +617,8 @@ impl PathSource<'_, '_, '_> {
617617 ( PathSource :: Trait ( _) , false ) => E0405 ,
618618 ( PathSource :: Type | PathSource :: DefineOpaques , true ) => E0573 ,
619619 ( PathSource :: Type | PathSource :: DefineOpaques , false ) => E0412 ,
620- ( PathSource :: Struct , true ) => E0574 ,
621- ( PathSource :: Struct , false ) => E0422 ,
620+ ( PathSource :: Struct ( _ ) , true ) => E0574 ,
621+ ( PathSource :: Struct ( _ ) , false ) => E0422 ,
622622 ( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
623623 ( PathSource :: Expr ( ..) , false ) | ( PathSource :: Delegation , false ) => E0425 ,
624624 ( PathSource :: Pat | PathSource :: TupleStruct ( ..) , true ) => E0532 ,
@@ -1483,11 +1483,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14831483 path : & [ Segment ] ,
14841484 opt_ns : Option < Namespace > , // `None` indicates a module path in import
14851485 finalize : Option < Finalize > ,
1486+ source : PathSource < ' _ , ' ast , ' ra > ,
14861487 ) -> PathResult < ' ra > {
14871488 self . r . resolve_path_with_ribs (
14881489 path,
14891490 opt_ns,
14901491 & self . parent_scope ,
1492+ Some ( source) ,
14911493 finalize,
14921494 Some ( & self . ribs ) ,
14931495 None ,
@@ -1967,7 +1969,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19671969 & mut self ,
19681970 partial_res : PartialRes ,
19691971 path : & [ Segment ] ,
1970- source : PathSource < ' _ , ' _ , ' _ > ,
1972+ source : PathSource < ' _ , ' ast , ' ra > ,
19711973 path_span : Span ,
19721974 ) {
19731975 let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -2020,7 +2022,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
20202022 | PathSource :: ReturnTypeNotation => false ,
20212023 PathSource :: Expr ( ..)
20222024 | PathSource :: Pat
2023- | PathSource :: Struct
2025+ | PathSource :: Struct ( _ )
20242026 | PathSource :: TupleStruct ( ..)
20252027 | PathSource :: DefineOpaques
20262028 | PathSource :: Delegation => true ,
@@ -3867,7 +3869,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38673869 self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
38683870 }
38693871 PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3870- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3872+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
38713873 self . record_patterns_with_skipped_bindings ( pat, rest) ;
38723874 }
38733875 PatKind :: Or ( ref ps) => {
@@ -4111,7 +4113,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41114113 id : NodeId ,
41124114 qself : & Option < P < QSelf > > ,
41134115 path : & Path ,
4114- source : PathSource < ' _ , ' ast , ' _ > ,
4116+ source : PathSource < ' _ , ' ast , ' ra > ,
41154117 ) {
41164118 self . smart_resolve_path_fragment (
41174119 qself,
@@ -4128,7 +4130,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41284130 & mut self ,
41294131 qself : & Option < P < QSelf > > ,
41304132 path : & [ Segment ] ,
4131- source : PathSource < ' _ , ' ast , ' _ > ,
4133+ source : PathSource < ' _ , ' ast , ' ra > ,
41324134 finalize : Finalize ,
41334135 record_partial_res : RecordPartialRes ,
41344136 parent_qself : Option < & QSelf > ,
@@ -4358,7 +4360,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43584360 std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
43594361 std_path. extend ( path) ;
43604362 if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4361- self . resolve_path ( & std_path, Some ( ns) , None )
4363+ self . resolve_path ( & std_path, Some ( ns) , None , source )
43624364 {
43634365 // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
43644366 let item_span =
@@ -4432,7 +4434,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44324434 span : Span ,
44334435 defer_to_typeck : bool ,
44344436 finalize : Finalize ,
4435- source : PathSource < ' _ , ' ast , ' _ > ,
4437+ source : PathSource < ' _ , ' ast , ' ra > ,
44364438 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
44374439 let mut fin_res = None ;
44384440
@@ -4475,7 +4477,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44754477 path : & [ Segment ] ,
44764478 ns : Namespace ,
44774479 finalize : Finalize ,
4478- source : PathSource < ' _ , ' ast , ' _ > ,
4480+ source : PathSource < ' _ , ' ast , ' ra > ,
44794481 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
44804482 debug ! (
44814483 "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4538,7 +4540,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45384540 ) ) ) ;
45394541 }
45404542
4541- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4543+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
45424544 PathResult :: NonModule ( path_res) => path_res,
45434545 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
45444546 PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4761,7 +4763,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
47614763 }
47624764
47634765 ExprKind :: Struct ( ref se) => {
4764- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4766+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
47654767 // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
47664768 // parent in for accurate suggestions when encountering `Foo { bar }` that should
47674769 // have been `Foo { bar: self.bar }`.
0 commit comments