diff --git a/tests/ui/higher-ranked/hrtb-projection-closure-62201.rs b/tests/ui/higher-ranked/hrtb-projection-closure-62201.rs new file mode 100644 index 0000000000000..15e68ebe2eacc --- /dev/null +++ b/tests/ui/higher-ranked/hrtb-projection-closure-62201.rs @@ -0,0 +1,42 @@ +//! Regression test for . +//! +//! A closure whose parameter type is a higher-ranked associated-type projection +//! (`for<'r> Fn(>::V)`) used to be wrongly rejected. It should compile. + +//@ check-pass + +#![allow(unused, unreachable_code)] + +trait Ty<'a> { + type V; +} + +trait SIter: for<'a> Ty<'a> { + fn f(&self, f: F) + where + F: for<'r> Fn(>::V); +} + +struct S(I); + +impl<'a, I: Ty<'a>> Ty<'a> for S { + type V = >::V; +} + +impl SIter for S +where + for<'r> S: Ty<'r, V = Item>, + for<'r> I: Ty<'r, V = Item>, +{ + fn f(&self, f: F) + where + F: Fn(::V), + { + self.0.f(|item| { + let item: ::V = loop {}; + f(item) + }) + } +} + +fn main() {}