about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-10-24 17:14:39 -0400
committerNiko Matsakis <niko@alum.mit.edu>2017-10-31 12:41:38 -0400
commitaf09f720d60c1226b5d42aaee3cc0c0e67ebe5cc (patch)
tree18ddf05c453ecff95afca75a105daf853b50846a /src/test
parente02937848b9316d393577171ede62a3423132583 (diff)
downloadrust-af09f720d60c1226b5d42aaee3cc0c0e67ebe5cc.tar.gz
rust-af09f720d60c1226b5d42aaee3cc0c0e67ebe5cc.zip
preliminary support for may-dangle attribute and drop constraints
Diffstat (limited to 'src/test')
-rw-r--r--src/test/mir-opt/nll/region-liveness-drop-no-may-dangle.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/mir-opt/nll/region-liveness-drop-no-may-dangle.rs b/src/test/mir-opt/nll/region-liveness-drop-no-may-dangle.rs
new file mode 100644
index 00000000000..5f4da966281
--- /dev/null
+++ b/src/test/mir-opt/nll/region-liveness-drop-no-may-dangle.rs
@@ -0,0 +1,50 @@
+// Copyright 2012-2016 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Basic test for liveness constraints: the region (`R1`) that appears
+// in the type of `p` includes the points after `&v[0]` up to (but not
+// including) the call to `use_x`. The `else` branch is not included.
+
+// ignore-tidy-linelength
+// compile-flags:-Znll -Zverbose
+//                     ^^^^^^^^^ force compiler to dump more region information
+
+#![allow(warnings)]
+
+fn use_x(_: usize) -> bool { true }
+
+fn main() {
+    let mut v = [1, 2, 3];
+    let p: Wrap<& /* R1 */ usize> = Wrap { value: &v[0] };
+    if true {
+        use_x(*p.value);
+    } else {
+        use_x(22);
+    }
+
+    // `p` will get dropped here. Because the `#[may_dangle]`
+    // attribute is not present on `Wrap`, we must conservatively
+    // assume that the dtor may access the `value` field, and hence we
+    // must consider R1 to be live.
+}
+
+struct Wrap<T> {
+    value: T
+}
+
+// Look ma, no `#[may_dangle]` attribute here.
+impl<T> Drop for Wrap<T> {
+    fn drop(&mut self) { }
+}
+
+// END RUST SOURCE
+// START rustc.node12.nll.0.mir
+// | R4: {bb1[3], bb1[4], bb1[5], bb2[0], bb2[1], bb2[2], bb3[0], bb4[0], bb4[1], bb4[2], bb6[0], bb7[0], bb7[1], bb8[0]}
+// END rustc.node12.nll.0.mir