diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-12-10 10:23:45 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-12-20 14:04:52 -0500 |
| commit | 93afb1affc9f4e7616e05a3fc2fdb66e81f35d1e (patch) | |
| tree | 2c2364727393a6c76b90666c4aa7c2051871dea0 /src/test | |
| parent | da63aaa7ab71ad5ba75340f3719591f370b847e2 (diff) | |
| download | rust-93afb1affc9f4e7616e05a3fc2fdb66e81f35d1e.tar.gz rust-93afb1affc9f4e7616e05a3fc2fdb66e81f35d1e.zip | |
connect NLL type checker to the impl trait code
We now add the suitable `impl Trait` constraints.
Diffstat (limited to 'src/test')
5 files changed, 121 insertions, 0 deletions
diff --git a/src/test/run-pass/impl-trait/example-calendar.rs b/src/test/run-pass/impl-trait/example-calendar.rs index 0b612c2d3ff..8d035bafab7 100644 --- a/src/test/run-pass/impl-trait/example-calendar.rs +++ b/src/test/run-pass/impl-trait/example-calendar.rs @@ -8,6 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// revisions: normal nll +//[nll] compile-flags: -Znll -Zborrowck=mir + #![feature(conservative_impl_trait, universal_impl_trait, fn_traits, diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.rs b/src/test/ui/nll/ty-outlives/impl-trait-captures.rs new file mode 100644 index 00000000000..896b74b579b --- /dev/null +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.rs @@ -0,0 +1,27 @@ +// Copyright 2016 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. + +// compile-flags:-Znll -Zborrowck=mir -Zverbose + +#![allow(warnings)] +#![feature(conservative_impl_trait)] + +trait Foo<'a> { +} + +impl<'a, T> Foo<'a> for T { } + +fn foo<'a, T>(x: &T) -> impl Foo<'a> { + x + //~^ WARNING not reporting region error due to -Znll + //~| ERROR free region `'_#2r` does not outlive free region `ReEarlyBound(0, 'a)` +} + +fn main() {} diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr new file mode 100644 index 00000000000..7de994dae88 --- /dev/null +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr @@ -0,0 +1,14 @@ +warning: not reporting region error due to -Znll + --> $DIR/impl-trait-captures.rs:22:5 + | +22 | x + | ^ + +error: free region `'_#2r` does not outlive free region `ReEarlyBound(0, 'a)` + --> $DIR/impl-trait-captures.rs:22:5 + | +22 | x + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/nll/ty-outlives/impl-trait-outlives.rs b/src/test/ui/nll/ty-outlives/impl-trait-outlives.rs new file mode 100644 index 00000000000..c03ec839808 --- /dev/null +++ b/src/test/ui/nll/ty-outlives/impl-trait-outlives.rs @@ -0,0 +1,51 @@ +// Copyright 2016 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. + +// compile-flags:-Znll -Zborrowck=mir -Zverbose + +#![allow(warnings)] +#![feature(conservative_impl_trait)] + +use std::fmt::Debug; + +fn no_region<'a, T>(x: Box<T>) -> impl Debug + 'a + //~^ WARNING not reporting region error due to -Znll +where + T: Debug, +{ + x + //~^ ERROR `T` does not outlive +} + +fn correct_region<'a, T>(x: Box<T>) -> impl Debug + 'a +where + T: 'a + Debug, +{ + x +} + +fn wrong_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a + //~^ WARNING not reporting region error due to -Znll +where + T: 'b + Debug, +{ + x + //~^ ERROR `T` does not outlive +} + +fn outlives_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a +where + T: 'b + Debug, + 'b: 'a, +{ + x +} + +fn main() {} diff --git a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr new file mode 100644 index 00000000000..4ebd2c7fc43 --- /dev/null +++ b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr @@ -0,0 +1,26 @@ +warning: not reporting region error due to -Znll + --> $DIR/impl-trait-outlives.rs:18:35 + | +18 | fn no_region<'a, T>(x: Box<T>) -> impl Debug + 'a + | ^^^^^^^^^^^^^^^ + +warning: not reporting region error due to -Znll + --> $DIR/impl-trait-outlives.rs:34:42 + | +34 | fn wrong_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a + | ^^^^^^^^^^^^^^^ + +error: `T` does not outlive `'_#1r` + --> $DIR/impl-trait-outlives.rs:23:5 + | +23 | x + | ^ + +error: `T` does not outlive `'_#1r` + --> $DIR/impl-trait-outlives.rs:39:5 + | +39 | x + | ^ + +error: aborting due to 2 previous errors + |
