@@ -403,7 +403,7 @@ pub(crate) enum PathSource<'a> {
403
403
// Paths in path patterns `Path`.
404
404
Pat ,
405
405
// Paths in struct expressions and patterns `Path { .. }`.
406
- Struct ,
406
+ Struct ( Option < & ' a Expr > ) ,
407
407
// Paths in tuple struct patterns `Path(..)`.
408
408
TupleStruct ( Span , & ' a [ Span ] ) ,
409
409
// `m::A::B` in `<T as m::A>::B::C`.
@@ -419,7 +419,7 @@ pub(crate) enum PathSource<'a> {
419
419
impl < ' a > PathSource < ' a > {
420
420
fn namespace ( self ) -> Namespace {
421
421
match self {
422
- PathSource :: Type | PathSource :: Trait ( _) | PathSource :: Struct => TypeNS ,
422
+ PathSource :: Type | PathSource :: Trait ( _) | PathSource :: Struct ( _ ) => TypeNS ,
423
423
PathSource :: Expr ( ..)
424
424
| PathSource :: Pat
425
425
| PathSource :: TupleStruct ( ..)
@@ -435,7 +435,7 @@ impl<'a> PathSource<'a> {
435
435
PathSource :: Type
436
436
| PathSource :: Expr ( ..)
437
437
| PathSource :: Pat
438
- | PathSource :: Struct
438
+ | PathSource :: Struct ( _ )
439
439
| PathSource :: TupleStruct ( ..)
440
440
| PathSource :: ReturnTypeNotation => true ,
441
441
PathSource :: Trait ( _)
@@ -450,7 +450,7 @@ impl<'a> PathSource<'a> {
450
450
PathSource :: Type => "type" ,
451
451
PathSource :: Trait ( _) => "trait" ,
452
452
PathSource :: Pat => "unit struct, unit variant or constant" ,
453
- PathSource :: Struct => "struct, variant or union type" ,
453
+ PathSource :: Struct ( _ ) => "struct, variant or union type" ,
454
454
PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
455
455
PathSource :: TraitItem ( ns) => match ns {
456
456
TypeNS => "associated type" ,
@@ -531,7 +531,7 @@ impl<'a> PathSource<'a> {
531
531
|| matches ! ( res, Res :: Def ( DefKind :: Const | DefKind :: AssocConst , _) )
532
532
}
533
533
PathSource :: TupleStruct ( ..) => res. expected_in_tuple_struct_pat ( ) ,
534
- PathSource :: Struct => matches ! (
534
+ PathSource :: Struct ( _ ) => matches ! (
535
535
res,
536
536
Res :: Def (
537
537
DefKind :: Struct
@@ -571,8 +571,8 @@ impl<'a> PathSource<'a> {
571
571
( PathSource :: Trait ( _) , false ) => E0405 ,
572
572
( PathSource :: Type , true ) => E0573 ,
573
573
( PathSource :: Type , false ) => E0412 ,
574
- ( PathSource :: Struct , true ) => E0574 ,
575
- ( PathSource :: Struct , false ) => E0422 ,
574
+ ( PathSource :: Struct ( _ ) , true ) => E0574 ,
575
+ ( PathSource :: Struct ( _ ) , false ) => E0422 ,
576
576
( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
577
577
( PathSource :: Expr ( ..) , false ) | ( PathSource :: Delegation , false ) => E0425 ,
578
578
( PathSource :: Pat | PathSource :: TupleStruct ( ..) , true ) => E0532 ,
@@ -1458,11 +1458,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1458
1458
path : & [ Segment ] ,
1459
1459
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1460
1460
finalize : Option < Finalize > ,
1461
+ source : PathSource < ' ast > ,
1461
1462
) -> PathResult < ' ra > {
1462
1463
self . r . resolve_path_with_ribs (
1463
1464
path,
1464
1465
opt_ns,
1465
1466
& self . parent_scope ,
1467
+ Some ( source) ,
1466
1468
finalize,
1467
1469
Some ( & self . ribs ) ,
1468
1470
None ,
@@ -1967,7 +1969,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1967
1969
| PathSource :: ReturnTypeNotation => false ,
1968
1970
PathSource :: Expr ( ..)
1969
1971
| PathSource :: Pat
1970
- | PathSource :: Struct
1972
+ | PathSource :: Struct ( _ )
1971
1973
| PathSource :: TupleStruct ( ..)
1972
1974
| PathSource :: Delegation => true ,
1973
1975
} ;
@@ -3805,7 +3807,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3805
3807
self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
3806
3808
}
3807
3809
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 ) ) ;
3809
3811
self . record_patterns_with_skipped_bindings ( pat, rest) ;
3810
3812
}
3811
3813
PatKind :: Or ( ref ps) => {
@@ -4214,6 +4216,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4214
4216
qself,
4215
4217
path,
4216
4218
ns,
4219
+ source,
4217
4220
path_span,
4218
4221
source. defer_to_typeck ( ) ,
4219
4222
finalize,
@@ -4259,7 +4262,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4259
4262
std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
4260
4263
std_path. extend ( path) ;
4261
4264
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 )
4263
4266
{
4264
4267
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
4265
4268
let item_span =
@@ -4330,6 +4333,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4330
4333
qself : & Option < P < QSelf > > ,
4331
4334
path : & [ Segment ] ,
4332
4335
primary_ns : Namespace ,
4336
+ source : PathSource < ' ast > ,
4333
4337
span : Span ,
4334
4338
defer_to_typeck : bool ,
4335
4339
finalize : Finalize ,
@@ -4338,7 +4342,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4338
4342
4339
4343
for ( i, & ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . enumerate ( ) {
4340
4344
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) ? {
4342
4346
Some ( partial_res)
4343
4347
if partial_res. unresolved_segments ( ) == 0 || defer_to_typeck =>
4344
4348
{
@@ -4374,6 +4378,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4374
4378
qself : & Option < P < QSelf > > ,
4375
4379
path : & [ Segment ] ,
4376
4380
ns : Namespace ,
4381
+ source : PathSource < ' ast > ,
4377
4382
finalize : Finalize ,
4378
4383
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4379
4384
debug ! (
@@ -4435,7 +4440,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4435
4440
) ) ) ;
4436
4441
}
4437
4442
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 ) {
4439
4444
PathResult :: NonModule ( path_res) => path_res,
4440
4445
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
4441
4446
PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4659,7 +4664,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4659
4664
}
4660
4665
4661
4666
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 ) ) ;
4663
4668
// This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
4664
4669
// parent in for accurate suggestions when encountering `Foo { bar }` that should
4665
4670
// have been `Foo { bar: self.bar }`.
0 commit comments