add new test for dyn<Trait + '_> used in a struct

`'_` is illegal in structs; this currently gets a duplicate error
This commit is contained in:
Niko Matsakis 2018-03-21 06:31:39 -04:00
parent f07ebc5df8
commit d913af8691
2 changed files with 42 additions and 0 deletions

View File

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

View File

@ -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`.