summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0316.md
blob: 4368c321737b2b0ea0349ad05824334741deaefb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
A `where` clause contains a nested quantification over lifetimes.

Erroneous code example:

```compile_fail,E0316
trait Tr<'a, 'b> {}

fn foo<T>(t: T)
where
    for<'a> &'a T: for<'b> Tr<'a, 'b>, // error: nested quantification
{
}
```

Rust syntax allows lifetime quantifications in two places within
`where` clauses: Quantifying over the trait bound only (as in
`Ty: for<'l> Trait<'l>`) and quantifying over the whole clause
(as in `for<'l> &'l Ty: Trait<'l>`). Using both in the same clause
leads to a nested lifetime quantification, which is not supported.

The following example compiles, because the clause with the nested
quantification has been rewritten to use only one `for<>`:

```
trait Tr<'a, 'b> {}

fn foo<T>(t: T)
where
    for<'a, 'b> &'a T: Tr<'a, 'b>, // ok
{
}
```