diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-03-21 06:31:39 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-03-22 16:54:51 -0400 |
| commit | d913af8691d4002166c9a6e1b60e51407cf82c9c (patch) | |
| tree | 876984a846440f506a96f57959418e7ab4174e67 | |
| parent | f07ebc5df806ac9bd2a178f525b5422ce20d4e3c (diff) | |
| download | rust-d913af8691d4002166c9a6e1b60e51407cf82c9c.tar.gz rust-d913af8691d4002166c9a6e1b60e51407cf82c9c.zip | |
add new test for `dyn<Trait + '_>` used in a struct
`'_` is illegal in structs; this currently gets a duplicate error
| -rw-r--r-- | src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.stderr | 16 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.rs b/src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.rs new file mode 100644 index 00000000000..d10541ad33b --- /dev/null +++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.rs @@ -0,0 +1,26 @@ +// 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. + +// Check that the `'_` in `dyn Trait + '_` acts like ordinary elision, +// and not like an object lifetime default. +// +// cc #48468 + +#![feature(dyn_trait)] +#![feature(underscore_lifetimes)] + +use std::fmt::Debug; + +struct Foo { + x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier + //~^ ERROR E0228 +} + +fn main() { } diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.stderr b/src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.stderr new file mode 100644 index 00000000000..a88ecb18dd6 --- /dev/null +++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.stderr @@ -0,0 +1,16 @@ +error[E0106]: missing lifetime specifier + --> $DIR/dyn-trait-underscore-in-struct.rs:22:24 + | +LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier + | ^^ expected lifetime parameter + +error[E0228]: the lifetime bound for this object type cannot be deduced from context; please supply an explicit bound + --> $DIR/dyn-trait-underscore-in-struct.rs:22:12 + | +LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier + | ^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +Some errors occurred: E0106, E0228. +For more information about an error, try `rustc --explain E0106`. |
