@@ -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 ,
@@ -1511,11 +1511,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1511
1511
path : & [ Segment ] ,
1512
1512
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1513
1513
finalize : Option < Finalize > ,
1514
+ source : PathSource < ' _ , ' ast , ' ra > ,
1514
1515
) -> PathResult < ' ra > {
1515
1516
self . r . resolve_path_with_ribs (
1516
1517
path,
1517
1518
opt_ns,
1518
1519
& self . parent_scope ,
1520
+ Some ( source) ,
1519
1521
finalize,
1520
1522
Some ( & self . ribs ) ,
1521
1523
None ,
@@ -1995,7 +1997,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1995
1997
& mut self ,
1996
1998
partial_res : PartialRes ,
1997
1999
path : & [ Segment ] ,
1998
- source : PathSource < ' _ , ' _ , ' _ > ,
2000
+ source : PathSource < ' _ , ' ast , ' ra > ,
1999
2001
path_span : Span ,
2000
2002
) {
2001
2003
let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -2048,7 +2050,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2048
2050
| PathSource :: ReturnTypeNotation => false ,
2049
2051
PathSource :: Expr ( ..)
2050
2052
| PathSource :: Pat
2051
- | PathSource :: Struct
2053
+ | PathSource :: Struct ( _ )
2052
2054
| PathSource :: TupleStruct ( ..)
2053
2055
| PathSource :: DefineOpaques
2054
2056
| PathSource :: Delegation => true ,
@@ -3878,7 +3880,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3878
3880
self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
3879
3881
}
3880
3882
PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3881
- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3883
+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
3882
3884
self . record_patterns_with_skipped_bindings ( pat, rest) ;
3883
3885
}
3884
3886
PatKind :: Or ( ref ps) => {
@@ -4122,7 +4124,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4122
4124
id : NodeId ,
4123
4125
qself : & Option < P < QSelf > > ,
4124
4126
path : & Path ,
4125
- source : PathSource < ' _ , ' ast , ' _ > ,
4127
+ source : PathSource < ' _ , ' ast , ' ra > ,
4126
4128
) {
4127
4129
self . smart_resolve_path_fragment (
4128
4130
qself,
@@ -4139,7 +4141,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4139
4141
& mut self ,
4140
4142
qself : & Option < P < QSelf > > ,
4141
4143
path : & [ Segment ] ,
4142
- source : PathSource < ' _ , ' ast , ' _ > ,
4144
+ source : PathSource < ' _ , ' ast , ' ra > ,
4143
4145
finalize : Finalize ,
4144
4146
record_partial_res : RecordPartialRes ,
4145
4147
parent_qself : Option < & QSelf > ,
@@ -4369,7 +4371,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4369
4371
std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
4370
4372
std_path. extend ( path) ;
4371
4373
if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4372
- self . resolve_path ( & std_path, Some ( ns) , None )
4374
+ self . resolve_path ( & std_path, Some ( ns) , None , source )
4373
4375
{
4374
4376
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
4375
4377
let item_span =
@@ -4443,7 +4445,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4443
4445
span : Span ,
4444
4446
defer_to_typeck : bool ,
4445
4447
finalize : Finalize ,
4446
- source : PathSource < ' _ , ' ast , ' _ > ,
4448
+ source : PathSource < ' _ , ' ast , ' ra > ,
4447
4449
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4448
4450
let mut fin_res = None ;
4449
4451
@@ -4486,7 +4488,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4486
4488
path : & [ Segment ] ,
4487
4489
ns : Namespace ,
4488
4490
finalize : Finalize ,
4489
- source : PathSource < ' _ , ' ast , ' _ > ,
4491
+ source : PathSource < ' _ , ' ast , ' ra > ,
4490
4492
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4491
4493
debug ! (
4492
4494
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4549,7 +4551,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4549
4551
) ) ) ;
4550
4552
}
4551
4553
4552
- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4554
+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
4553
4555
PathResult :: NonModule ( path_res) => path_res,
4554
4556
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
4555
4557
PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4772,7 +4774,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4772
4774
}
4773
4775
4774
4776
ExprKind :: Struct ( ref se) => {
4775
- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4777
+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
4776
4778
// This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
4777
4779
// parent in for accurate suggestions when encountering `Foo { bar }` that should
4778
4780
// have been `Foo { bar: self.bar }`.
0 commit comments