diff --git a/src/test/ui/issue-48132.rs b/src/test/ui/issue-48132.rs new file mode 100644 index 0000000000000..87fee986de768 --- /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 or the MIT license +// , 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 { + iterator: I, + item: V, +} + +struct Outer { + inner: Inner, +} + +fn outer(iterator: I) -> Outer +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 0000000000000..745b59e0658f1 --- /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 or the MIT license +// , 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 { + value: Option, +} + +impl Container { + 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 0000000000000..a0d1faf1f0e84 --- /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 or the MIT license +// , 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); + +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 0000000000000..3d25b67ac07c9 --- /dev/null +++ b/src/test/ui/nll/issue-31567.stderr @@ -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" diff --git a/src/test/ui/nll/issue-47470.rs b/src/test/ui/nll/issue-47470.rs new file mode 100644 index 0000000000000..c962f193cd5b0 --- /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 or the MIT license +// , 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 0000000000000..414eac06a4a59 --- /dev/null +++ b/src/test/ui/nll/issue-47470.stderr @@ -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"