3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
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
+ fn main() {
17
+ let a = (Foo(0), Foo(1));
18
+ let f = || {
19
+ let _ = &a;
20
+ //~^ HELP: add a dummy
21
+ //~| WARNING: drop order
22
+ let x = a.0;
23
+ println!("{:?}", x);
24
+ };
25
+ f();
26
+ }
Original file line number Diff line number Diff line change
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
+ fn main ( ) {
17
+ let a = ( Foo ( 0 ) , Foo ( 1 ) ) ;
18
+ let f = || {
19
+ //~^ HELP: add a dummy
20
+ //~| WARNING: drop order
21
+ let x = a. 0 ;
22
+ println ! ( "{:?}" , x) ;
23
+ } ;
24
+ f ( ) ;
25
+ }
Original file line number Diff line number Diff line change
1
+ warning: changes to closure capture in Rust 2021 will affect drop order
2
+ --> $DIR/rfc2229-migration.rs:18:13
3
+ |
4
+ LL | let f = || {
5
+ | ^^
6
+ ...
7
+ LL | let x = a.0;
8
+ | --- in Rust 2018, this closure captures all of `a`, but in Rust 2021, it will only capture `a.0`
9
+ ...
10
+ LL | }
11
+ | - in Rust 2018, `a` is dropped here, but in Rust 2021, only `a.0` will be dropped here as part of the closure
12
+ |
13
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
14
+ note: the lint level is defined here
15
+ --> $DIR/rfc2229-migration.rs:5:9
16
+ |
17
+ LL | #![warn(rust_2021_compatibility)]
18
+ | ^^^^^^^^^^^^^^^^^^^^^^^
19
+ = note: `#[warn(rust_2021_incompatible_closure_captures)]` implied by `#[warn(rust_2021_compatibility)]`
20
+ help: add a dummy let to cause `a` to be fully captured
21
+ |
22
+ LL ~ let f = || {
23
+ LL + let _ = &a;
24
+ |
25
+
26
+ warning: 1 warning emitted
27
+
0 commit comments