@@ -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" ,
@@ -535,7 +535,7 @@ impl<'a> PathSource<'a> {
535535 || matches ! ( res, Res :: Def ( DefKind :: Const | DefKind :: AssocConst , _) )
536536 }
537537 PathSource :: TupleStruct ( ..) => res. expected_in_tuple_struct_pat ( ) ,
538- PathSource :: Struct => matches ! (
538+ PathSource :: Struct ( _ ) => matches ! (
539539 res,
540540 Res :: Def (
541541 DefKind :: Struct
@@ -575,8 +575,8 @@ impl<'a> PathSource<'a> {
575575 ( PathSource :: Trait ( _) , false ) => E0405 ,
576576 ( PathSource :: Type , true ) => E0573 ,
577577 ( PathSource :: Type , false ) => E0412 ,
578- ( PathSource :: Struct , true ) => E0574 ,
579- ( PathSource :: Struct , false ) => E0422 ,
578+ ( PathSource :: Struct ( _ ) , true ) => E0574 ,
579+ ( PathSource :: Struct ( _ ) , false ) => E0422 ,
580580 ( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
581581 ( PathSource :: Expr ( ..) , false ) | ( PathSource :: Delegation , false ) => E0425 ,
582582 ( PathSource :: Pat | PathSource :: TupleStruct ( ..) , true ) => E0532 ,
@@ -1461,11 +1461,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14611461 path : & [ Segment ] ,
14621462 opt_ns : Option < Namespace > , // `None` indicates a module path in import
14631463 finalize : Option < Finalize > ,
1464+ source : PathSource < ' ast > ,
14641465 ) -> PathResult < ' ra > {
14651466 self . r . resolve_path_with_ribs (
14661467 path,
14671468 opt_ns,
14681469 & self . parent_scope ,
1470+ Some ( source) ,
14691471 finalize,
14701472 Some ( & self . ribs ) ,
14711473 None ,
@@ -1975,7 +1977,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19751977 | PathSource :: ReturnTypeNotation => false ,
19761978 PathSource :: Expr ( ..)
19771979 | PathSource :: Pat
1978- | PathSource :: Struct
1980+ | PathSource :: Struct ( _ )
19791981 | PathSource :: TupleStruct ( ..)
19801982 | PathSource :: Delegation => true ,
19811983 } ;
@@ -3816,7 +3818,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38163818 self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
38173819 }
38183820 PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3819- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3821+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
38203822 self . record_patterns_with_skipped_bindings ( pat, rest) ;
38213823 }
38223824 PatKind :: Or ( ref ps) => {
@@ -4222,6 +4224,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
42224224 qself,
42234225 path,
42244226 ns,
4227+ source,
42254228 path_span,
42264229 source. defer_to_typeck ( ) ,
42274230 finalize,
@@ -4267,7 +4270,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
42674270 std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
42684271 std_path. extend ( path) ;
42694272 if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4270- self . resolve_path ( & std_path, Some ( ns) , None )
4273+ self . resolve_path ( & std_path, Some ( ns) , None , source )
42714274 {
42724275 // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
42734276 let item_span =
@@ -4338,6 +4341,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43384341 qself : & Option < P < QSelf > > ,
43394342 path : & [ Segment ] ,
43404343 primary_ns : Namespace ,
4344+ source : PathSource < ' ast > ,
43414345 span : Span ,
43424346 defer_to_typeck : bool ,
43434347 finalize : Finalize ,
@@ -4346,7 +4350,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43464350
43474351 for ( i, & ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . enumerate ( ) {
43484352 if i == 0 || ns != primary_ns {
4349- match self . resolve_qpath ( qself, path, ns, finalize) ? {
4353+ match self . resolve_qpath ( qself, path, ns, source , finalize) ? {
43504354 Some ( partial_res)
43514355 if partial_res. unresolved_segments ( ) == 0 || defer_to_typeck =>
43524356 {
@@ -4382,6 +4386,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43824386 qself : & Option < P < QSelf > > ,
43834387 path : & [ Segment ] ,
43844388 ns : Namespace ,
4389+ source : PathSource < ' ast > ,
43854390 finalize : Finalize ,
43864391 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
43874392 debug ! (
@@ -4443,7 +4448,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44434448 ) ) ) ;
44444449 }
44454450
4446- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4451+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
44474452 PathResult :: NonModule ( path_res) => path_res,
44484453 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
44494454 PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4664,7 +4669,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46644669 }
46654670
46664671 ExprKind :: Struct ( ref se) => {
4667- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4672+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
46684673 // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
46694674 // parent in for accurate suggestions when encountering `Foo { bar }` that should
46704675 // have been `Foo { bar: self.bar }`.
0 commit comments