@@ -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 ,
@@ -1458,11 +1458,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14581458 path : & [ Segment ] ,
14591459 opt_ns : Option < Namespace > , // `None` indicates a module path in import
14601460 finalize : Option < Finalize > ,
1461+ source : PathSource < ' ast > ,
14611462 ) -> PathResult < ' ra > {
14621463 self . r . resolve_path_with_ribs (
14631464 path,
14641465 opt_ns,
14651466 & self . parent_scope ,
1467+ Some ( source) ,
14661468 finalize,
14671469 Some ( & self . ribs ) ,
14681470 None ,
@@ -1967,7 +1969,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19671969 | PathSource :: ReturnTypeNotation => false ,
19681970 PathSource :: Expr ( ..)
19691971 | PathSource :: Pat
1970- | PathSource :: Struct
1972+ | PathSource :: Struct ( _ )
19711973 | PathSource :: TupleStruct ( ..)
19721974 | PathSource :: Delegation => true ,
19731975 } ;
@@ -3805,7 +3807,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38053807 self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
38063808 }
38073809 PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3808- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3810+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
38093811 self . record_patterns_with_skipped_bindings ( pat, rest) ;
38103812 }
38113813 PatKind :: Or ( ref ps) => {
@@ -4214,6 +4216,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
42144216 qself,
42154217 path,
42164218 ns,
4219+ source,
42174220 path_span,
42184221 source. defer_to_typeck ( ) ,
42194222 finalize,
@@ -4259,7 +4262,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
42594262 std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
42604263 std_path. extend ( path) ;
42614264 if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4262- self . resolve_path ( & std_path, Some ( ns) , None )
4265+ self . resolve_path ( & std_path, Some ( ns) , None , source )
42634266 {
42644267 // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
42654268 let item_span =
@@ -4330,6 +4333,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43304333 qself : & Option < P < QSelf > > ,
43314334 path : & [ Segment ] ,
43324335 primary_ns : Namespace ,
4336+ source : PathSource < ' ast > ,
43334337 span : Span ,
43344338 defer_to_typeck : bool ,
43354339 finalize : Finalize ,
@@ -4338,7 +4342,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43384342
43394343 for ( i, & ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . enumerate ( ) {
43404344 if i == 0 || ns != primary_ns {
4341- match self . resolve_qpath ( qself, path, ns, finalize) ? {
4345+ match self . resolve_qpath ( qself, path, ns, source , finalize) ? {
43424346 Some ( partial_res)
43434347 if partial_res. unresolved_segments ( ) == 0 || defer_to_typeck =>
43444348 {
@@ -4374,6 +4378,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43744378 qself : & Option < P < QSelf > > ,
43754379 path : & [ Segment ] ,
43764380 ns : Namespace ,
4381+ source : PathSource < ' ast > ,
43774382 finalize : Finalize ,
43784383 ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
43794384 debug ! (
@@ -4435,7 +4440,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44354440 ) ) ) ;
44364441 }
44374442
4438- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4443+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
44394444 PathResult :: NonModule ( path_res) => path_res,
44404445 PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
44414446 PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4659,7 +4664,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46594664 }
46604665
46614666 ExprKind :: Struct ( ref se) => {
4662- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4667+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
46634668 // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
46644669 // parent in for accurate suggestions when encountering `Foo { bar }` that should
46654670 // have been `Foo { bar: self.bar }`.
0 commit comments