@@ -402,6 +402,8 @@ pub(crate) enum PathSource<'a> {
402
402
TraitItem ( Namespace ) ,
403
403
// Paths in delegation item
404
404
Delegation ,
405
+ /// An arg in a `use<'a, N>` precise-capturing bound.
406
+ PreciseCapturingArg ( Namespace ) ,
405
407
}
406
408
407
409
impl < ' a > PathSource < ' a > {
@@ -413,6 +415,7 @@ impl<'a> PathSource<'a> {
413
415
| PathSource :: TupleStruct ( ..)
414
416
| PathSource :: Delegation => ValueNS ,
415
417
PathSource :: TraitItem ( ns) => ns,
418
+ PathSource :: PreciseCapturingArg ( ns) => ns,
416
419
}
417
420
}
418
421
@@ -423,7 +426,10 @@ impl<'a> PathSource<'a> {
423
426
| PathSource :: Pat
424
427
| PathSource :: Struct
425
428
| PathSource :: TupleStruct ( ..) => true ,
426
- PathSource :: Trait ( _) | PathSource :: TraitItem ( ..) | PathSource :: Delegation => false ,
429
+ PathSource :: Trait ( _)
430
+ | PathSource :: TraitItem ( ..)
431
+ | PathSource :: Delegation
432
+ | PathSource :: PreciseCapturingArg ( ..) => false ,
427
433
}
428
434
}
429
435
@@ -466,6 +472,7 @@ impl<'a> PathSource<'a> {
466
472
_ => "value" ,
467
473
} ,
468
474
PathSource :: Delegation => "function" ,
475
+ PathSource :: PreciseCapturingArg ( ..) => "type or const parameter" ,
469
476
}
470
477
}
471
478
@@ -534,15 +541,25 @@ impl<'a> PathSource<'a> {
534
541
_ => false ,
535
542
} ,
536
543
PathSource :: Delegation => matches ! ( res, Res :: Def ( DefKind :: Fn | DefKind :: AssocFn , _) ) ,
544
+ PathSource :: PreciseCapturingArg ( ValueNS ) => {
545
+ matches ! ( res, Res :: Def ( DefKind :: ConstParam , _) )
546
+ }
547
+ // We allow `SelfTyAlias` here so we can give a more descriptive error later.
548
+ PathSource :: PreciseCapturingArg ( TypeNS ) => matches ! (
549
+ res,
550
+ Res :: Def ( DefKind :: TyParam , _) | Res :: SelfTyParam { .. } | Res :: SelfTyAlias { .. }
551
+ ) ,
552
+ PathSource :: PreciseCapturingArg ( MacroNS ) => false ,
537
553
}
538
554
}
539
555
540
556
fn error_code ( self , has_unexpected_resolution : bool ) -> ErrCode {
541
557
match ( self , has_unexpected_resolution) {
542
558
( PathSource :: Trait ( _) , true ) => E0404 ,
543
559
( PathSource :: Trait ( _) , false ) => E0405 ,
544
- ( PathSource :: Type , true ) => E0573 ,
545
- ( PathSource :: Type , false ) => E0412 ,
560
+ // TODO:
561
+ ( PathSource :: Type | PathSource :: PreciseCapturingArg ( ..) , true ) => E0573 ,
562
+ ( PathSource :: Type | PathSource :: PreciseCapturingArg ( ..) , false ) => E0412 ,
546
563
( PathSource :: Struct , true ) => E0574 ,
547
564
( PathSource :: Struct , false ) => E0422 ,
548
565
( PathSource :: Expr ( ..) , true ) | ( PathSource :: Delegation , true ) => E0423 ,
@@ -1077,9 +1094,19 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
1077
1094
} ;
1078
1095
// Like `Ty::Param`, we try resolving this as both a const and a type.
1079
1096
if !check_ns ( TypeNS ) && check_ns ( ValueNS ) {
1080
- self . smart_resolve_path ( * id, & None , path, PathSource :: Expr ( None ) ) ;
1097
+ self . smart_resolve_path (
1098
+ * id,
1099
+ & None ,
1100
+ path,
1101
+ PathSource :: PreciseCapturingArg ( ValueNS ) ,
1102
+ ) ;
1081
1103
} else {
1082
- self . smart_resolve_path ( * id, & None , path, PathSource :: Type ) ;
1104
+ self . smart_resolve_path (
1105
+ * id,
1106
+ & None ,
1107
+ path,
1108
+ PathSource :: PreciseCapturingArg ( TypeNS ) ,
1109
+ ) ;
1083
1110
}
1084
1111
}
1085
1112
}
@@ -1889,7 +1916,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1889
1916
) ;
1890
1917
1891
1918
let inferred = match source {
1892
- PathSource :: Trait ( ..) | PathSource :: TraitItem ( ..) | PathSource :: Type => false ,
1919
+ PathSource :: Trait ( ..)
1920
+ | PathSource :: TraitItem ( ..)
1921
+ | PathSource :: Type
1922
+ | PathSource :: PreciseCapturingArg ( ..) => false ,
1893
1923
PathSource :: Expr ( ..)
1894
1924
| PathSource :: Pat
1895
1925
| PathSource :: Struct
@@ -3982,7 +4012,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3982
4012
Applicability :: MaybeIncorrect ,
3983
4013
) )
3984
4014
} else if res. is_none ( )
3985
- && let PathSource :: Type | PathSource :: Expr ( _) = source
4015
+ && let PathSource :: Type
4016
+ | PathSource :: Expr ( _)
4017
+ | PathSource :: PreciseCapturingArg ( ..) = source
3986
4018
{
3987
4019
this. suggest_adding_generic_parameter ( path, source)
3988
4020
} else {
0 commit comments