diff --git a/tests/ui/borrowck/nested-closure-with-generic-ice.rs b/tests/ui/borrowck/nested-closure-with-generic-ice.rs new file mode 100644 index 0000000000000..f0e308da38718 --- /dev/null +++ b/tests/ui/borrowck/nested-closure-with-generic-ice.rs @@ -0,0 +1,39 @@ +//@ check-pass +// Regression test for issue https://github.com/rust-lang/rust/issues/143821 +// Tests that we don't ICE when borrow-checking nested closures with generic type parameters +// and late-bound lifetime parameters. + +fn data_(_: &()) -> &T { + loop {} +} + +fn register(f: F) -> IfaceToken +where + T: 'static, + F: FnOnce(&()), +{ + loop {} +} + +fn method_with_cr_async(cb: CB) +where + CB: Fn(), +{ + loop {} +} + +struct IfaceToken(T); + +fn foo() -> IfaceToken { + register::(|b: &()| { + method_with_cr_async(|| { + data_::(&()); + }); + }) +} + +struct A(); + +fn main() { + foo::(); +}