forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#78133 - JohnTitor:mir-tests, r=lcnr
Add some MIR-related regression tests Closes rust-lang#68841 Closes rust-lang#75053 Closes rust-lang#76375 Closes rust-lang#77911 I think they're fixed by rust-lang#77306.
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// edition:2018 | ||
// compile-flags: -Z mir-opt-level=2 -Z unsound-mir-opts | ||
|
||
#[inline(always)] | ||
pub fn f(s: bool) -> String { | ||
let a = "Hello world!".to_string(); | ||
let b = a; | ||
let c = b; | ||
if s { | ||
c | ||
} else { | ||
String::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// compile-flags: -Z mir-opt-level=2 | ||
// edition:2018 | ||
// build-pass | ||
|
||
#![feature(async_closure)] | ||
|
||
use std::future::Future; | ||
|
||
fn async_closure() -> impl Future<Output = u8> { | ||
(async move || -> u8 { 42 })() | ||
} | ||
|
||
fn main() { | ||
let _fut = async_closure(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// compile-flags: -Z mir-opt-level=2 | ||
// build-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
use std::marker::PhantomData; | ||
|
||
trait MyIndex<T> { | ||
type O; | ||
fn my_index(self) -> Self::O; | ||
} | ||
trait MyFrom<T>: Sized { | ||
type Error; | ||
fn my_from(value: T) -> Result<Self, Self::Error>; | ||
} | ||
|
||
trait F {} | ||
impl F for () {} | ||
type DummyT<T> = impl F; | ||
fn _dummy_t<T>() -> DummyT<T> {} | ||
|
||
struct Phantom1<T>(PhantomData<T>); | ||
struct Phantom2<T>(PhantomData<T>); | ||
struct Scope<T>(Phantom2<DummyT<T>>); | ||
|
||
impl<T> Scope<T> { | ||
fn new() -> Self { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
impl<T> MyFrom<Phantom2<T>> for Phantom1<T> { | ||
type Error = (); | ||
fn my_from(_: Phantom2<T>) -> Result<Self, Self::Error> { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<Phantom1<T>> for Scope<U> { | ||
type O = T; | ||
fn my_index(self) -> Self::O { | ||
MyFrom::my_from(self.0).ok().unwrap() | ||
} | ||
} | ||
|
||
fn main() { | ||
let _pos: Phantom1<DummyT<()>> = Scope::new().my_index(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// edition:2018 | ||
// build-pass | ||
// compile-flags: -Z mir-opt-level=2 -L. | ||
// aux-build:issue_76375_aux.rs | ||
|
||
#![crate_type = "lib"] | ||
|
||
extern crate issue_76375_aux; | ||
|
||
pub async fn g() { | ||
issue_76375_aux::f(true); | ||
h().await; | ||
} | ||
|
||
pub async fn h() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// compile-flags: -Z mir-opt-level=2 | ||
// ignore-cloudabi no std::fs | ||
// build-pass | ||
|
||
use std::fs::File; | ||
use std::io::{BufRead, BufReader}; | ||
|
||
fn file_lines() -> impl Iterator<Item = String> { | ||
BufReader::new(File::open("").unwrap()) | ||
.lines() | ||
.map(Result::unwrap) | ||
} | ||
|
||
fn main() { | ||
for _ in file_lines() {} | ||
} |