Skip to content

Commit 962cae0

Browse files
authored
Rollup merge of rust-lang#71576 - lcnr:inline-as_mut, r=oli-obk
check that `AsRef` and `AsMut` are inlined Adds a regression test for rust-lang#58867 r? @Dylan-DPC
2 parents b2a8a8a + cf61a56 commit 962cae0

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// EMIT_MIR rustc.a.Inline.after.mir
2+
pub fn a<T>(x: &mut [T]) -> &mut [T] {
3+
x.as_mut()
4+
}
5+
6+
// EMIT_MIR rustc.b.Inline.after.mir
7+
pub fn b<T>(x: &mut Box<T>) -> &mut T {
8+
x.as_mut()
9+
}
10+
11+
// EMIT_MIR rustc.c.Inline.after.mir
12+
pub fn c<T>(x: &[T]) -> &[T] {
13+
x.as_ref()
14+
}
15+
16+
// EMIT_MIR rustc.d.Inline.after.mir
17+
pub fn d<T>(x: &Box<T>) -> &T {
18+
x.as_ref()
19+
}
20+
21+
fn main() {
22+
let mut boxed = Box::new(1);
23+
println!("{:?}", a(&mut [1]));
24+
println!("{:?}", b(&mut boxed));
25+
println!("{:?}", c(&[1]));
26+
println!("{:?}", d(&boxed));
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// MIR for `a` after Inline
2+
3+
fn a(_1: &mut [T]) -> &mut [T] {
4+
debug x => _1; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:2:13: 2:14
5+
let mut _0: &mut [T]; // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:2:29: 2:37
6+
let mut _2: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
7+
let mut _3: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
8+
let mut _4: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
9+
scope 1 {
10+
debug self => _4; // in scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
11+
let mut _5: &mut [T]; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
12+
}
13+
14+
bb0: {
15+
StorageLive(_2); // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
16+
StorageLive(_3); // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
17+
StorageLive(_4); // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
18+
_4 = &mut (*_1); // bb0[3]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
19+
StorageLive(_5); // bb0[4]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
20+
_5 = _4; // bb0[5]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
21+
_3 = _5; // bb0[6]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
22+
StorageDead(_5); // bb0[7]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
23+
_2 = &mut (*_3); // bb0[8]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
24+
StorageDead(_4); // bb0[9]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:14: 3:15
25+
_0 = &mut (*_2); // bb0[10]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
26+
StorageDead(_3); // bb0[11]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:1: 4:2
27+
StorageDead(_2); // bb0[12]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:1: 4:2
28+
return; // bb0[13]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:2: 4:2
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// MIR for `b` after Inline
2+
3+
fn b(_1: &mut std::boxed::Box<T>) -> &mut T {
4+
debug x => _1; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:7:13: 7:14
5+
let mut _0: &mut T; // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:7:32: 7:38
6+
let mut _2: &mut T; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
7+
let mut _3: &mut T; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
8+
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
9+
scope 1 {
10+
debug self => _4; // in scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
11+
let mut _5: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
12+
let mut _6: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
13+
}
14+
15+
bb0: {
16+
StorageLive(_2); // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
17+
StorageLive(_3); // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
18+
StorageLive(_4); // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6
19+
_4 = &mut (*_1); // bb0[3]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6
20+
StorageLive(_5); // bb0[4]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
21+
StorageLive(_6); // bb0[5]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
22+
_6 = &mut (*(*_4)); // bb0[6]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
23+
_5 = _6; // bb0[7]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
24+
_3 = _5; // bb0[8]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
25+
StorageDead(_6); // bb0[9]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
26+
StorageDead(_5); // bb0[10]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
27+
_2 = &mut (*_3); // bb0[11]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
28+
StorageDead(_4); // bb0[12]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:14: 8:15
29+
_0 = &mut (*_2); // bb0[13]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
30+
StorageDead(_3); // bb0[14]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:1: 9:2
31+
StorageDead(_2); // bb0[15]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:1: 9:2
32+
return; // bb0[16]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:2: 9:2
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// MIR for `c` after Inline
2+
3+
fn c(_1: &[T]) -> &[T] {
4+
debug x => _1; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:12:13: 12:14
5+
let mut _0: &[T]; // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:12:25: 12:29
6+
let _2: &[T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15
7+
let mut _3: &[T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:6
8+
scope 1 {
9+
debug self => _3; // in scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
10+
}
11+
12+
bb0: {
13+
StorageLive(_2); // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15
14+
StorageLive(_3); // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:6
15+
_3 = &(*_1); // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:6
16+
_2 = _3; // bb0[3]: scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
17+
_0 = &(*_2); // bb0[4]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15
18+
StorageDead(_3); // bb0[5]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:14: 13:15
19+
StorageDead(_2); // bb0[6]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:14:1: 14:2
20+
return; // bb0[7]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:14:2: 14:2
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// MIR for `d` after Inline
2+
3+
fn d(_1: &std::boxed::Box<T>) -> &T {
4+
debug x => _1; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:17:13: 17:14
5+
let mut _0: &T; // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:17:28: 17:30
6+
let _2: &T; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
7+
let mut _3: &std::boxed::Box<T>; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:6
8+
scope 1 {
9+
debug self => _3; // in scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
10+
let _4: &T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
11+
}
12+
13+
bb0: {
14+
StorageLive(_2); // bb0[0]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
15+
StorageLive(_3); // bb0[1]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:6
16+
_3 = &(*_1); // bb0[2]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:6
17+
StorageLive(_4); // bb0[3]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
18+
_4 = &(*(*_3)); // bb0[4]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
19+
_2 = _4; // bb0[5]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
20+
StorageDead(_4); // bb0[6]: scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
21+
_0 = &(*_2); // bb0[7]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15
22+
StorageDead(_3); // bb0[8]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:14: 18:15
23+
StorageDead(_2); // bb0[9]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:19:1: 19:2
24+
return; // bb0[10]: scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:19:2: 19:2
25+
}
26+
}

0 commit comments

Comments
 (0)