Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f3f0b5a

Browse files
committedMar 13, 2025
Test interaction between RFC 2229 migration and use closures
1 parent cdd8af2 commit f3f0b5a

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//@ run-rustfix
2+
//@ edition:2018
3+
//@ check-pass
4+
#![feature(ergonomic_clones)]
5+
#![warn(rust_2021_compatibility)]
6+
#![allow(incomplete_features)]
7+
8+
#[derive(Debug)]
9+
struct Foo(i32);
10+
impl Drop for Foo {
11+
fn drop(&mut self) {
12+
println!("{:?} dropped", self.0);
13+
}
14+
}
15+
16+
macro_rules! m {
17+
(@ $body:expr) => {{
18+
let f = use || $body;
19+
//~^ WARNING: drop order
20+
f();
21+
}};
22+
($body:block) => {{
23+
m!(@ $body);
24+
}};
25+
}
26+
27+
fn main() {
28+
let a = (Foo(0), Foo(1));
29+
m!({
30+
let _ = &a;
31+
//~^ HELP: add a dummy
32+
let x = a.0;
33+
println!("{:?}", x);
34+
});
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ run-rustfix
2+
//@ edition:2018
3+
//@ check-pass
4+
#![feature(ergonomic_clones)]
5+
#![warn(rust_2021_compatibility)]
6+
#![allow(incomplete_features)]
7+
8+
#[derive(Debug)]
9+
struct Foo(i32);
10+
impl Drop for Foo {
11+
fn drop(&mut self) {
12+
println!("{:?} dropped", self.0);
13+
}
14+
}
15+
16+
macro_rules! m {
17+
(@ $body:expr) => {{
18+
let f = use || $body;
19+
//~^ WARNING: drop order
20+
f();
21+
}};
22+
($body:block) => {{
23+
m!(@ $body);
24+
}};
25+
}
26+
27+
fn main() {
28+
let a = (Foo(0), Foo(1));
29+
m!({
30+
//~^ HELP: add a dummy
31+
let x = a.0;
32+
println!("{:?}", x);
33+
});
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
warning: changes to closure capture in Rust 2021 will affect drop order
2+
--> $DIR/rfc2229-migration.rs:18:17
3+
|
4+
LL | let f = use || $body;
5+
| ^^^^^^
6+
...
7+
LL | }};
8+
| - in Rust 2018, `a` is dropped here, but in Rust 2021, only `a.0` will be dropped here as part of the closure
9+
...
10+
LL | / m!({
11+
LL | |
12+
LL | | let x = a.0;
13+
| | --- in Rust 2018, this closure captures all of `a`, but in Rust 2021, it will only capture `a.0`
14+
LL | | println!("{:?}", x);
15+
LL | | });
16+
| |______- in this macro invocation
17+
|
18+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
19+
note: the lint level is defined here
20+
--> $DIR/rfc2229-migration.rs:5:9
21+
|
22+
LL | #![warn(rust_2021_compatibility)]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^
24+
= note: `#[warn(rust_2021_incompatible_closure_captures)]` implied by `#[warn(rust_2021_compatibility)]`
25+
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
26+
help: add a dummy let to cause `a` to be fully captured
27+
|
28+
LL ~ m!({
29+
LL + let _ = &a;
30+
|
31+
32+
warning: 1 warning emitted
33+

0 commit comments

Comments
 (0)
Failed to load comments.