add regression tests for various MIR bugs that get fixed

Fixes #31567
Fixes #47470
Fixes #48132
Fixes #48179
This commit is contained in:
Niko Matsakis 2018-02-27 16:14:41 -05:00
parent 36e5092dfa
commit 1e4e632ad8
6 changed files with 199 additions and 0 deletions

View File

@ -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());
}

View File

@ -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() {}

View File

@ -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);
}

View File

@ -0,0 +1,18 @@
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 the lifetime 'a as defined on the function body at 21:1...
--> $DIR/issue-31567.rs:21:1
|
LL | fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
If you want more information on this error, try using "rustc --explain E0597"

View File

@ -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);
}

View File

@ -0,0 +1,17 @@
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 the lifetime 'a as defined on the impl at 23:1...
--> $DIR/issue-47470.rs:23:1
|
LL | impl<'a> Bar for Foo<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
If you want more information on this error, try using "rustc --explain E0597"