Skip to content

Commit d913af8

Browse files
committed
add new test for dyn<Trait + '_> used in a struct
`'_` is illegal in structs; this currently gets a duplicate error
1 parent f07ebc5 commit d913af8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that the `'_` in `dyn Trait + '_` acts like ordinary elision,
12+
// and not like an object lifetime default.
13+
//
14+
// cc #48468
15+
16+
#![feature(dyn_trait)]
17+
#![feature(underscore_lifetimes)]
18+
19+
use std::fmt::Debug;
20+
21+
struct Foo {
22+
x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier
23+
//~^ ERROR E0228
24+
}
25+
26+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/dyn-trait-underscore-in-struct.rs:22:24
3+
|
4+
LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier
5+
| ^^ expected lifetime parameter
6+
7+
error[E0228]: the lifetime bound for this object type cannot be deduced from context; please supply an explicit bound
8+
--> $DIR/dyn-trait-underscore-in-struct.rs:22:12
9+
|
10+
LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
Some errors occurred: E0106, E0228.
16+
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)