Skip to content

Commit dd0da10

Browse files
committed
Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obk
Implement syntax for `impl Trait` to specify its captures explicitly (`feature(precise_capturing)`) Implements `impl use<'a, 'b, T, U> Sized` syntax that allows users to explicitly list the captured parameters for an opaque, rather than inferring it from the opaque's bounds (or capturing *all* lifetimes under 2024-edition capture rules). This allows us to exclude some implicit captures, so this syntax may be used as a migration strategy for changes due to #117587. We represent this list of captured params as `PreciseCapturingArg` in AST and HIR, resolving them between `rustc_resolve` and `resolve_bound_vars`. Later on, we validate that the opaques only capture the parameters in this list. We artificially limit the feature to *require* mentioning all type and const parameters, since we don't currently have support for non-lifetime bivariant generics. This can be relaxed in the future. We also may need to limit this to require naming *all* lifetime parameters for RPITIT, since GATs have no variance. I have to investigate this. This can also be relaxed in the future. r? `@oli-obk` Tracking issue: - #123432
2 parents ac174ae + 735f2c6 commit dd0da10

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎clippy_utils/src/ast_utils.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
709709
(Tup(l),Tup(r)) => over(l, r, |l, r| eq_ty(l, r)),
710710
(Path(lq, lp),Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp),
711711
(TraitObject(lg, ls),TraitObject(rg, rs)) => ls == rs && over(lg, rg, eq_generic_bound),
712-
(ImplTrait(_, lg),ImplTrait(_, rg)) => over(lg, rg, eq_generic_bound),
712+
(ImplTrait(_, lg, lc),ImplTrait(_, rg, rc)) =>
713+
over(lg, rg, eq_generic_bound) && both(lc, rc, |lc, rc| over(lc.0.as_slice(), rc.0.as_slice(), eq_precise_capture)),
713714
(Typeof(l),Typeof(r)) => eq_expr(&l.value,&r.value),
714715
(MacCall(l),MacCall(r)) => eq_mac_call(l, r),
715716
_ => false,
@@ -770,6 +771,14 @@ pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool {
770771
}
771772
}
772773

774+
pubfneq_precise_capture(l:&PreciseCapturingArg,r:&PreciseCapturingArg) -> bool{
775+
match(l, r){
776+
(PreciseCapturingArg::Lifetime(l),PreciseCapturingArg::Lifetime(r)) => l.ident == r.ident,
777+
(PreciseCapturingArg::Arg(l, _),PreciseCapturingArg::Arg(r, _)) => l.segments[0].ident == r.segments[0].ident,
778+
_ => false,
779+
}
780+
}
781+
773782
fneq_term(l:&Term,r:&Term) -> bool{
774783
match(l, r){
775784
(Term::Ty(l),Term::Ty(r)) => eq_ty(l, r),

0 commit comments

Comments
 (0)