@@ -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 ,
@@ -1511,11 +1511,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15111511 path : & [ Segment ] ,
15121512 opt_ns : Option < Namespace > , // `None` indicates a module path in import
15131513 finalize : Option < Finalize > ,
1514+ source : PathSource < ' _ , ' ast , ' ra > ,
15141515 ) -> PathResult < ' ra > {
15151516 self . r . resolve_path_with_ribs (
15161517 path,
15171518 opt_ns,
15181519 & self . parent_scope ,
1520+ Some ( source) ,
15191521 finalize,
15201522 Some ( & self . ribs ) ,
15211523 None ,
@@ -1995,7 +1997,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19951997 & mut self ,
19961998 partial_res : PartialRes ,
19971999 path : & [ Segment ] ,
1998- source : PathSource < ' _ , ' _ , ' _ > ,
2000+ source : PathSource < ' _ , ' ast , ' ra > ,
19992001 path_span : Span ,
20002002 ) {
20012003 let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -2048,7 +2050,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
20482050 | PathSource :: ReturnTypeNotation => false ,
20492051 PathSource :: Expr ( ..)
20502052 | PathSource :: Pat
2051- | PathSource :: Struct
2053+ | PathSource :: Struct ( _ )
20522054 | PathSource :: TupleStruct ( ..)
20532055 | PathSource :: DefineOpaques
20542056 | PathSource :: Delegation => true ,
@@ -3878,7 +3880,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38783880 self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
38793881 }
38803882 PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3881- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3883+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
38823884 self . record_patterns_with_skipped_bindings ( pat, rest) ;
38833885 }
38843886 PatKind :: Or ( ref ps) => {
@@ -4122,7 +4124,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41224124 id : NodeId ,
41234125 qself : & Option < P < QSelf > > ,
41244126 path : & Path ,
4125- source : PathSource < ' _ , ' ast , ' _ > ,
4127+ source : PathSource < ' _ , ' ast , ' ra > ,
41264128 ) {
41274129 self . smart_resolve_path_fragment (
41284130 qself,
@@ -4139,7 +4141,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41394141 & mut self ,
41404142 qself : & Option < P < QSelf > > ,
41414143 path : & [ Segment ] ,
4142- source : PathSource < ' _ , ' ast , ' _ > ,
4144+ source : PathSource < ' _ , ' ast , ' ra > ,
41434145 finalize : Finalize ,
41444146 record_partial_res : RecordPartialRes ,
41454147 parent_qself : Option < & QSelf > ,
@@ -4369,7 +4371,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43694371 std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
43704372 std_path. extend ( path) ;
43714373 if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4372- self . resolve_path ( & std_path, Some ( ns) , None )
4374+ self . resolve_path ( & std_path, Some ( ns) , None , source )
43734375 {
43744376 // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
43754377 let item_span =
@@ -4443,7 +4445,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44434445 span : Span ,
44444446 defer_to_typeck : bool ,
44454447 finalize : Finalize ,
4446- source : PathSource < ' _ , ' ast , ' _ > ,
4448+ source : PathSource < ' _ , ' ast , ' ra > ,
44474449 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
44484450 let mut fin_res = None ;
44494451
@@ -4486,7 +4488,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44864488 path : & [ Segment ] ,
44874489 ns : Namespace ,
44884490 finalize : Finalize ,
4489- source : PathSource < ' _ , ' ast , ' _ > ,
4491+ source : PathSource < ' _ , ' ast , ' ra > ,
44904492 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
44914493 debug ! (
44924494 "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4549,7 +4551,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45494551 ) ) ) ;
45504552 }
45514553
4552- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4554+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
45534555 PathResult :: NonModule ( path_res) => path_res,
45544556 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
45554557 PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4772,7 +4774,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
47724774 }
47734775
47744776 ExprKind :: Struct ( ref se) => {
4775- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4777+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
47764778 // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
47774779 // parent in for accurate suggestions when encountering `Foo { bar }` that should
47784780 // have been `Foo { bar: self.bar }`.
0 commit comments