@@ -424,7 +424,7 @@ pub(crate) enum PathSource<'a, 'ast, 'ra> {
424424 /// Paths in path patterns `Path`.
425425 Pat ,
426426 /// Paths in struct expressions and patterns `Path { .. }`.
427- Struct ,
427+ Struct ( Option < & ' a Expr > ) ,
428428 /// Paths in tuple struct patterns `Path(..)`.
429429 TupleStruct ( Span , & ' ra [ Span ] ) ,
430430 /// `m::A::B` in `<T as m::A>::B::C`.
@@ -447,7 +447,7 @@ impl PathSource<'_, '_, '_> {
447447 match self {
448448 PathSource :: Type
449449 | PathSource :: Trait ( _)
450- | PathSource :: Struct
450+ | PathSource :: Struct ( _ )
451451 | PathSource :: DefineOpaques => TypeNS ,
452452 PathSource :: Expr ( ..)
453453 | PathSource :: Pat
@@ -464,7 +464,7 @@ impl PathSource<'_, '_, '_> {
464464 PathSource :: Type
465465 | PathSource :: Expr ( ..)
466466 | PathSource :: Pat
467- | PathSource :: Struct
467+ | PathSource :: Struct ( _ )
468468 | PathSource :: TupleStruct ( ..)
469469 | PathSource :: ReturnTypeNotation => true ,
470470 PathSource :: Trait ( _)
@@ -481,7 +481,7 @@ impl PathSource<'_, '_, '_> {
481481 PathSource :: Type => "type" ,
482482 PathSource :: Trait ( _) => "trait" ,
483483 PathSource :: Pat => "unit struct, unit variant or constant" ,
484- PathSource :: Struct => "struct, variant or union type" ,
484+ PathSource :: Struct ( _ ) => "struct, variant or union type" ,
485485 PathSource :: TraitItem ( ValueNS , PathSource :: TupleStruct ( ..) )
486486 | PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
487487 PathSource :: TraitItem ( ns, _) => match ns {
@@ -576,7 +576,7 @@ impl PathSource<'_, '_, '_> {
576576 || matches ! ( res, Res :: Def ( DefKind :: Const | DefKind :: AssocConst , _) )
577577 }
578578 PathSource :: TupleStruct ( ..) => res. expected_in_tuple_struct_pat ( ) ,
579- PathSource :: Struct => matches ! (
579+ PathSource :: Struct ( _ ) => matches ! (
580580 res,
581581 Res :: Def (
582582 DefKind :: Struct
@@ -616,8 +616,8 @@ impl PathSource<'_, '_, '_> {
616616 ( PathSource :: Trait ( _) , false ) => E0405 ,
617617 ( PathSource :: Type | PathSource :: DefineOpaques , true ) => E0573 ,
618618 ( PathSource :: Type | PathSource :: DefineOpaques , false ) => E0412 ,
619- ( PathSource :: Struct , true ) => E0574 ,
620- ( PathSource :: Struct , false ) => E0422 ,
619+ ( PathSource :: Struct ( _ ) , true ) => E0574 ,
620+ ( PathSource :: Struct ( _ ) , false ) => E0422 ,
621621 ( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
622622 ( PathSource :: Expr ( ..) , false ) | ( PathSource :: Delegation , false ) => E0425 ,
623623 ( PathSource :: Pat | PathSource :: TupleStruct ( ..) , true ) => E0532 ,
@@ -1482,11 +1482,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14821482 path : & [ Segment ] ,
14831483 opt_ns : Option < Namespace > , // `None` indicates a module path in import
14841484 finalize : Option < Finalize > ,
1485+ source : PathSource < ' _ , ' ast , ' ra > ,
14851486 ) -> PathResult < ' ra > {
14861487 self . r . cm ( ) . resolve_path_with_ribs (
14871488 path,
14881489 opt_ns,
14891490 & self . parent_scope ,
1491+ Some ( source) ,
14901492 finalize,
14911493 Some ( & self . ribs ) ,
14921494 None ,
@@ -1966,7 +1968,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19661968 & mut self ,
19671969 partial_res : PartialRes ,
19681970 path : & [ Segment ] ,
1969- source : PathSource < ' _ , ' _ , ' _ > ,
1971+ source : PathSource < ' _ , ' ast , ' ra > ,
19701972 path_span : Span ,
19711973 ) {
19721974 let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -2019,7 +2021,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
20192021 | PathSource :: ReturnTypeNotation => false ,
20202022 PathSource :: Expr ( ..)
20212023 | PathSource :: Pat
2022- | PathSource :: Struct
2024+ | PathSource :: Struct ( _ )
20232025 | PathSource :: TupleStruct ( ..)
20242026 | PathSource :: DefineOpaques
20252027 | PathSource :: Delegation => true ,
@@ -3866,7 +3868,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38663868 self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
38673869 }
38683870 PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3869- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3871+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
38703872 self . record_patterns_with_skipped_bindings ( pat, rest) ;
38713873 }
38723874 PatKind :: Or ( ref ps) => {
@@ -4110,7 +4112,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41104112 id : NodeId ,
41114113 qself : & Option < Box < QSelf > > ,
41124114 path : & Path ,
4113- source : PathSource < ' _ , ' ast , ' _ > ,
4115+ source : PathSource < ' _ , ' ast , ' ra > ,
41144116 ) {
41154117 self . smart_resolve_path_fragment (
41164118 qself,
@@ -4127,7 +4129,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41274129 & mut self ,
41284130 qself : & Option < Box < QSelf > > ,
41294131 path : & [ Segment ] ,
4130- source : PathSource < ' _ , ' ast , ' _ > ,
4132+ source : PathSource < ' _ , ' ast , ' ra > ,
41314133 finalize : Finalize ,
41324134 record_partial_res : RecordPartialRes ,
41334135 parent_qself : Option < & QSelf > ,
@@ -4365,7 +4367,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43654367 std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
43664368 std_path. extend ( path) ;
43674369 if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4368- self . resolve_path ( & std_path, Some ( ns) , None )
4370+ self . resolve_path ( & std_path, Some ( ns) , None , source )
43694371 {
43704372 // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
43714373 let item_span =
@@ -4439,7 +4441,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44394441 span : Span ,
44404442 defer_to_typeck : bool ,
44414443 finalize : Finalize ,
4442- source : PathSource < ' _ , ' ast , ' _ > ,
4444+ source : PathSource < ' _ , ' ast , ' ra > ,
44434445 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
44444446 let mut fin_res = None ;
44454447
@@ -4488,7 +4490,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44884490 path : & [ Segment ] ,
44894491 ns : Namespace ,
44904492 finalize : Finalize ,
4491- source : PathSource < ' _ , ' ast , ' _ > ,
4493+ source : PathSource < ' _ , ' ast , ' ra > ,
44924494 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
44934495 debug ! (
44944496 "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4551,7 +4553,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45514553 ) ) ) ;
45524554 }
45534555
4554- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4556+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
45554557 PathResult :: NonModule ( path_res) => path_res,
45564558 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
45574559 PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4774,7 +4776,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
47744776 }
47754777
47764778 ExprKind :: Struct ( ref se) => {
4777- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4779+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
47784780 // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
47794781 // parent in for accurate suggestions when encountering `Foo { bar }` that should
47804782 // have been `Foo { bar: self.bar }`.
0 commit comments