Skip to content

Commit c01d63a

Browse files
committed
Add E0316.md
1 parent a20870b commit c01d63a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ E0308: include_str!("./error_codes/E0308.md"),
157157
E0309: include_str!("./error_codes/E0309.md"),
158158
E0310: include_str!("./error_codes/E0310.md"),
159159
E0312: include_str!("./error_codes/E0312.md"),
160+
E0316: include_str!("./error_codes/E0316.md"),
160161
E0317: include_str!("./error_codes/E0317.md"),
161162
E0321: include_str!("./error_codes/E0321.md"),
162163
E0322: include_str!("./error_codes/E0322.md"),
@@ -555,7 +556,6 @@ E0783: include_str!("./error_codes/E0783.md"),
555556
// variable
556557
// E0314, // closure outlives stack frame
557558
// E0315, // cannot invoke closure outside of its lifetime
558-
E0316, // nested quantification of lifetimes
559559
// E0319, // trait impls for defaulted traits allowed just for structs/enums
560560
E0320, // recursive overflow during dropck
561561
// E0372, // coherence not object safe
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
A `where` clause contains a nested quantification over lifetimes.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0316
6+
trait Tr<'a, 'b> {}
7+
8+
fn foo<T>(t: T)
9+
where
10+
for<'a> &'a T: for<'b> Tr<'a, 'b>, // error: nested quantification
11+
{
12+
}
13+
```
14+
15+
Rust syntax allows lifetime quantifications in two places within
16+
`where` clauses: Quantifying over the trait bound only (as in
17+
`Ty: for<'l> Trait<'l>`) and quantifying over the whole clause
18+
(as in `for<'l> &'l Ty: Trait<'l>`). Using both in the same clause
19+
leads to a nested lifetime quantification, which is not supported.
20+
21+
The following example compiles, because the clause with the nested
22+
quantification has been rewritten to use only one `for<>`:
23+
24+
```
25+
trait Tr<'a, 'b> {}
26+
27+
fn foo<T>(t: T)
28+
where
29+
for<'a, 'b> &'a T: Tr<'a, 'b>, // ok
30+
{
31+
}
32+
```

0 commit comments

Comments
 (0)