@@ -424,7 +424,7 @@ pub(crate) enum PathSource<'a, 'ast, 'ra> {
424
424
/// Paths in path patterns `Path`.
425
425
Pat ,
426
426
/// Paths in struct expressions and patterns `Path { .. }`.
427
- Struct ,
427
+ Struct ( Option < & ' a Expr > ) ,
428
428
/// Paths in tuple struct patterns `Path(..)`.
429
429
TupleStruct ( Span , & ' ra [ Span ] ) ,
430
430
/// `m::A::B` in `<T as m::A>::B::C`.
@@ -447,7 +447,7 @@ impl PathSource<'_, '_, '_> {
447
447
match self {
448
448
PathSource :: Type
449
449
| PathSource :: Trait ( _)
450
- | PathSource :: Struct
450
+ | PathSource :: Struct ( _ )
451
451
| PathSource :: DefineOpaques => TypeNS ,
452
452
PathSource :: Expr ( ..)
453
453
| PathSource :: Pat
@@ -464,7 +464,7 @@ impl PathSource<'_, '_, '_> {
464
464
PathSource :: Type
465
465
| PathSource :: Expr ( ..)
466
466
| PathSource :: Pat
467
- | PathSource :: Struct
467
+ | PathSource :: Struct ( _ )
468
468
| PathSource :: TupleStruct ( ..)
469
469
| PathSource :: ReturnTypeNotation => true ,
470
470
PathSource :: Trait ( _)
@@ -481,7 +481,7 @@ impl PathSource<'_, '_, '_> {
481
481
PathSource :: Type => "type" ,
482
482
PathSource :: Trait ( _) => "trait" ,
483
483
PathSource :: Pat => "unit struct, unit variant or constant" ,
484
- PathSource :: Struct => "struct, variant or union type" ,
484
+ PathSource :: Struct ( _ ) => "struct, variant or union type" ,
485
485
PathSource :: TraitItem ( ValueNS , PathSource :: TupleStruct ( ..) )
486
486
| PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
487
487
PathSource :: TraitItem ( ns, _) => match ns {
@@ -576,7 +576,7 @@ impl PathSource<'_, '_, '_> {
576
576
|| matches ! ( res, Res :: Def ( DefKind :: Const | DefKind :: AssocConst , _) )
577
577
}
578
578
PathSource :: TupleStruct ( ..) => res. expected_in_tuple_struct_pat ( ) ,
579
- PathSource :: Struct => matches ! (
579
+ PathSource :: Struct ( _ ) => matches ! (
580
580
res,
581
581
Res :: Def (
582
582
DefKind :: Struct
@@ -616,8 +616,8 @@ impl PathSource<'_, '_, '_> {
616
616
( PathSource :: Trait ( _) , false ) => E0405 ,
617
617
( PathSource :: Type | PathSource :: DefineOpaques , true ) => E0573 ,
618
618
( 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 ,
621
621
( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
622
622
( PathSource :: Expr ( ..) , false ) | ( PathSource :: Delegation , false ) => E0425 ,
623
623
( PathSource :: Pat | PathSource :: TupleStruct ( ..) , true ) => E0532 ,
@@ -1482,11 +1482,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1482
1482
path : & [ Segment ] ,
1483
1483
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1484
1484
finalize : Option < Finalize > ,
1485
+ source : PathSource < ' _ , ' ast , ' ra > ,
1485
1486
) -> PathResult < ' ra > {
1486
1487
self . r . cm ( ) . resolve_path_with_ribs (
1487
1488
path,
1488
1489
opt_ns,
1489
1490
& self . parent_scope ,
1491
+ Some ( source) ,
1490
1492
finalize,
1491
1493
Some ( & self . ribs ) ,
1492
1494
None ,
@@ -1966,7 +1968,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1966
1968
& mut self ,
1967
1969
partial_res : PartialRes ,
1968
1970
path : & [ Segment ] ,
1969
- source : PathSource < ' _ , ' _ , ' _ > ,
1971
+ source : PathSource < ' _ , ' ast , ' ra > ,
1970
1972
path_span : Span ,
1971
1973
) {
1972
1974
let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -2019,7 +2021,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2019
2021
| PathSource :: ReturnTypeNotation => false ,
2020
2022
PathSource :: Expr ( ..)
2021
2023
| PathSource :: Pat
2022
- | PathSource :: Struct
2024
+ | PathSource :: Struct ( _ )
2023
2025
| PathSource :: TupleStruct ( ..)
2024
2026
| PathSource :: DefineOpaques
2025
2027
| PathSource :: Delegation => true ,
@@ -3866,7 +3868,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3866
3868
self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
3867
3869
}
3868
3870
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 ) ) ;
3870
3872
self . record_patterns_with_skipped_bindings ( pat, rest) ;
3871
3873
}
3872
3874
PatKind :: Or ( ref ps) => {
@@ -4110,7 +4112,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4110
4112
id : NodeId ,
4111
4113
qself : & Option < Box < QSelf > > ,
4112
4114
path : & Path ,
4113
- source : PathSource < ' _ , ' ast , ' _ > ,
4115
+ source : PathSource < ' _ , ' ast , ' ra > ,
4114
4116
) {
4115
4117
self . smart_resolve_path_fragment (
4116
4118
qself,
@@ -4127,7 +4129,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4127
4129
& mut self ,
4128
4130
qself : & Option < Box < QSelf > > ,
4129
4131
path : & [ Segment ] ,
4130
- source : PathSource < ' _ , ' ast , ' _ > ,
4132
+ source : PathSource < ' _ , ' ast , ' ra > ,
4131
4133
finalize : Finalize ,
4132
4134
record_partial_res : RecordPartialRes ,
4133
4135
parent_qself : Option < & QSelf > ,
@@ -4365,7 +4367,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4365
4367
std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
4366
4368
std_path. extend ( path) ;
4367
4369
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 )
4369
4371
{
4370
4372
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
4371
4373
let item_span =
@@ -4439,7 +4441,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4439
4441
span : Span ,
4440
4442
defer_to_typeck : bool ,
4441
4443
finalize : Finalize ,
4442
- source : PathSource < ' _ , ' ast , ' _ > ,
4444
+ source : PathSource < ' _ , ' ast , ' ra > ,
4443
4445
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4444
4446
let mut fin_res = None ;
4445
4447
@@ -4488,7 +4490,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4488
4490
path : & [ Segment ] ,
4489
4491
ns : Namespace ,
4490
4492
finalize : Finalize ,
4491
- source : PathSource < ' _ , ' ast , ' _ > ,
4493
+ source : PathSource < ' _ , ' ast , ' ra > ,
4492
4494
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4493
4495
debug ! (
4494
4496
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4551,7 +4553,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4551
4553
) ) ) ;
4552
4554
}
4553
4555
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 ) {
4555
4557
PathResult :: NonModule ( path_res) => path_res,
4556
4558
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
4557
4559
PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4774,7 +4776,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4774
4776
}
4775
4777
4776
4778
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 ) ) ;
4778
4780
// This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
4779
4781
// parent in for accurate suggestions when encountering `Foo { bar }` that should
4780
4782
// have been `Foo { bar: self.bar }`.
0 commit comments