diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-02-27 16:14:41 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-03-13 11:22:07 -0400 |
| commit | 1e4e632ad8be2be00a1894c6c5946b730e12a5bd (patch) | |
| tree | c5cd861e6624d0aed2750c8255fa13df0a977835 /src | |
| parent | 36e5092dfa7fcc676c7d6b63f8dd692edd3399a5 (diff) | |
| download | rust-1e4e632ad8be2be00a1894c6c5946b730e12a5bd.tar.gz rust-1e4e632ad8be2be00a1894c6c5946b730e12a5bd.zip | |
add regression tests for various MIR bugs that get fixed
Fixes #31567 Fixes #47470 Fixes #48132 Fixes #48179
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/issue-48132.rs | 42 | ||||
| -rw-r--r-- | src/test/ui/issue-48179.rs | 51 | ||||
| -rw-r--r-- | src/test/ui/nll/issue-31567.rs | 37 | ||||
| -rw-r--r-- | src/test/ui/nll/issue-31567.stderr | 18 | ||||
| -rw-r--r-- | src/test/ui/nll/issue-47470.rs | 34 | ||||
| -rw-r--r-- | src/test/ui/nll/issue-47470.stderr | 17 |
6 files changed, 199 insertions, 0 deletions
diff --git a/src/test/ui/issue-48132.rs b/src/test/ui/issue-48132.rs new file mode 100644 index 00000000000..87fee986de7 --- /dev/null +++ b/src/test/ui/issue-48132.rs @@ -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()); +} diff --git a/src/test/ui/issue-48179.rs b/src/test/ui/issue-48179.rs new file mode 100644 index 00000000000..745b59e0658 --- /dev/null +++ b/src/test/ui/issue-48179.rs @@ -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() {} diff --git a/src/test/ui/nll/issue-31567.rs b/src/test/ui/nll/issue-31567.rs new file mode 100644 index 00000000000..a0d1faf1f0e --- /dev/null +++ b/src/test/ui/nll/issue-31567.rs @@ -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); +} diff --git a/src/test/ui/nll/issue-31567.stderr b/src/test/ui/nll/issue-31567.stderr new file mode 100644 index 00000000000..e0ff653e2b4 --- /dev/null +++ b/src/test/ui/nll/issue-31567.stderr @@ -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" diff --git a/src/test/ui/nll/issue-47470.rs b/src/test/ui/nll/issue-47470.rs new file mode 100644 index 00000000000..c962f193cd5 --- /dev/null +++ b/src/test/ui/nll/issue-47470.rs @@ -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); +} diff --git a/src/test/ui/nll/issue-47470.stderr b/src/test/ui/nll/issue-47470.stderr new file mode 100644 index 00000000000..1356461a6e4 --- /dev/null +++ b/src/test/ui/nll/issue-47470.stderr @@ -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" |
