Files
rust/tests/ui/closures/basic-closure-syntax.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
773 B
Rust
Raw Normal View History

2025-06-29 23:13:37 +05:00
//! Test basic closure syntax and usage with generic functions.
//!
//! This test checks that closure syntax works correctly for:
//! - Closures with parameters and return values
//! - Closures without parameters (both expression and block forms)
//! - Integration with generic functions and FnOnce trait bounds
2025-06-29 23:13:37 +05:00
//@ run-pass
2025-06-29 23:13:37 +05:00
fn f<F>(i: isize, f: F) -> isize
where
F: FnOnce(isize) -> isize,
{
f(i)
}
2025-06-29 23:13:37 +05:00
fn g<G>(_g: G)
where
G: FnOnce(),
{
}
pub fn main() {
2025-06-29 23:13:37 +05:00
// Closure with parameter that returns the same value
assert_eq!(f(10, |a| a), 10);
2025-06-29 23:13:37 +05:00
// Closure without parameters - expression form
g(|| ());
// Test closure reuse in generic context
assert_eq!(f(10, |a| a), 10);
2025-06-29 23:13:37 +05:00
// Closure without parameters - block form
g(|| {});
}