From e0b7b2350e0fd22e65175ba4f600162b69805280 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 12 Oct 2025 08:23:44 +0900 Subject: [PATCH] Add a regression test for #72207 --- .../associated-type-fn-bound-issue-72207.rs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/ui/impl-trait/associated-type-fn-bound-issue-72207.rs diff --git a/tests/ui/impl-trait/associated-type-fn-bound-issue-72207.rs b/tests/ui/impl-trait/associated-type-fn-bound-issue-72207.rs new file mode 100644 index 0000000000000..67e4ed9f4c87a --- /dev/null +++ b/tests/ui/impl-trait/associated-type-fn-bound-issue-72207.rs @@ -0,0 +1,57 @@ +//@ check-pass +//@ compile-flags: --crate-type=lib + +#![allow(dead_code)] + +use std::marker::PhantomData; + +pub struct XImpl +where + F2: Fn(E), +{ + f1: F1, + f2: F2, + _ghost: PhantomData<(T, E)>, +} + +pub trait X: Sized { + type F1; + type F2: Fn(Self::E); + type E; + + fn and(self, f: NewF1Generator) -> XImpl + where + NewF1Generator: FnOnce(Self::F1) -> NewF1; +} + +impl X for XImpl +where + F2: Fn(E), +{ + type E = E; + type F2 = F2; + type F1 = F1; + + fn and(self, f: NewF1Generator) -> XImpl + where + NewF1Generator: FnOnce(F1) -> NewF1, + { + XImpl { + f1: f(self.f1), + f2: self.f2, + _ghost: PhantomData, + } + } +} + +fn f() -> impl X<(), E = ()> { + XImpl { + f1: || (), + f2: |()| (), + _ghost: PhantomData, + } +} + +fn f2() -> impl X<(), E = ()> { + f().and(|rb| rb) +}