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.
add regression tests for various MIR bugs that get fixed
Fixes rust-lang#31567 Fixes rust-lang#47470 Fixes rust-lang#48132 Fixes rust-lang#48179
- Loading branch information
1 parent
3f6e611
commit 027eb10
Showing
6 changed files
with
191 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,42 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Regression test for #48132. This was failing due to problems around | ||
// the projection caching and dropck type enumeration. | ||
|
||
// run-pass | ||
|
||
#![feature(nll)] | ||
#![allow(warnings)] | ||
|
||
struct Inner<I, V> { | ||
iterator: I, | ||
item: V, | ||
} | ||
|
||
struct Outer<I: Iterator> { | ||
inner: Inner<I, I::Item>, | ||
} | ||
|
||
fn outer<I>(iterator: I) -> Outer<I> | ||
where I: Iterator, | ||
I::Item: Default, | ||
{ | ||
Outer { | ||
inner: Inner { | ||
iterator: iterator, | ||
item: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
outer(std::iter::once(&1).cloned()); | ||
} |
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,51 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Regression test for #48132. This was failing due to problems around | ||
// the projection caching and dropck type enumeration. | ||
|
||
// run-pass | ||
|
||
#![feature(nll)] | ||
#![allow(warnings)] | ||
|
||
pub struct Container<T: Iterator> { | ||
value: Option<T::Item>, | ||
} | ||
|
||
impl<T: Iterator> Container<T> { | ||
pub fn new(iter: T) -> Self { | ||
panic!() | ||
} | ||
} | ||
|
||
pub struct Wrapper<'a> { | ||
content: &'a Content, | ||
} | ||
|
||
impl<'a, 'de> Wrapper<'a> { | ||
pub fn new(content: &'a Content) -> Self { | ||
Wrapper { | ||
content: content, | ||
} | ||
} | ||
} | ||
|
||
pub struct Content; | ||
|
||
fn crash_it(content: Content) { | ||
let items = vec![content]; | ||
let map = items.iter().map(|ref o| Wrapper::new(o)); | ||
|
||
let mut map_visitor = Container::new(map); | ||
|
||
} | ||
|
||
fn main() {} |
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,37 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Regression test for #31567: cached results of projections were | ||
// causing region relations not to be enforced at all the places where | ||
// they have to be enforced. | ||
|
||
#![feature(nll)] | ||
|
||
struct VecWrapper<'a>(&'a mut S); | ||
|
||
struct S(Box<u32>); | ||
|
||
fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 { | ||
let s_inner: &'a S = &*v.0; //~ ERROR `*v.0` does not live long enough | ||
&s_inner.0 | ||
} | ||
|
||
impl<'a> Drop for VecWrapper<'a> { | ||
fn drop(&mut self) { | ||
*self.0 = S(Box::new(0)); | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut s = S(Box::new(11)); | ||
let vw = VecWrapper(&mut s); | ||
let dangling = get_dangling(vw); | ||
println!("{}", dangling); | ||
} |
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 @@ | ||
error[E0597]: `*v.0` does not live long enough | ||
--> $DIR/issue-31567.rs:22:26 | ||
| | ||
LL | let s_inner: &'a S = &*v.0; //~ ERROR `*v.0` does not live long enough | ||
| ^^^^^ borrowed value does not live long enough | ||
LL | &s_inner.0 | ||
LL | } | ||
| - borrowed value only lives until here | ||
| | ||
= note: borrowed value must be valid for lifetime '_#3r... | ||
|
||
error: aborting due to previous error | ||
|
||
If you want more information on this error, try using "rustc --explain E0597" |
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,34 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Regression test for #47470: cached results of projections were | ||
// causing region relations not to be enforced at all the places where | ||
// they have to be enforced. | ||
|
||
#![feature(nll)] | ||
|
||
struct Foo<'a>(&'a ()); | ||
trait Bar { | ||
type Assoc; | ||
fn get(self) -> Self::Assoc; | ||
} | ||
|
||
impl<'a> Bar for Foo<'a> { | ||
type Assoc = &'a u32; | ||
fn get(self) -> Self::Assoc { | ||
let local = 42; | ||
&local //~ ERROR `local` does not live long enough | ||
} | ||
} | ||
|
||
fn main() { | ||
let f = Foo(&()).get(); | ||
println!("{}", f); | ||
} |
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,13 @@ | ||
error[E0597]: `local` does not live long enough | ||
--> $DIR/issue-47470.rs:27:9 | ||
| | ||
LL | &local //~ ERROR `local` does not live long enough | ||
| ^^^^^^ borrowed value does not live long enough | ||
LL | } | ||
| - borrowed value only lives until here | ||
| | ||
= note: borrowed value must be valid for lifetime '_#4r... | ||
|
||
error: aborting due to previous error | ||
|
||
If you want more information on this error, try using "rustc --explain E0597" |