From e9b28d22fb1fe343ddb03c456516973abe15afcd Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 7 Aug 2015 15:51:25 +0200 Subject: [PATCH 1/3] Turn nonzeroing move hints back off by default. This is a temporary workaround for the bugs that have been found in the implementation of PR #26173. * pnkfelix is unavailable in the short-term (i.e. for the next week) to fix them. * When the bugs are fixed, we will turn this back on by default. (If you want to play with the known-to-be-buggy optimization in the meantime, you can opt-back in via the debugging option that this commit is toggling.) --- src/librustc/session/config.rs | 4 ++-- src/librustc/session/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f74bb9ee89ad0..c5db7cd718b8e 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -596,8 +596,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "Force drop flag checks on or off"), trace_macros: bool = (false, parse_bool, "For every macro invocation, print its name and arguments"), - disable_nonzeroing_move_hints: bool = (false, parse_bool, - "Force nonzeroing move optimization off"), + enable_nonzeroing_move_hints: bool = (false, parse_bool, + "Force nonzeroing move optimization on"), } pub fn default_lib_output() -> CrateType { diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index efd46d35f56b7..99a58f07ae62b 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -273,7 +273,7 @@ impl Session { self.opts.debugging_opts.print_enum_sizes } pub fn nonzeroing_move_hints(&self) -> bool { - !self.opts.debugging_opts.disable_nonzeroing_move_hints + self.opts.debugging_opts.enable_nonzeroing_move_hints } pub fn sysroot<'a>(&'a self) -> &'a Path { match self.opts.maybe_sysroot { From 61704350553060a782a6ca2fbf6f9f0a04d4a1b6 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 7 Aug 2015 16:21:22 +0200 Subject: [PATCH 2/3] Regression test for dropflag reinit issue. Fix #27401. --- .../run-pass/issue-27401-dropflag-reinit.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/run-pass/issue-27401-dropflag-reinit.rs diff --git a/src/test/run-pass/issue-27401-dropflag-reinit.rs b/src/test/run-pass/issue-27401-dropflag-reinit.rs new file mode 100644 index 0000000000000..99d5e5cd536df --- /dev/null +++ b/src/test/run-pass/issue-27401-dropflag-reinit.rs @@ -0,0 +1,34 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that when a `let`-binding occurs in a loop, its associated +// drop-flag is reinitialized (to indicate "needs-drop" at the end of +// the owning variable's scope). + +struct A<'a>(&'a mut i32); + +impl<'a> Drop for A<'a> { + fn drop(&mut self) { + *self.0 += 1; + } +} + +fn main() { + let mut cnt = 0; + for i in 0..2 { + let a = A(&mut cnt); + if i == 1 { // Note that + break; // both this break + } // and also + drop(a); // this move of `a` + // are necessary to expose the bug + } + assert_eq!(cnt, 2); +} From 1a68b187630f19236c8c48e813775f29e1f52114 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 7 Aug 2015 18:23:37 +0200 Subject: [PATCH 3/3] placate the pretty tests by ignoring my test. --- src/test/run-pass/issue-27401-dropflag-reinit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/run-pass/issue-27401-dropflag-reinit.rs b/src/test/run-pass/issue-27401-dropflag-reinit.rs index 99d5e5cd536df..ab8f22e78be72 100644 --- a/src/test/run-pass/issue-27401-dropflag-reinit.rs +++ b/src/test/run-pass/issue-27401-dropflag-reinit.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-pretty #27582 + // Check that when a `let`-binding occurs in a loop, its associated // drop-flag is reinitialized (to indicate "needs-drop" at the end of // the owning variable's scope).