From ddddb4d10975302345d43cdc9a9d5cc9e4cf234e Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 7 May 2026 23:33:00 +0900 Subject: [PATCH] add regression test for closure return ICE --- .../closures/return-in-closure-with-fn-bound.rs | 8 ++++++++ .../return-in-closure-with-fn-bound.stderr | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/ui/closures/return-in-closure-with-fn-bound.rs create mode 100644 tests/ui/closures/return-in-closure-with-fn-bound.stderr diff --git a/tests/ui/closures/return-in-closure-with-fn-bound.rs b/tests/ui/closures/return-in-closure-with-fn-bound.rs new file mode 100644 index 000000000000..5e05cec98ca1 --- /dev/null +++ b/tests/ui/closures/return-in-closure-with-fn-bound.rs @@ -0,0 +1,8 @@ +// Regression test for https://github.com/rust-lang/rust/issues/155893. + +fn func(_f: impl Fn()) { + func(|| return 2) + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/closures/return-in-closure-with-fn-bound.stderr b/tests/ui/closures/return-in-closure-with-fn-bound.stderr new file mode 100644 index 000000000000..c51e6faca42b --- /dev/null +++ b/tests/ui/closures/return-in-closure-with-fn-bound.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/return-in-closure-with-fn-bound.rs:4:20 + | +LL | func(|| return 2) + | ^ expected `()`, found integer + | +note: return type inferred to be `()` here + --> $DIR/return-in-closure-with-fn-bound.rs:4:20 + | +LL | func(|| return 2) + | ^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`.