]>
Commit | Line | Data |
---|---|---|
17df50a5 XL |
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 | ``` |