about summary refs log tree commit diff
path: root/src/test/run-pass
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2018-01-29 23:15:38 -0500
committerAaron Hill <aa1ronham@gmail.com>2018-01-29 23:25:54 -0500
commitb5f8cd5c20977119eb600b05edf699a1bde92a2c (patch)
tree601168b12623431d7a5b9f8258c8e459acb27774 /src/test/run-pass
parent90eb44a5897c39e3dff9c7e48e3973671dcd9496 (diff)
downloadrust-b5f8cd5c20977119eb600b05edf699a1bde92a2c.tar.gz
rust-b5f8cd5c20977119eb600b05edf699a1bde92a2c.zip
Fix ref-to-ptr coercions not working with NLL in certain cases
Implicit coercions from references to pointers were lowered to slightly
different Mir than explicit casts (e.g. 'foo as *mut T'). This resulted
in certain uses of self-referential structs compiling correctly when an
explicit cast was used, but not when the implicit coercion was used.

To fix this, this commit adds an outer 'Use' expr when applying a
raw-ptr-borrow adjustment. This makes the lowered Mir for coercions
identical to that of explicit coercions, allowing the original code to
compile regardless of how the raw ptr cast occurs.

Fixes #47722
Diffstat (limited to 'src/test/run-pass')
-rw-r--r--src/test/run-pass/issue-47722.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/run-pass/issue-47722.rs b/src/test/run-pass/issue-47722.rs
new file mode 100644
index 00000000000..3b5d808e1f5
--- /dev/null
+++ b/src/test/run-pass/issue-47722.rs
@@ -0,0 +1,26 @@
+// Copyright 2018 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.
+//
+// Tests that automatic coercions from &mut T to *mut T
+// allow borrows of T to expire immediately - essentially, that
+// they work identically to 'foo as *mut T'
+#![feature(nll)]
+
+struct SelfReference {
+    self_reference: *mut SelfReference,
+}
+
+impl SelfReference {
+    fn set_self_ref(&mut self) {
+        self.self_reference = self;
+    }
+}
+
+fn main() {}