Adding more tests

This commit is contained in:
Deadbeef 2022-07-13 18:13:07 +00:00
parent d1c6b797de
commit c74f155b24
7 changed files with 114 additions and 112 deletions

View File

@ -0,0 +1,74 @@
// MIR for `foo` after PreCodegen
fn foo(_1: Option<String>) -> i32 {
debug s => _1; // in scope 0 at $DIR/string.rs:+0:12: +0:13
let mut _0: i32; // return place in scope 0 at $DIR/string.rs:+0:34: +0:37
let mut _2: &std::string::String; // in scope 0 at $DIR/string.rs:+2:14: +2:17
let mut _3: &str; // in scope 0 at $DIR/string.rs:+2:14: +2:17
let mut _4: bool; // in scope 0 at $DIR/string.rs:+2:14: +2:17
let mut _5: isize; // in scope 0 at $DIR/string.rs:+2:9: +2:18
let _6: std::option::Option<std::string::String>; // in scope 0 at $DIR/string.rs:+3:9: +3:10
let mut _7: bool; // in scope 0 at $DIR/string.rs:+5:1: +5:2
scope 1 {
debug s => _6; // in scope 1 at $DIR/string.rs:+3:9: +3:10
}
bb0: {
_7 = const false; // scope 0 at $DIR/string.rs:+1:11: +1:12
_7 = const true; // scope 0 at $DIR/string.rs:+1:11: +1:12
_5 = discriminant(_1); // scope 0 at $DIR/string.rs:+1:11: +1:12
switchInt(move _5) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/string.rs:+1:5: +1:12
}
bb1: {
StorageLive(_6); // scope 0 at $DIR/string.rs:+3:9: +3:10
_7 = const false; // scope 0 at $DIR/string.rs:+3:9: +3:10
_6 = move _1; // scope 0 at $DIR/string.rs:+3:9: +3:10
_0 = const 4321_i32; // scope 1 at $DIR/string.rs:+3:14: +3:18
drop(_6) -> bb6; // scope 0 at $DIR/string.rs:+3:17: +3:18
}
bb2: {
_2 = &((_1 as Some).0: std::string::String); // scope 0 at $DIR/string.rs:+2:14: +2:17
_3 = <String as Deref>::deref(move _2) -> bb3; // scope 0 at $DIR/string.rs:+2:14: +2:17
// mir::Constant
// + span: $DIR/string.rs:9:14: 9:17
// + literal: Const { ty: for<'a> fn(&'a String) -> &'a <String as Deref>::Target {<String as Deref>::deref}, val: Value(<ZST>) }
}
bb3: {
_4 = <str as PartialEq>::eq(_3, const "a") -> bb4; // scope 0 at $DIR/string.rs:+2:14: +2:17
// mir::Constant
// + span: $DIR/string.rs:9:14: 9:17
// + literal: Const { ty: for<'a, 'b> fn(&'a str, &'b str) -> bool {<str as PartialEq>::eq}, val: Value(<ZST>) }
// mir::Constant
// + span: $DIR/string.rs:9:14: 9:17
// + literal: Const { ty: &str, val: Value(Slice(..)) }
}
bb4: {
switchInt(move _4) -> [false: bb1, otherwise: bb5]; // scope 0 at $DIR/string.rs:+2:14: +2:17
}
bb5: {
_0 = const 1234_i32; // scope 0 at $DIR/string.rs:+2:22: +2:26
goto -> bb9; // scope 0 at $DIR/string.rs:+2:22: +2:26
}
bb6: {
StorageDead(_6); // scope 0 at $DIR/string.rs:+3:17: +3:18
goto -> bb9; // scope 0 at $DIR/string.rs:+3:17: +3:18
}
bb7: {
return; // scope 0 at $DIR/string.rs:+5:2: +5:2
}
bb8: {
drop(_1) -> bb7; // scope 0 at $DIR/string.rs:+5:1: +5:2
}
bb9: {
switchInt(_7) -> [false: bb7, otherwise: bb8]; // scope 0 at $DIR/string.rs:+5:1: +5:2
}
}

View File

@ -0,0 +1,12 @@
// compile-flags: -Z mir-opt-level=0 -C panic=abort
#![feature(deref_patterns)]
#![crate_type = "lib"]
// EMIT_MIR string.foo.PreCodegen.after.mir
pub fn foo(s: Option<String>) -> i32 {
match s {
Some("a") => 1234,
s => 4321,
}
}

View File

@ -0,0 +1,9 @@
// check-pass
#![feature(deref_patterns)]
fn main() {
match <_ as Default>::default() {
"" => (),
_ => unreachable!(),
}
}

