From b88cb3dc114a04800c5361a8a6a826cd0c554b5b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 7 Apr 2020 14:59:07 +0300 Subject: [PATCH 01/10] bootstrap: work around "unused attribute" errors in incremental stdlib rebuilds. --- src/bootstrap/builder.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index b14352d7f4ba0..7fc089d18f113 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1099,6 +1099,13 @@ impl<'a> Builder<'a> { if self.config.deny_warnings { rustflags.arg("-Dwarnings"); + + // FIXME(#58633) hide "unused attribute" errors in incremental + // builds of the standard library, as the underlying checks are + // not yet properly integrated with incremental recompilation. + if mode == Mode::Std && compiler.stage == 0 && self.config.incremental { + rustflags.arg("-Aunused-attributes"); + } } } From 8a03147f224369f96c2a826bc2dcbde3a6be1f10 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 9 Apr 2020 16:48:36 +0200 Subject: [PATCH 02/10] Normalize MIR locals' types for generator layout computation. --- src/librustc_mir/transform/generator.rs | 5 ++++- src/test/ui/repeat_count_const_in_async_fn.rs | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/repeat_count_const_in_async_fn.rs diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 53eec1f6dc3de..ca596f63393d7 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -720,15 +720,18 @@ fn compute_layout<'tcx>( _ => bug!(), }; + let param_env = tcx.param_env(source.def_id()); + for (local, decl) in body.local_decls.iter_enumerated() { // Ignore locals which are internal or not live if !live_locals.contains(local) || decl.internal { continue; } + let decl_ty = tcx.normalize_erasing_regions(param_env, decl.ty); // Sanity check that typeck knows about the type of locals which are // live across a suspension point - if !allowed.contains(&decl.ty) && !allowed_upvars.contains(&decl.ty) { + if !allowed.contains(&decl_ty) && !allowed_upvars.contains(&decl_ty) { span_bug!( body.span, "Broken MIR: generator contains type {} in MIR, \ diff --git a/src/test/ui/repeat_count_const_in_async_fn.rs b/src/test/ui/repeat_count_const_in_async_fn.rs new file mode 100644 index 0000000000000..ebabc3fbf10f9 --- /dev/null +++ b/src/test/ui/repeat_count_const_in_async_fn.rs @@ -0,0 +1,10 @@ +// check-pass +// edition:2018 +// compile-flags: --crate-type=lib + +pub async fn test() { + const C: usize = 4; + foo(&mut [0u8; C]).await; +} + +async fn foo(_: &mut [u8]) {} From 68b38c3bd902deccd31d59f45d5b49e58aa76a9d Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Fri, 10 Apr 2020 18:14:55 +0800 Subject: [PATCH 03/10] Normalize function signature in function casting check --- src/librustc_typeck/check/cast.rs | 5 ++++- src/test/ui/issues/issue-54094.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issues/issue-54094.rs diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 5de0184f2bba9..38d0c42e1588b 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -536,7 +536,10 @@ impl<'a, 'tcx> CastCheck<'tcx> { match self.expr_ty.kind { ty::FnDef(..) => { // Attempt a coercion to a fn pointer type. - let f = self.expr_ty.fn_sig(fcx.tcx); + let f = fcx.normalize_associated_types_in( + self.expr.span, + &self.expr_ty.fn_sig(fcx.tcx), + ); let res = fcx.try_coerce( self.expr, self.expr_ty, diff --git a/src/test/ui/issues/issue-54094.rs b/src/test/ui/issues/issue-54094.rs new file mode 100644 index 0000000000000..57384825a35fe --- /dev/null +++ b/src/test/ui/issues/issue-54094.rs @@ -0,0 +1,14 @@ +// check-pass +trait Zoo { + type X; +} + +impl Zoo for u16 { + type X = usize; +} + +fn foo(abc: ::X) {} + +fn main() { + let x: *const u8 = foo as _; +} \ No newline at end of file From 75cc40335c5ca83ffa636ea6ff249d1934223b8b Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Fri, 10 Apr 2020 18:51:27 +0800 Subject: [PATCH 04/10] Tidy fix --- src/test/ui/issues/issue-54094.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/issues/issue-54094.rs b/src/test/ui/issues/issue-54094.rs index 57384825a35fe..ec38dc40e610a 100644 --- a/src/test/ui/issues/issue-54094.rs +++ b/src/test/ui/issues/issue-54094.rs @@ -11,4 +11,4 @@ fn foo(abc: ::X) {} fn main() { let x: *const u8 = foo as _; -} \ No newline at end of file +} From 6e70849304f3f9d15edfdc1aaeb9d2ef9937ad79 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 28 Feb 2020 22:56:37 -0500 Subject: [PATCH 05/10] tests encoding current behavior for various cases of "binding" to _. The `_` binding form is special, in that it encodes a "no-op": nothing is actually bound, and thus nothing is moved or borrowed in this scenario. Usually we do the "right" thing in all such cases. The exceptions are explicitly pointed out in this test case, so that we keep track of whether they are eventually fixed. --- .../ui/binding/issue-53114-borrow-checks.rs | 58 ++++++++++ .../binding/issue-53114-borrow-checks.stderr | 34 ++++++ .../ui/binding/issue-53114-safety-checks.rs | 51 +++++++++ .../binding/issue-53114-safety-checks.stderr | 100 ++++++++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 src/test/ui/binding/issue-53114-borrow-checks.rs create mode 100644 src/test/ui/binding/issue-53114-borrow-checks.stderr create mode 100644 src/test/ui/binding/issue-53114-safety-checks.rs create mode 100644 src/test/ui/binding/issue-53114-safety-checks.stderr diff --git a/src/test/ui/binding/issue-53114-borrow-checks.rs b/src/test/ui/binding/issue-53114-borrow-checks.rs new file mode 100644 index 0000000000000..6aee2699474df --- /dev/null +++ b/src/test/ui/binding/issue-53114-borrow-checks.rs @@ -0,0 +1,58 @@ +// Issue #53114: NLL's borrow check had some deviations from the old borrow +// checker, and both had some deviations from our ideal state. This test +// captures the behavior of how `_` bindings are handled wiith respect to how we +// flag expressions that are meant to request unsafe blocks. + +struct M; + +fn let_wild_gets_moved_expr() { + let m = M; + drop(m); + let _ = m; // accepted, and want it to continue to be + + let mm = (M, M); // variation on above with `_` in substructure + let (_x, _) = mm; + let (_, _y) = mm; + let (_, _) = mm; +} + +fn match_moved_expr_to_wild() { + let m = M; + drop(m); + match m { _ => { } } // #53114: should eventually be accepted too + //~^ ERROR [E0382] + + let mm = (M, M); // variation on above with `_` in substructure + match mm { (_x, _) => { } } + match mm { (_, _y) => { } } + //~^ ERROR [E0382] + match mm { (_, _) => { } } + //~^ ERROR [E0382] +} + +fn let_wild_gets_borrowed_expr() { + let mut m = M; + let r = &mut m; + let _ = m; // accepted, and want it to continue to be + // let _x = m; // (compare with this error.) + drop(r); + + let mut mm = (M, M); // variation on above with `_` in substructure + let (r1, r2) = (&mut mm.0, &mut mm.1); + let (_, _) = mm; + drop((r1, r2)); +} + +fn match_borrowed_expr_to_wild() { + let mut m = M; + let r = &mut m; + match m { _ => {} } ; // accepted, and want it to continue to be + drop(r); + + let mut mm = (M, M); // variation on above with `_` in substructure + let (r1, r2) = (&mut mm.0, &mut mm.1); + match mm { (_, _) => { } } + drop((r1, r2)); +} + +fn main() { } diff --git a/src/test/ui/binding/issue-53114-borrow-checks.stderr b/src/test/ui/binding/issue-53114-borrow-checks.stderr new file mode 100644 index 0000000000000..18114dc09cf52 --- /dev/null +++ b/src/test/ui/binding/issue-53114-borrow-checks.stderr @@ -0,0 +1,34 @@ +error[E0382]: use of moved value: `m` + --> $DIR/issue-53114-borrow-checks.rs:22:11 + | +LL | let m = M; + | - move occurs because `m` has type `M`, which does not implement the `Copy` trait +LL | drop(m); + | - value moved here +LL | match m { _ => { } } // #53114: should eventually be accepted too + | ^ value used here after move + +error[E0382]: use of moved value: `mm` + --> $DIR/issue-53114-borrow-checks.rs:27:11 + | +LL | match mm { (_x, _) => { } } + | -- value moved here +LL | match mm { (_, _y) => { } } + | ^^ value used here after partial move + | + = note: move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait + +error[E0382]: use of moved value: `mm` + --> $DIR/issue-53114-borrow-checks.rs:29:11 + | +LL | match mm { (_, _y) => { } } + | -- value moved here +LL | +LL | match mm { (_, _) => { } } + | ^^ value used here after partial move + | + = note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/binding/issue-53114-safety-checks.rs b/src/test/ui/binding/issue-53114-safety-checks.rs new file mode 100644 index 0000000000000..86c863bc9a843 --- /dev/null +++ b/src/test/ui/binding/issue-53114-safety-checks.rs @@ -0,0 +1,51 @@ +// Issue #53114: NLL's borrow check had some deviations from the old borrow +// checker, and both had some deviations from our ideal state. This test +// captures the behavior of how `_` bindings are handled wiith respect to how we +// flag expressions that are meant to request unsafe blocks. + +#![feature(untagged_unions)] + +struct I(i64); +struct F(f64); + +union U { a: I, b: F } + +#[repr(packed)] +struct P { + a: &'static i8, + b: &'static u32, +} + +fn let_wild_gets_unsafe_field() { + let u1 = U { a: I(0) }; + let u2 = U { a: I(1) }; + let p = P { a: &2, b: &3 }; + let _ = &p.b; //~ WARN E0133 + //~^ WARN will become a hard error + let _ = u1.a; // #53114: should eventually signal error as well + let _ = &u2.a; //~ ERROR [E0133] + + // variation on above with `_` in substructure + let (_,) = (&p.b,); //~ WARN E0133 + //~^ WARN will become a hard error + let (_,) = (u1.a,); //~ ERROR [E0133] + let (_,) = (&u2.a,); //~ ERROR [E0133] +} + +fn match_unsafe_field_to_wild() { + let u1 = U { a: I(0) }; + let u2 = U { a: I(1) }; + let p = P { a: &2, b: &3 }; + match &p.b { _ => { } } //~ WARN E0133 + //~^ WARN will become a hard error + match u1.a { _ => { } } //~ ERROR [E0133] + match &u2.a { _ => { } } //~ ERROR [E0133] + + // variation on above with `_` in substructure + match (&p.b,) { (_,) => { } } //~ WARN E0133 + //~^ WARN will become a hard error + match (u1.a,) { (_,) => { } } //~ ERROR [E0133] + match (&u2.a,) { (_,) => { } } //~ ERROR [E0133] +} + +fn main() { } diff --git a/src/test/ui/binding/issue-53114-safety-checks.stderr b/src/test/ui/binding/issue-53114-safety-checks.stderr new file mode 100644 index 0000000000000..fc714a78bf648 --- /dev/null +++ b/src/test/ui/binding/issue-53114-safety-checks.stderr @@ -0,0 +1,100 @@ +warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133) + --> $DIR/issue-53114-safety-checks.rs:23:13 + | +LL | let _ = &p.b; + | ^^^^ + | + = note: `#[warn(safe_packed_borrows)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #46043 + = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior + +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-53114-safety-checks.rs:26:13 + | +LL | let _ = &u2.a; + | ^^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133) + --> $DIR/issue-53114-safety-checks.rs:29:17 + | +LL | let (_,) = (&p.b,); + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #46043 + = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior + +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-53114-safety-checks.rs:31:17 + | +LL | let (_,) = (u1.a,); + | ^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-53114-safety-checks.rs:32:17 + | +LL | let (_,) = (&u2.a,); + | ^^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133) + --> $DIR/issue-53114-safety-checks.rs:39:11 + | +LL | match &p.b { _ => { } } + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #46043 + = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior + +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-53114-safety-checks.rs:41:11 + | +LL | match u1.a { _ => { } } + | ^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-53114-safety-checks.rs:42:11 + | +LL | match &u2.a { _ => { } } + | ^^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133) + --> $DIR/issue-53114-safety-checks.rs:45:12 + | +LL | match (&p.b,) { (_,) => { } } + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #46043 + = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior + +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-53114-safety-checks.rs:47:12 + | +LL | match (u1.a,) { (_,) => { } } + | ^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-53114-safety-checks.rs:48:12 + | +LL | match (&u2.a,) { (_,) => { } } + | ^^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0133`. From ee7a035d8c9ebb2c537abe8f03f4f3c2f6c0078c Mon Sep 17 00:00:00 2001 From: Felix S Klock II Date: Thu, 5 Mar 2020 13:51:48 -0500 Subject: [PATCH 06/10] Update src/test/ui/binding/issue-53114-borrow-checks.rs Co-Authored-By: Mazdak Farrokhzad --- src/test/ui/binding/issue-53114-borrow-checks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/binding/issue-53114-borrow-checks.rs b/src/test/ui/binding/issue-53114-borrow-checks.rs index 6aee2699474df..2eb11ed84d490 100644 --- a/src/test/ui/binding/issue-53114-borrow-checks.rs +++ b/src/test/ui/binding/issue-53114-borrow-checks.rs @@ -1,6 +1,6 @@ // Issue #53114: NLL's borrow check had some deviations from the old borrow // checker, and both had some deviations from our ideal state. This test -// captures the behavior of how `_` bindings are handled wiith respect to how we +// captures the behavior of how `_` bindings are handled with respect to how we // flag expressions that are meant to request unsafe blocks. struct M; From 192d5330c40ea8ac4e3f3462c47c7cbe9b293ec9 Mon Sep 17 00:00:00 2001 From: Felix S Klock II Date: Thu, 5 Mar 2020 13:52:10 -0500 Subject: [PATCH 07/10] Update src/test/ui/binding/issue-53114-safety-checks.rs Co-Authored-By: Mazdak Farrokhzad --- src/test/ui/binding/issue-53114-safety-checks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/binding/issue-53114-safety-checks.rs b/src/test/ui/binding/issue-53114-safety-checks.rs index 86c863bc9a843..28adb7571a98b 100644 --- a/src/test/ui/binding/issue-53114-safety-checks.rs +++ b/src/test/ui/binding/issue-53114-safety-checks.rs @@ -1,6 +1,6 @@ // Issue #53114: NLL's borrow check had some deviations from the old borrow // checker, and both had some deviations from our ideal state. This test -// captures the behavior of how `_` bindings are handled wiith respect to how we +// captures the behavior of how `_` bindings are handled with respect to how we // flag expressions that are meant to request unsafe blocks. #![feature(untagged_unions)] From 1ff99b724ccafc5d0077827f6913f825be042949 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 5 Mar 2020 14:06:40 -0500 Subject: [PATCH 08/10] copy test cases to `if let` as well. --- .../ui/binding/issue-53114-borrow-checks.rs | 28 +++++++++++++++- .../binding/issue-53114-borrow-checks.stderr | 33 ++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/test/ui/binding/issue-53114-borrow-checks.rs b/src/test/ui/binding/issue-53114-borrow-checks.rs index 2eb11ed84d490..7646472f45fac 100644 --- a/src/test/ui/binding/issue-53114-borrow-checks.rs +++ b/src/test/ui/binding/issue-53114-borrow-checks.rs @@ -2,7 +2,7 @@ // checker, and both had some deviations from our ideal state. This test // captures the behavior of how `_` bindings are handled with respect to how we // flag expressions that are meant to request unsafe blocks. - +#![allow(irrefutable_let_patterns)] struct M; fn let_wild_gets_moved_expr() { @@ -30,6 +30,20 @@ fn match_moved_expr_to_wild() { //~^ ERROR [E0382] } +fn if_let_moved_expr_to_wild() { + let m = M; + drop(m); + if let _ = m { } // #53114: should eventually be accepted too + //~^ ERROR [E0382] + + let mm = (M, M); // variation on above with `_` in substructure + if let (_x, _) = mm { } + if let (_, _y) = mm { } + //~^ ERROR [E0382] + if let (_, _) = mm { } + //~^ ERROR [E0382] +} + fn let_wild_gets_borrowed_expr() { let mut m = M; let r = &mut m; @@ -55,4 +69,16 @@ fn match_borrowed_expr_to_wild() { drop((r1, r2)); } +fn if_let_borrowed_expr_to_wild() { + let mut m = M; + let r = &mut m; + if let _ = m { } // accepted, and want it to continue to be + drop(r); + + let mut mm = (M, M); // variation on above with `_` in substructure + let (r1, r2) = (&mut mm.0, &mut mm.1); + if let (_, _) = mm { } + drop((r1, r2)); +} + fn main() { } diff --git a/src/test/ui/binding/issue-53114-borrow-checks.stderr b/src/test/ui/binding/issue-53114-borrow-checks.stderr index 18114dc09cf52..f535a66cf63ba 100644 --- a/src/test/ui/binding/issue-53114-borrow-checks.stderr +++ b/src/test/ui/binding/issue-53114-borrow-checks.stderr @@ -29,6 +29,37 @@ LL | match mm { (_, _) => { } } | = note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait -error: aborting due to 3 previous errors +error[E0382]: use of moved value: `m` + --> $DIR/issue-53114-borrow-checks.rs:36:16 + | +34 | let m = M; + | - move occurs because `m` has type `M`, which does not implement the `Copy` trait +35 | drop(m); + | - value moved here +36 | if let _ = m { } // #53114: should eventually be accepted too + | ^ value used here after move + +error[E0382]: use of moved value: `mm` + --> $DIR/issue-53114-borrow-checks.rs:41:22 + | +40 | if let (_x, _) = mm { } + | -- value moved here +41 | if let (_, _y) = mm { } + | ^^ value used here after partial move + | + = note: move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait + +error[E0382]: use of moved value: `mm` + --> $DIR/issue-53114-borrow-checks.rs:43:21 + | +41 | if let (_, _y) = mm { } + | -- value moved here +42 | +43 | if let (_, _) = mm { } + | ^^ value used here after partial move + | + = note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0382`. From 22ea3a4476e3b2ecef218524f132b57ea14c64de Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Fri, 10 Apr 2020 18:22:24 +0200 Subject: [PATCH 09/10] --bless you --- .../ui/binding/issue-53114-borrow-checks.stderr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/ui/binding/issue-53114-borrow-checks.stderr b/src/test/ui/binding/issue-53114-borrow-checks.stderr index f535a66cf63ba..2a7a721324d69 100644 --- a/src/test/ui/binding/issue-53114-borrow-checks.stderr +++ b/src/test/ui/binding/issue-53114-borrow-checks.stderr @@ -32,19 +32,19 @@ LL | match mm { (_, _) => { } } error[E0382]: use of moved value: `m` --> $DIR/issue-53114-borrow-checks.rs:36:16 | -34 | let m = M; +LL | let m = M; | - move occurs because `m` has type `M`, which does not implement the `Copy` trait -35 | drop(m); +LL | drop(m); | - value moved here -36 | if let _ = m { } // #53114: should eventually be accepted too +LL | if let _ = m { } // #53114: should eventually be accepted too | ^ value used here after move error[E0382]: use of moved value: `mm` --> $DIR/issue-53114-borrow-checks.rs:41:22 | -40 | if let (_x, _) = mm { } +LL | if let (_x, _) = mm { } | -- value moved here -41 | if let (_, _y) = mm { } +LL | if let (_, _y) = mm { } | ^^ value used here after partial move | = note: move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait @@ -52,10 +52,10 @@ error[E0382]: use of moved value: `mm` error[E0382]: use of moved value: `mm` --> $DIR/issue-53114-borrow-checks.rs:43:21 | -41 | if let (_, _y) = mm { } +LL | if let (_, _y) = mm { } | -- value moved here -42 | -43 | if let (_, _) = mm { } +LL | +LL | if let (_, _) = mm { } | ^^ value used here after partial move | = note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait From 7de9511d25e31fbb8a42d82738016ec1645b898b Mon Sep 17 00:00:00 2001 From: Ozaren Date: Thu, 9 Apr 2020 14:48:06 -0400 Subject: [PATCH 10/10] added machine hooks to track deallocations --- src/librustc_mir/interpret/machine.rs | 8 ++++++++ src/librustc_mir/interpret/memory.rs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 23e39f433f53b..fd67b088c93cf 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -254,6 +254,14 @@ pub trait Machine<'mir, 'tcx>: Sized { kind: Option>, ) -> (Cow<'b, Allocation>, Self::PointerTag); + /// Called to notify the machine before a deallocation occurs. + fn before_deallocation( + _memory_extra: &mut Self::MemoryExtra, + _id: AllocId, + ) -> InterpResult<'tcx> { + Ok(()) + } + /// Return the "base" tag for the given *global* allocation: the one that is used for direct /// accesses to this static/const/fn allocation. If `id` is not a global allocation, /// this will return an unusable tag (i.e., accesses will be UB)! diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index c16c59715e40c..539537e9de80c 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -254,6 +254,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { ); } + M::before_deallocation(&mut self.extra, ptr.alloc_id)?; + let (alloc_kind, mut alloc) = match self.alloc_map.remove(&ptr.alloc_id) { Some(alloc) => alloc, None => {