@@ -425,7 +425,7 @@ pub(crate) enum PathSource<'a, 'ast, 'ra> {
425
425
/// Paths in path patterns `Path`.
426
426
Pat ,
427
427
/// Paths in struct expressions and patterns `Path { .. }`.
428
- Struct ,
428
+ Struct ( Option < & ' a Expr > ) ,
429
429
/// Paths in tuple struct patterns `Path(..)`.
430
430
TupleStruct ( Span , & ' ra [ Span ] ) ,
431
431
/// `m::A::B` in `<T as m::A>::B::C`.
@@ -448,7 +448,7 @@ impl PathSource<'_, '_, '_> {
448
448
match self {
449
449
PathSource :: Type
450
450
| PathSource :: Trait ( _)
451
- | PathSource :: Struct
451
+ | PathSource :: Struct ( _ )
452
452
| PathSource :: DefineOpaques => TypeNS ,
453
453
PathSource :: Expr ( ..)
454
454
| PathSource :: Pat
@@ -465,7 +465,7 @@ impl PathSource<'_, '_, '_> {
465
465
PathSource :: Type
466
466
| PathSource :: Expr ( ..)
467
467
| PathSource :: Pat
468
- | PathSource :: Struct
468
+ | PathSource :: Struct ( _ )
469
469
| PathSource :: TupleStruct ( ..)
470
470
| PathSource :: ReturnTypeNotation => true ,
471
471
PathSource :: Trait ( _)
@@ -482,7 +482,7 @@ impl PathSource<'_, '_, '_> {
482
482
PathSource :: Type => "type" ,
483
483
PathSource :: Trait ( _) => "trait" ,
484
484
PathSource :: Pat => "unit struct, unit variant or constant" ,
485
- PathSource :: Struct => "struct, variant or union type" ,
485
+ PathSource :: Struct ( _ ) => "struct, variant or union type" ,
486
486
PathSource :: TraitItem ( ValueNS , PathSource :: TupleStruct ( ..) )
487
487
| PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
488
488
PathSource :: TraitItem ( ns, _) => match ns {
@@ -577,7 +577,7 @@ impl PathSource<'_, '_, '_> {
577
577
|| matches ! ( res, Res :: Def ( DefKind :: Const | DefKind :: AssocConst , _) )
578
578
}
579
579
PathSource :: TupleStruct ( ..) => res. expected_in_tuple_struct_pat ( ) ,
580
- PathSource :: Struct => matches ! (
580
+ PathSource :: Struct ( _ ) => matches ! (
581
581
res,
582
582
Res :: Def (
583
583
DefKind :: Struct
@@ -617,8 +617,8 @@ impl PathSource<'_, '_, '_> {
617
617
( PathSource :: Trait ( _) , false ) => E0405 ,
618
618
( PathSource :: Type | PathSource :: DefineOpaques , true ) => E0573 ,
619
619
( 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 ,
622
622
( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
623
623
( PathSource :: Expr ( ..) , false ) | ( PathSource :: Delegation , false ) => E0425 ,
624
624
( PathSource :: Pat | PathSource :: TupleStruct ( ..) , true ) => E0532 ,
@@ -1483,11 +1483,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1483
1483
path : & [ Segment ] ,
1484
1484
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1485
1485
finalize : Option < Finalize > ,
1486
+ source : PathSource < ' _ , ' ast , ' ra > ,
1486
1487
) -> PathResult < ' ra > {
1487
1488
self . r . resolve_path_with_ribs (
1488
1489
path,
1489
1490
opt_ns,
1490
1491
& self . parent_scope ,
1492
+ Some ( source) ,
1491
1493
finalize,
1492
1494
Some ( & self . ribs ) ,
1493
1495
None ,
@@ -1967,7 +1969,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1967
1969
& mut self ,
1968
1970
partial_res : PartialRes ,
1969
1971
path : & [ Segment ] ,
1970
- source : PathSource < ' _ , ' _ , ' _ > ,
1972
+ source : PathSource < ' _ , ' ast , ' ra > ,
1971
1973
path_span : Span ,
1972
1974
) {
1973
1975
let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -2020,7 +2022,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2020
2022
| PathSource :: ReturnTypeNotation => false ,
2021
2023
PathSource :: Expr ( ..)
2022
2024
| PathSource :: Pat
2023
- | PathSource :: Struct
2025
+ | PathSource :: Struct ( _ )
2024
2026
| PathSource :: TupleStruct ( ..)
2025
2027
| PathSource :: DefineOpaques
2026
2028
| PathSource :: Delegation => true ,
@@ -3867,7 +3869,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3867
3869
self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
3868
3870
}
3869
3871
PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3870
- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3872
+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
3871
3873
self . record_patterns_with_skipped_bindings ( pat, rest) ;
3872
3874
}
3873
3875
PatKind :: Or ( ref ps) => {
@@ -4111,7 +4113,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4111
4113
id : NodeId ,
4112
4114
qself : & Option < P < QSelf > > ,
4113
4115
path : & Path ,
4114
- source : PathSource < ' _ , ' ast , ' _ > ,
4116
+ source : PathSource < ' _ , ' ast , ' ra > ,
4115
4117
) {
4116
4118
self . smart_resolve_path_fragment (
4117
4119
qself,
@@ -4128,7 +4130,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4128
4130
& mut self ,
4129
4131
qself : & Option < P < QSelf > > ,
4130
4132
path : & [ Segment ] ,
4131
- source : PathSource < ' _ , ' ast , ' _ > ,
4133
+ source : PathSource < ' _ , ' ast , ' ra > ,
4132
4134
finalize : Finalize ,
4133
4135
record_partial_res : RecordPartialRes ,
4134
4136
parent_qself : Option < & QSelf > ,
@@ -4358,7 +4360,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4358
4360
std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
4359
4361
std_path. extend ( path) ;
4360
4362
if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4361
- self . resolve_path ( & std_path, Some ( ns) , None )
4363
+ self . resolve_path ( & std_path, Some ( ns) , None , source )
4362
4364
{
4363
4365
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
4364
4366
let item_span =
@@ -4432,7 +4434,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4432
4434
span : Span ,
4433
4435
defer_to_typeck : bool ,
4434
4436
finalize : Finalize ,
4435
- source : PathSource < ' _ , ' ast , ' _ > ,
4437
+ source : PathSource < ' _ , ' ast , ' ra > ,
4436
4438
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4437
4439
let mut fin_res = None ;
4438
4440
@@ -4475,7 +4477,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4475
4477
path : & [ Segment ] ,
4476
4478
ns : Namespace ,
4477
4479
finalize : Finalize ,
4478
- source : PathSource < ' _ , ' ast , ' _ > ,
4480
+ source : PathSource < ' _ , ' ast , ' ra > ,
4479
4481
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4480
4482
debug ! (
4481
4483
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4538,7 +4540,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4538
4540
) ) ) ;
4539
4541
}
4540
4542
4541
- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4543
+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
4542
4544
PathResult :: NonModule ( path_res) => path_res,
4543
4545
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
4544
4546
PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4761,7 +4763,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4761
4763
}
4762
4764
4763
4765
ExprKind :: Struct ( ref se) => {
4764
- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4766
+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
4765
4767
// This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
4766
4768
// parent in for accurate suggestions when encountering `Foo { bar }` that should
4767
4769
// have been `Foo { bar: self.bar }`.
0 commit comments