@@ -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" ,
@@ -535,7 +535,7 @@ impl<'a> PathSource<'a> {
535
535
|| matches ! ( res, Res :: Def ( DefKind :: Const | DefKind :: AssocConst , _) )
536
536
}
537
537
PathSource :: TupleStruct ( ..) => res. expected_in_tuple_struct_pat ( ) ,
538
- PathSource :: Struct => matches ! (
538
+ PathSource :: Struct ( _ ) => matches ! (
539
539
res,
540
540
Res :: Def (
541
541
DefKind :: Struct
@@ -575,8 +575,8 @@ impl<'a> PathSource<'a> {
575
575
( PathSource :: Trait ( _) , false ) => E0405 ,
576
576
( PathSource :: Type , true ) => E0573 ,
577
577
( PathSource :: Type , false ) => E0412 ,
578
- ( PathSource :: Struct , true ) => E0574 ,
579
- ( PathSource :: Struct , false ) => E0422 ,
578
+ ( PathSource :: Struct ( _ ) , true ) => E0574 ,
579
+ ( PathSource :: Struct ( _ ) , false ) => E0422 ,
580
580
( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
581
581
( PathSource :: Expr ( ..) , false ) | ( PathSource :: Delegation , false ) => E0425 ,
582
582
( PathSource :: Pat | PathSource :: TupleStruct ( ..) , true ) => E0532 ,
@@ -1461,11 +1461,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1461
1461
path : & [ Segment ] ,
1462
1462
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1463
1463
finalize : Option < Finalize > ,
1464
+ source : PathSource < ' ast > ,
1464
1465
) -> PathResult < ' ra > {
1465
1466
self . r . resolve_path_with_ribs (
1466
1467
path,
1467
1468
opt_ns,
1468
1469
& self . parent_scope ,
1470
+ Some ( source) ,
1469
1471
finalize,
1470
1472
Some ( & self . ribs ) ,
1471
1473
None ,
@@ -1975,7 +1977,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1975
1977
| PathSource :: ReturnTypeNotation => false ,
1976
1978
PathSource :: Expr ( ..)
1977
1979
| PathSource :: Pat
1978
- | PathSource :: Struct
1980
+ | PathSource :: Struct ( _ )
1979
1981
| PathSource :: TupleStruct ( ..)
1980
1982
| PathSource :: Delegation => true ,
1981
1983
} ;
@@ -3816,7 +3818,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3816
3818
self . smart_resolve_path ( pat. id , qself, path, PathSource :: Pat ) ;
3817
3819
}
3818
3820
PatKind :: Struct ( ref qself, ref path, ref _fields, ref rest) => {
3819
- self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ) ;
3821
+ self . smart_resolve_path ( pat. id , qself, path, PathSource :: Struct ( None ) ) ;
3820
3822
self . record_patterns_with_skipped_bindings ( pat, rest) ;
3821
3823
}
3822
3824
PatKind :: Or ( ref ps) => {
@@ -4222,6 +4224,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4222
4224
qself,
4223
4225
path,
4224
4226
ns,
4227
+ source,
4225
4228
path_span,
4226
4229
source. defer_to_typeck ( ) ,
4227
4230
finalize,
@@ -4267,7 +4270,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4267
4270
std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
4268
4271
std_path. extend ( path) ;
4269
4272
if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
4270
- self . resolve_path ( & std_path, Some ( ns) , None )
4273
+ self . resolve_path ( & std_path, Some ( ns) , None , source )
4271
4274
{
4272
4275
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
4273
4276
let item_span =
@@ -4338,6 +4341,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4338
4341
qself : & Option < P < QSelf > > ,
4339
4342
path : & [ Segment ] ,
4340
4343
primary_ns : Namespace ,
4344
+ source : PathSource < ' ast > ,
4341
4345
span : Span ,
4342
4346
defer_to_typeck : bool ,
4343
4347
finalize : Finalize ,
@@ -4346,7 +4350,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4346
4350
4347
4351
for ( i, & ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . enumerate ( ) {
4348
4352
if i == 0 || ns != primary_ns {
4349
- match self . resolve_qpath ( qself, path, ns, finalize) ? {
4353
+ match self . resolve_qpath ( qself, path, ns, source , finalize) ? {
4350
4354
Some ( partial_res)
4351
4355
if partial_res. unresolved_segments ( ) == 0 || defer_to_typeck =>
4352
4356
{
@@ -4382,6 +4386,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4382
4386
qself : & Option < P < QSelf > > ,
4383
4387
path : & [ Segment ] ,
4384
4388
ns : Namespace ,
4389
+ source : PathSource < ' ast > ,
4385
4390
finalize : Finalize ,
4386
4391
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4387
4392
debug ! (
@@ -4443,7 +4448,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4443
4448
) ) ) ;
4444
4449
}
4445
4450
4446
- let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) ) {
4451
+ let result = match self . resolve_path ( path, Some ( ns) , Some ( finalize) , source ) {
4447
4452
PathResult :: NonModule ( path_res) => path_res,
4448
4453
PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) if !module. is_normal ( ) => {
4449
4454
PartialRes :: new ( module. res ( ) . unwrap ( ) )
@@ -4664,7 +4669,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4664
4669
}
4665
4670
4666
4671
ExprKind :: Struct ( ref se) => {
4667
- self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ) ;
4672
+ self . smart_resolve_path ( expr. id , & se. qself , & se. path , PathSource :: Struct ( parent ) ) ;
4668
4673
// This is the same as `visit::walk_expr(self, expr);`, but we want to pass the
4669
4674
// parent in for accurate suggestions when encountering `Foo { bar }` that should
4670
4675
// have been `Foo { bar: self.bar }`.
0 commit comments