about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-04-26 21:02:40 +0200
committerGitHub <noreply@github.com>2020-04-26 21:02:40 +0200
commit962cae070f085f7c67813aba6b75547e172ec669 (patch)
treee6008f7c09e14c44b05015e5ede8c9e8c52c6683
parentb2a8a8a0f882728809a99841787cd8f745768f5f (diff)
parentcf61a562896e3abded4891719884c6acc18b5039 (diff)
downloadrust-962cae070f085f7c67813aba6b75547e172ec669.tar.gz
rust-962cae070f085f7c67813aba6b75547e172ec669.zip
Rollup merge of #71576 - lcnr:inline-as_mut, r=oli-obk
check that `AsRef` and `AsMut` are inlined

Adds a regression test for #58867

r? @Dylan-DPC
-rw-r--r--src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut.rs27
-rw-r--r--src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir30
-rw-r--r--src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir34
-rw-r--r--src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.c.Inline.after.mir22
-rw-r--r--src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.d.Inline.after.mir26
5 files changed, 139 insertions, 0 deletions
diff --git a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut.rs b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut.rs
new file mode 100644
index 00000000000..317705f7612
--- /dev/null
+++ b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut.rs
@@ -0,0 +1,27 @@
+// EMIT_MIR rustc.a.Inline.after.mir
+pub fn a<T>(x: &mut [T]) -> &mut [T] {
+    x.as_mut()
+}
+
+// EMIT_MIR rustc.b.Inline.after.mir
+pub fn b<T>(x: &mut Box<T>) -> &mut T {
+    x.as_mut()
+}
+
+// EMIT_MIR rustc.c.Inline.after.mir
+pub fn c<T>(x: &[T]) -> &[T] {
+    x.as_ref()
+}
+
+// EMIT_MIR rustc.d.Inline.after.mir
+pub fn d<T>(x: &Box<T>) -> &T {
+    x.as_ref()
+}
+
+fn main() {
+    let mut boxed = Box::new(1);
+    println!("{:?}", a(&mut [1]));
+    println!("{:?}", b(&mut boxed));
+    println!("{:?}", c(&[1]));
+    println!("{:?}", d(&boxed));
+}
diff --git a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir
new file mode 100644
index 00000000000..c5d44cbafac
--- /dev/null
+++ b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir
@@ -0,0 +1,30 @@
+// MIR for `a` after Inline
+
+fn a(_1: &mut [T]) -> &mut [T] {
+    debug x => _1;                       // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:2:13: 2:14
+    let mut _0: &mut [T];                // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:2:29: 2:37
+    let mut _2: &mut [T];                // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
+    let mut _3: &mut [T];                // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
+    let mut _4: &mut [T];                // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
+    scope 1 {
+        debug self => _4;                // in scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
+        let mut _5: &mut [T];            // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
+    }
+
+    bb0: {
+        StorageLive(_2);                 // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
+        StorageLive(_3);                 // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
+        StorageLive(_4);                 // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
+        _4 = &mut (*_1);                 // bb0[3]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
+        StorageLive(_5);                 // bb0[4]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
+        _5 = _4;                         // bb0[5]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
+        _3 = _5;                         // bb0[6]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
+        StorageDead(_5);                 // bb0[7]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
+        _2 = &mut (*_3);                 // bb0[8]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
+        StorageDead(_4);                 // bb0[9]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:14: 3:15
+        _0 = &mut (*_2);                 // bb0[10]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
+        StorageDead(_3);                 // bb0[11]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:1: 4:2
+        StorageDead(_2);                 // bb0[12]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:1: 4:2
+        return;                          // bb0[13]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:2: 4:2
+    }
+}
diff --git a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir
new file mode 100644
index 00000000000..8384b949b95
--- /dev/null
+++ b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir
@@ -0,0 +1,34 @@
+// MIR for `b` after Inline
+
+fn b(_1: &mut std::boxed::Box<T>) -> &mut T {
+    debug x => _1;                       // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:7:13: 7:14
+    let mut _0: &mut T;                  // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:7:32: 7:38
+    let mut _2: &mut T;                  // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+    let mut _3: &mut T;                  // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+    let mut _4: &mut std::boxed::Box<T>; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6
+    scope 1 {
+        debug self => _4;                // in scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        let mut _5: &mut T;              // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+        let mut _6: &mut T;              // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+    }
+
+    bb0: {
+        StorageLive(_2);                 // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+        StorageLive(_3);                 // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+        StorageLive(_4);                 // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6
+        _4 = &mut (*_1);                 // bb0[3]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6
+        StorageLive(_5);                 // bb0[4]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        StorageLive(_6);                 // bb0[5]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        _6 = &mut (*(*_4));              // bb0[6]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        _5 = _6;                         // bb0[7]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        _3 = _5;                         // bb0[8]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        StorageDead(_6);                 // bb0[9]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        StorageDead(_5);                 // bb0[10]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        _2 = &mut (*_3);                 // bb0[11]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+        StorageDead(_4);                 // bb0[12]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:14: 8:15
+        _0 = &mut (*_2);                 // bb0[13]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
+        StorageDead(_3);                 // bb0[14]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:1: 9:2
+        StorageDead(_2);                 // bb0[15]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:1: 9:2
+        return;                          // bb0[16]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:2: 9:2
+    }
+}
diff --git a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.c.Inline.after.mir b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.c.Inline.after.mir
new file mode 100644
index 00000000000..5adb4a68312
--- /dev/null
+++ b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.c.Inline.after.mir
@@ -0,0 +1,22 @@
+// MIR for `c` after Inline
+
+fn c(_1: &[T]) -> &[T] {
+    debug x => _1;                       // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:12:13: 12:14
+    let mut _0: &[T];                    // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:12:25: 12:29
+    let _2: &[T];                        // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15
+    let mut _3: &[T];                    // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:6
+    scope 1 {
+        debug self => _3;                // in scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
+    }
+
+    bb0: {
+        StorageLive(_2);                 // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15
+        StorageLive(_3);                 // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:6
+        _3 = &(*_1);                     // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:6
+        _2 = _3;                         // bb0[3]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
+        _0 = &(*_2);                     // bb0[4]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15
+        StorageDead(_3);                 // bb0[5]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:14: 13:15
+        StorageDead(_2);                 // bb0[6]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:14:1: 14:2
+        return;                          // bb0[7]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:14:2: 14:2
+    }
+}
diff --git a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.d.Inline.after.mir b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.d.Inline.after.mir
new file mode 100644
index 00000000000..d4d62dd788e
--- /dev/null
+++ b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.d.Inline.after.mir
@@ -0,0 +1,26 @@
+// MIR for `d` after Inline
+
+fn d(_1: &std::boxed::Box<T>) -> &T {
+    debug x => _1;                       // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:17:13: 17:14
+    let mut _0: &T;                      // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:17:28: 17:30
+    let _2: &T;                          // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
+    let mut _3: &std::boxed::Box<T>;     // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:6
+    scope 1 {
+        debug self => _3;                // in scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        let _4: &T;                      // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
+    }
+
+    bb0: {
+        StorageLive(_2);                 // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
+        StorageLive(_3);                 // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:6
+        _3 = &(*_1);                     // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:6
+        StorageLive(_4);                 // bb0[3]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        _4 = &(*(*_3));                  // bb0[4]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        _2 = _4;                         // bb0[5]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        StorageDead(_4);                 // bb0[6]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
+        _0 = &(*_2);                     // bb0[7]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
+        StorageDead(_3);                 // bb0[8]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:14: 18:15
+        StorageDead(_2);                 // bb0[9]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:19:1: 19:2
+        return;                          // bb0[10]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:19:2: 19:2
+    }
+}