@@ -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 ,
@@ -1515,11 +1515,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1515
1515
path : & [ Segment ] ,
1516
1516
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1517
1517
finalize : Option < Finalize > ,
1518
+ source : PathSource < ' _ , ' ast , ' ra > ,
1518
1519
) -> PathResult < ' ra > {
1519
1520
self . r . resolve_path_with_ribs (
1520
1521
path,
1521
1522
opt_ns,
1522
1523
& self . parent_scope ,
1524
+ Some ( source) ,
1523
1525
finalize,
1524
1526
Some ( & self . ribs ) ,
1525
1527
None ,
@@ -1999,7 +2001,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1999
2001
& mut self ,
2000
2002
partial_res : PartialRes ,
2001
2003
path : & [ Segment ] ,
2002
- source : PathSource < ' _ , ' _ , ' _ > ,
2004
+ source : PathSource < ' _ , ' ast , ' ra > ,
2003
2005
path_span : Span ,
2004
2006
) {
2005
2007
let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -2052,7 +2054,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2052
2054
| PathSource :: ReturnTypeNotation => false ,
2053
2055
PathSource :: Expr ( ..)
2054
2056
| PathSource :: Pat
2055
- | PathSource :: Struct
2057
+ | PathSource :: Struct ( _ )
2056
2058
| PathSource :: TupleStruct ( ..)
2057
2059
| PathSource :: DefineOpaques
2058
2060
| PathSource :: Delegation => true ,
@@ -3880,7 +3882,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3880
3882
self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
3881
3883
}
3882
3884
PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3883
- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3885
+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
3884
3886
self . record_patterns_with_skipped_bindings ( pat, rest) ;
3885
3887
}
3886
3888
PatKind :: Or ( ref ps) => {
@@ -4124,7 +4126,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4124
4126
id : NodeId ,
4125
4127
qself : & Option < P < QSelf > > ,
4126
4128
path : & Path ,
4127
- source : PathSource < ' _ , ' ast , ' _ > ,
4129
+ source : PathSource < ' _ , ' ast , ' ra > ,
4128
4130
) {
4129
4131
self . smart_resolve_path_fragment (
4130
4132
qself,
@@ -4141,7 +4143,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4141
4143
& mut self ,
4142
4144
qself : & Option < P < QSelf > > ,
4143
4145
path : & [ Segment ] ,
4144
- source : PathSource < ' _ , ' ast , ' _ > ,
4146
+ source : PathSource < ' _ , ' ast , ' ra > ,
4145
4147
finalize : Finalize ,
4146
4148
record_partial_res : RecordPartialRes ,
4147
4149
parent_qself : Option < & QSelf > ,
@@ -4371,7 +4373,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4371
4373
std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
4372
4374
std_path. extend ( path) ;
4373
4375
if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4374
- self . resolve_path ( & std_path, Some ( ns) , None )
4376
+ self . resolve_path ( & std_path, Some ( ns) , None , source )
4375
4377
{
4376
4378
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
4377
4379
let item_span =
@@ -4445,7 +4447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4445
4447
span : Span ,
4446
4448
defer_to_typeck : bool ,
4447
4449
finalize : Finalize ,
4448
- source : PathSource < ' _ , ' ast , ' _ > ,
4450
+ source : PathSource < ' _ , ' ast , ' ra > ,
4449
4451
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4450
4452
let mut fin_res = None ;
4451
4453
@@ -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