@@ -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,6 +541,15 @@ 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
@@ -551,6 +567,8 @@ impl<'a> PathSource<'a> {
551
567
( PathSource :: Pat | PathSource :: TupleStruct ( ..) , false ) => E0531 ,
552
568
( PathSource :: TraitItem ( ..) , true ) => E0575 ,
553
569
( PathSource :: TraitItem ( ..) , false ) => E0576 ,
570
+ ( PathSource :: PreciseCapturingArg ( ..) , true ) => E0799 ,
571
+ ( PathSource :: PreciseCapturingArg ( ..) , false ) => E0800 ,
554
572
}
555
573
}
556
574
}
@@ -1077,9 +1095,19 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
1077
1095
} ;
1078
1096
// Like `Ty::Param`, we try resolving this as both a const and a type.
1079
1097
if !check_ns ( TypeNS ) && check_ns ( ValueNS ) {
1080
- self . smart_resolve_path ( * id, & None , path, PathSource :: Expr ( None ) ) ;
1098
+ self . smart_resolve_path (
1099
+ * id,
1100
+ & None ,
1101
+ path,
1102
+ PathSource :: PreciseCapturingArg ( ValueNS ) ,
1103
+ ) ;
1081
1104
} else {
1082
- self . smart_resolve_path ( * id, & None , path, PathSource :: Type ) ;
1105
+ self . smart_resolve_path (
1106
+ * id,
1107
+ & None ,
1108
+ path,
1109
+ PathSource :: PreciseCapturingArg ( TypeNS ) ,
1110
+ ) ;
1083
1111
}
1084
1112
}
1085
1113
}
@@ -1889,7 +1917,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1889
1917
) ;
1890
1918
1891
1919
let inferred = match source {
1892
- PathSource :: Trait ( ..) | PathSource :: TraitItem ( ..) | PathSource :: Type => false ,
1920
+ PathSource :: Trait ( ..)
1921
+ | PathSource :: TraitItem ( ..)
1922
+ | PathSource :: Type
1923
+ | PathSource :: PreciseCapturingArg ( ..) => false ,
1893
1924
PathSource :: Expr ( ..)
1894
1925
| PathSource :: Pat
1895
1926
| PathSource :: Struct
@@ -3982,7 +4013,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3982
4013
Applicability :: MaybeIncorrect ,
3983
4014
) )
3984
4015
} else if res. is_none ( )
3985
- && let PathSource :: Type | PathSource :: Expr ( _) = source
4016
+ && let PathSource :: Type
4017
+ | PathSource :: Expr ( _)
4018
+ | PathSource :: PreciseCapturingArg ( ..) = source
3986
4019
{
3987
4020
this. suggest_adding_generic_parameter ( path, source)
3988
4021
} else {
0 commit comments