Skip to content

Commit c82b2bc

Browse files
authored
Rollup merge of #92351 - TmLev:master, r=GuillaumeGomez
Add long error explanation for E0227 Part of the #61137.
2 parents 0e41194 + 406d6d4 commit c82b2bc

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ E0223: include_str!("./error_codes/E0223.md"),
120120
E0224: include_str!("./error_codes/E0224.md"),
121121
E0225: include_str!("./error_codes/E0225.md"),
122122
E0226: include_str!("./error_codes/E0226.md"),
123+
E0227: include_str!("./error_codes/E0227.md"),
123124
E0228: include_str!("./error_codes/E0228.md"),
124125
E0229: include_str!("./error_codes/E0229.md"),
125126
E0230: include_str!("./error_codes/E0230.md"),
@@ -530,7 +531,6 @@ E0786: include_str!("./error_codes/E0786.md"),
530531
// E0217, // ambiguous associated type, defined in multiple supertraits
531532
// E0218, // no associated type defined
532533
// E0219, // associated type defined in higher-ranked supertrait
533-
E0227, // ambiguous lifetime bound, explicit lifetime bound required
534534
// E0233,
535535
// E0234,
536536
// E0235, // structure constructor specifies a structure of type but
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
This error indicates that the compiler is unable to determine whether there is
2+
exactly one unique region in the set of derived region bounds.
3+
4+
Example of erroneous code:
5+
6+
```compile_fail,E0227
7+
trait Foo<'foo>: 'foo {}
8+
trait Bar<'bar>: 'bar {}
9+
10+
trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {}
11+
12+
struct Baz<'foo, 'bar> {
13+
baz: dyn FooBar<'foo, 'bar>,
14+
}
15+
```
16+
17+
Here, `baz` can have either `'foo` or `'bar` lifetimes.
18+
19+
To resolve this error, provide an explicit lifetime:
20+
21+
```rust
22+
trait Foo<'foo>: 'foo {}
23+
trait Bar<'bar>: 'bar {}
24+
25+
trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {}
26+
27+
struct Baz<'foo, 'bar, 'baz>
28+
where
29+
'baz: 'foo + 'bar,
30+
{
31+
obj: dyn FooBar<'foo, 'bar> + 'baz,
32+
}
33+
```

src/test/ui/error-codes/E0227.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Foo<'foo>: 'foo {}
2+
trait Bar<'bar>: 'bar {}
3+
4+
trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {}
5+
6+
struct Baz<'foo, 'bar> {
7+
baz: dyn FooBar<'foo, 'bar>,
8+
//~^ ERROR ambiguous lifetime bound, explicit lifetime bound required
9+
}
10+
11+
fn main() {
12+
}

src/test/ui/error-codes/E0227.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
2+
--> $DIR/E0227.rs:7:10
3+
|
4+
LL | baz: dyn FooBar<'foo, 'bar>,
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0227`.

src/tools/tidy/src/error_codes_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use regex::Regex;
1010

1111
// A few of those error codes can't be tested but all the others can and *should* be tested!
1212
const EXEMPTED_FROM_TEST: &[&str] = &[
13-
"E0227", "E0279", "E0280", "E0313", "E0377", "E0461", "E0462", "E0465", "E0476", "E0514",
14-
"E0519", "E0523", "E0554", "E0640", "E0717", "E0729",
13+
"E0279", "E0280", "E0313", "E0377", "E0461", "E0462", "E0465", "E0476", "E0514", "E0519",
14+
"E0523", "E0554", "E0640", "E0717", "E0729",
1515
];
1616

1717
// Some error codes don't have any tests apparently...

0 commit comments

Comments
 (0)