Skip to content

Commit 1a75a9b

Browse files
committed
Adding more tests
1 parent f06efcd commit 1a75a9b

File tree

7 files changed

+126
-112
lines changed

7 files changed

+126
-112
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// MIR for `foo` after PreCodegen
2+
3+
fn foo(_1: Option<String>) -> i32 {
4+
debug s => _1; // in scope 0 at $DIR/string.rs:+0:12: +0:13
5+
let mut _0: i32; // return place in scope 0 at $DIR/string.rs:+0:34: +0:37
6+
let mut _2: &std::string::String; // in scope 0 at $DIR/string.rs:+2:14: +2:17
7+
let mut _3: &str; // in scope 0 at $DIR/string.rs:+2:14: +2:17
8+
let mut _4: bool; // in scope 0 at $DIR/string.rs:+2:14: +2:17
9+
let mut _5: isize; // in scope 0 at $DIR/string.rs:+2:9: +2:18
10+
let _6: std::option::Option<std::string::String>; // in scope 0 at $DIR/string.rs:+3:9: +3:10
11+
let mut _7: bool; // in scope 0 at $DIR/string.rs:+5:1: +5:2
12+
scope 1 {
13+
debug s => _6; // in scope 1 at $DIR/string.rs:+3:9: +3:10
14+
}
15+
16+
bb0: {
17+
_7 = const false; // scope 0 at $DIR/string.rs:+1:11: +1:12
18+
_7 = const true; // scope 0 at $DIR/string.rs:+1:11: +1:12
19+
_5 = discriminant(_1); // scope 0 at $DIR/string.rs:+1:11: +1:12
20+
switchInt(move _5) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/string.rs:+1:5: +1:12
21+
}
22+
23+
bb1: {
24+
StorageLive(_6); // scope 0 at $DIR/string.rs:+3:9: +3:10
25+
_7 = const false; // scope 0 at $DIR/string.rs:+3:9: +3:10
26+
_6 = move _1; // scope 0 at $DIR/string.rs:+3:9: +3:10
27+
_0 = const 4321_i32; // scope 1 at $DIR/string.rs:+3:14: +3:18
28+
drop(_6) -> [return: bb6, unwind: bb12]; // scope 0 at $DIR/string.rs:+3:17: +3:18
29+
}
30+
31+
bb2: {
32+
_2 = &((_1 as Some).0: std::string::String); // scope 0 at $DIR/string.rs:+2:14: +2:17
33+
_3 = <String as Deref>::deref(move _2) -> bb3; // scope 0 at $DIR/string.rs:+2:14: +2:17
34+
// mir::Constant
35+
// + span: $DIR/string.rs:9:14: 9:17
36+
// + literal: Const { ty: for<'a> fn(&'a String) -> &'a <String as Deref>::Target {<String as Deref>::deref}, val: Value(<ZST>) }
37+
}
38+
39+
bb3: {
40+
_4 = <str as PartialEq>::eq(_3, const "a") -> [return: bb4, unwind: bb12]; // scope 0 at $DIR/string.rs:+2:14: +2:17
41+
// mir::Constant
42+
// + span: $DIR/string.rs:9:14: 9:17
43+
// + literal: Const { ty: for<'a, 'b> fn(&'a str, &'b str) -> bool {<str as PartialEq>::eq}, val: Value(<ZST>) }
44+
// mir::Constant
45+
// + span: $DIR/string.rs:9:14: 9:17
46+
// + literal: Const { ty: &str, val: Value(Slice(..)) }
47+
}
48+
49+
bb4: {
50+
switchInt(move _4) -> [false: bb1, otherwise: bb5]; // scope 0 at $DIR/string.rs:+2:14: +2:17
51+
}
52+
53+
bb5: {
54+
_0 = const 1234_i32; // scope 0 at $DIR/string.rs:+2:22: +2:26
55+
goto -> bb10; // scope 0 at $DIR/string.rs:+2:22: +2:26
56+
}
57+
58+
bb6: {
59+
StorageDead(_6); // scope 0 at $DIR/string.rs:+3:17: +3:18
60+
goto -> bb10; // scope 0 at $DIR/string.rs:+3:17: +3:18
61+
}
62+
63+
bb7: {
64+
return; // scope 0 at $DIR/string.rs:+5:2: +5:2
65+
}
66+
67+
bb8 (cleanup): {
68+
resume; // scope 0 at $DIR/string.rs:+0:1: +5:2
69+
}
70+
71+
bb9: {
72+
drop(_1) -> [return: bb7, unwind: bb8]; // scope 0 at $DIR/string.rs:+5:1: +5:2
73+
}
74+
75+
bb10: {
76+
switchInt(_7) -> [false: bb7, otherwise: bb9]; // scope 0 at $DIR/string.rs:+5:1: +5:2
77+
}
78+
79+
bb11 (cleanup): {
80+
drop(_1) -> bb8; // scope 0 at $DIR/string.rs:+5:1: +5:2
81+
}
82+
83+
bb12 (cleanup): {
84+
switchInt(_7) -> [false: bb8, otherwise: bb11]; // scope 0 at $DIR/string.rs:+5:1: +5:2
85+
}
86+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -Z mir-opt-level=0
2+
3+
#![feature(deref_patterns)]
4+
#![crate_type = "lib"]
5+
6+
// EMIT_MIR string.foo.PreCodegen.after.mir
7+
pub fn foo(s: Option<String>) -> i32 {
8+
match s {
9+
Some("a") => 1234,
10+
s => 4321,
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
#![feature(deref_patterns)]
3+
4+
fn main() {
5+
match <_ as Default>::default() {
6+
"" => (),
7+
_ => unreachable!(),
8+
}
9+
}

src/test/ui/deref-patterns/gate.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/gate.rs:3:9
2+
--> $DIR/gate.rs:4:9
33
|
44
LL | match String::new() {
55
| ------------- this expression has type `String`

src/test/ui/deref-patterns/mir.rs

-12
This file was deleted.

src/test/ui/deref-patterns/mir.stdout

-99
This file was deleted.

src/test/ui/deref-patterns/refs.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
#![feature(deref_patterns)]
3+
4+
fn foo(s: &String) -> i32 {
5+
match *s {
6+
"a" => 42,
7+
_ => -1,
8+
}
9+
}
10+
11+
fn bar(s: Option<&&&&String>) -> i32 {
12+
match s {
13+
Some(&&&&"&&&&") => 1,
14+
_ => -1,
15+
}
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)