View File

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/gate.rs:3:9
--> $DIR/gate.rs:4:9
|
LL | match String::new() {
| ------------- this expression has type `String`

View File

@ -1,12 +0,0 @@
// compile-flags: -Z unpretty=mir
// build-pass
#![feature(deref_patterns)]
fn main() {
let s = Some(String::new());
let a;
match s {
Some("a") => a = 1234,
s => a = 4321,
}
}

View File

@ -1,99 +0,0 @@
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/mir.rs:5:11: 5:11
let _1: std::option::Option<std::string::String>; // in scope 0 at $DIR/mir.rs:6:9: 6:10
let mut _2: std::string::String; // in scope 0 at $DIR/mir.rs:6:18: 6:31
let mut _4: &std::string::String; // in scope 0 at $DIR/mir.rs:9:14: 9:17
let mut _5: &str; // in scope 0 at $DIR/mir.rs:9:14: 9:17
let mut _6: bool; // in scope 0 at $DIR/mir.rs:9:14: 9:17
let mut _7: isize; // in scope 0 at $DIR/mir.rs:9:9: 9:18
let mut _9: bool; // in scope 0 at $DIR/mir.rs:12:1: 12:2
scope 1 {
debug s => _1; // in scope 1 at $DIR/mir.rs:6:9: 6:10
let _3: i32; // in scope 1 at $DIR/mir.rs:7:9: 7:10
scope 2 {
debug a => _3; // in scope 2 at $DIR/mir.rs:7:9: 7:10
let _8: std::option::Option<std::string::String>; // in scope 2 at $DIR/mir.rs:10:9: 10:10
scope 3 {
debug s => _8; // in scope 3 at $DIR/mir.rs:10:9: 10:10
}
}
}
bb0: {
_9 = const false; // scope 0 at $DIR/mir.rs:6:9: 6:10
_2 = String::new() -> bb1; // scope 0 at $DIR/mir.rs:6:18: 6:31
// mir::Constant
// + span: $DIR/mir.rs:6:18: 6:29
// + literal: Const { ty: fn() -> String {String::new}, val: Value(Scalar(<ZST>)) }
}
bb1: {
_9 = const true; // scope 0 at $DIR/mir.rs:6:13: 6:32
Deinit(_1); // scope 0 at $DIR/mir.rs:6:13: 6:32
((_1 as Some).0: std::string::String) = move _2; // scope 0 at $DIR/mir.rs:6:13: 6:32
discriminant(_1) = 1; // scope 0 at $DIR/mir.rs:6:13: 6:32
_7 = discriminant(_1); // scope 2 at $DIR/mir.rs:8:11: 8:12
switchInt(move _7) -> [1_isize: bb3, otherwise: bb2]; // scope 2 at $DIR/mir.rs:8:5: 8:12
}
bb2: {
_9 = const false; // scope 2 at $DIR/mir.rs:10:9: 10:10
_8 = move _1; // scope 2 at $DIR/mir.rs:10:9: 10:10
_3 = const 4321_i32; // scope 3 at $DIR/mir.rs:10:14: 10:22
drop(_8) -> [return: bb7, unwind: bb12]; // scope 2 at $DIR/mir.rs:10:21: 10:22
}
bb3: {
_4 = &((_1 as Some).0: std::string::String); // scope 2 at $DIR/mir.rs:9:14: 9:17
_5 = <String as Deref>::deref(move _4) -> bb4; // scope 2 at $DIR/mir.rs:9:14: 9:17
// mir::Constant
// + span: $DIR/mir.rs:9:14: 9:17
// + literal: Const { ty: for<'r> fn(&'r String) -> &'r <String as Deref>::Target {<String as Deref>::deref}, val: Value(Scalar(<ZST>)) }
}
bb4: {
_6 = <str as PartialEq>::eq(_5, const "a") -> [return: bb5, unwind: bb12]; // scope 2 at $DIR/mir.rs:9:14: 9:17
// mir::Constant
// + span: $DIR/mir.rs:9:14: 9:17
// + literal: Const { ty: for<'r, 's> fn(&'r str, &'s str) -> bool {<str as PartialEq>::eq}, val: Value(Scalar(<ZST>)) }
// mir::Constant
// + span: $DIR/mir.rs:9:14: 9:17
// + literal: Const { ty: &str, val: Value(Slice(..)) }
}
bb5: {
switchInt(move _6) -> [false: bb2, otherwise: bb6]; // scope 2 at $DIR/mir.rs:9:14: 9:17
}
bb6: {
_3 = const 1234_i32; // scope 2 at $DIR/mir.rs:9:22: 9:30
goto -> bb7; // scope 2 at $DIR/mir.rs:9:22: 9:30
}
bb7: {
switchInt(_9) -> [false: bb8, otherwise: bb10]; // scope 0 at $DIR/mir.rs:12:1: 12:2
}
bb8: {
_9 = const false; // scope 0 at $DIR/mir.rs:12:1: 12:2
return; // scope 0 at $DIR/mir.rs:12:2: 12:2
}
bb9 (cleanup): {
resume; // scope 0 at $DIR/mir.rs:5:1: 12:2
}
bb10: {
drop(_1) -> bb8; // scope 0 at $DIR/mir.rs:12:1: 12:2
}
bb11 (cleanup): {
drop(_1) -> bb9; // scope 0 at $DIR/mir.rs:12:1: 12:2
}
bb12 (cleanup): {
switchInt(_9) -> [false: bb9, otherwise: bb11]; // scope 0 at $DIR/mir.rs:12:1: 12:2
}
}

View File

@ -0,0 +1,18 @@
// check-pass
#![feature(deref_patterns)]
fn foo(s: &String) -> i32 {
match *s {
"a" => 42,
_ => -1,
}
}
fn bar(s: Option<&&&&String>) -> i32 {
match s {
Some(&&&&"&&&&") => 1,
_ => -1,
}
}
fn main() {}