Files
rust/tests/ui/closures/closure-clone-requires-captured-clone.rs

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

20 lines
613 B
Rust
Raw Normal View History

2025-06-30 00:05:58 +05:00
//! Test that closures only implement `Clone` if all captured values implement `Clone`.
//!
//! When a closure captures variables from its environment, it can only be cloned
//! if all those captured variables are cloneable. This test makes sure the compiler
//! properly rejects attempts to clone closures that capture non-Clone types.
2017-09-13 22:40:48 +02:00
2025-06-30 00:05:58 +05:00
//@ compile-flags: --diagnostic-width=300
struct NonClone(i32);
2017-09-13 22:40:48 +02:00
fn main() {
2025-06-30 00:05:58 +05:00
let captured_value = NonClone(5);
let closure = move || {
let _ = captured_value.0;
2017-09-13 22:40:48 +02:00
};
2025-06-30 00:05:58 +05:00
closure.clone();
//~^ ERROR the trait bound `NonClone: Clone` is not satisfied
2017-09-13 22:40:48 +02:00
}