@@ -402,6 +402,8 @@ pub(crate) enum PathSource<'a> {
402402 TraitItem ( Namespace ) ,
403403 // Paths in delegation item
404404 Delegation ,
405+ /// An arg in a `use<'a, N>` precise-capturing bound.
406+ PreciseCapturingArg ( Namespace ) ,
405407}
406408
407409impl < ' a > PathSource < ' a > {
@@ -413,6 +415,7 @@ impl<'a> PathSource<'a> {
413415 | PathSource :: TupleStruct ( ..)
414416 | PathSource :: Delegation => ValueNS ,
415417 PathSource :: TraitItem ( ns) => ns,
418+ PathSource :: PreciseCapturingArg ( ns) => ns,
416419 }
417420 }
418421
@@ -423,7 +426,10 @@ impl<'a> PathSource<'a> {
423426 | PathSource :: Pat
424427 | PathSource :: Struct
425428 | PathSource :: TupleStruct ( ..) => true ,
426- PathSource :: Trait ( _) | PathSource :: TraitItem ( ..) | PathSource :: Delegation => false ,
429+ PathSource :: Trait ( _)
430+ | PathSource :: TraitItem ( ..)
431+ | PathSource :: Delegation
432+ | PathSource :: PreciseCapturingArg ( ..) => false ,
427433 }
428434 }
429435
@@ -466,6 +472,7 @@ impl<'a> PathSource<'a> {
466472 _ => "value" ,
467473 } ,
468474 PathSource :: Delegation => "function" ,
475+ PathSource :: PreciseCapturingArg ( ..) => "type or const parameter" ,
469476 }
470477 }
471478
@@ -534,6 +541,15 @@ impl<'a> PathSource<'a> {
534541 _ => false ,
535542 } ,
536543 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 ,
537553 }
538554 }
539555
@@ -551,6 +567,8 @@ impl<'a> PathSource<'a> {
551567 ( PathSource :: Pat | PathSource :: TupleStruct ( ..) , false ) => E0531 ,
552568 ( PathSource :: TraitItem ( ..) , true ) => E0575 ,
553569 ( PathSource :: TraitItem ( ..) , false ) => E0576 ,
570+ ( PathSource :: PreciseCapturingArg ( ..) , true ) => E0799 ,
571+ ( PathSource :: PreciseCapturingArg ( ..) , false ) => E0800 ,
554572 }
555573 }
556574}
@@ -1077,9 +1095,19 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
10771095 } ;
10781096 // Like `Ty::Param`, we try resolving this as both a const and a type.
10791097 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+ ) ;
10811104 } 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+ ) ;
10831111 }
10841112 }
10851113 }
@@ -1889,7 +1917,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
18891917 ) ;
18901918
18911919 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 ,
18931924 PathSource :: Expr ( ..)
18941925 | PathSource :: Pat
18951926 | PathSource :: Struct
@@ -3982,7 +4013,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
39824013 Applicability :: MaybeIncorrect ,
39834014 ) )
39844015 } else if res. is_none ( )
3985- && let PathSource :: Type | PathSource :: Expr ( _) = source
4016+ && let PathSource :: Type
4017+ | PathSource :: Expr ( _)
4018+ | PathSource :: PreciseCapturingArg ( ..) = source
39864019 {
39874020 this. suggest_adding_generic_parameter ( path, source)
39884021 } else {
0 commit comments