Question: Unexpected move closure behavior in 2021/2024 editions - bug or feature?
⚓ Rust 📅 2025-10-02 👤 surdeus 👁️ 8Description
The ownership check for move closures is broken in Rust 2021 and 2024 editions, but works correctly in 2015 and 2018 editions.
Reproduction
#[derive(Debug)]
struct Point { x: i32, y: i32 }
fn main() {
let mut a = Point { x: 1, y: 2 };
let mut add = move |x, y| {
a.x += x;
a.y += y;
};
add(10, 10);
println!("{:?}", a); // Should error but doesn't in 2021/2024
}
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c43dd055665addee1ca6e30c4251b9b0a
commit-date: 2025-09-14
host: x86_64-pc-windows-msvc
release: 1.90.0
Expected behavior (as in 2015/2018 editions)
Compilation error E0382: borrow of moved value a
Actual behavior in 2021/2024 editions
Code compiles without error
Output: Point { x: 1, y: 2 } (closure has no effect)
Test results
✅ rustc --edition=2015 main.rs: Correct error
✅ rustc --edition=2018 main.rs: Correct error
❌ rustc --edition=2021 main.rs: Incorrectly compiles
❌ rustc --edition=2024 main.rs: Incorrectly compiles
4 posts - 3 participants
🏷️ Rust_feed