Type bounds may be higher ranked over lifetimes. These bounds specify a bound is true for all lifetimes. For example, a bound such as `for<'a> &'a T: PartialEq<i32>` would require an implementation like:
```rust
impl<'a> PartialEq<i32> for &'a T {
// ...
}
```
and could then be used to compare a `&'a T` with any lifetime to an `i32`.
Only a higher-ranked bound can be used here, because the lifetime of the reference is shorter than any possible lifetime parameter on the functionγ
4γπππ
```rust
/* Adding HRTB to make it work!*/
fn call_on_ref_zero<'a, F>(f: F) where F: Fn(&'a i32) {
let zero = 0;
f(&zero);
}
fn main() {
println!("Success!")
}
```
## NLL (Non-Lexical Lifetime)
Before explaining NLL, let's see some code first:
```rust
fn main() {
let mut s = String::from("hello");
let r1 = &s;
let r2 = &s;
println!("{} and {}", r1, r2);
let r3 = &mut s;
println!("{}", r3);
}
```
Based on our current knowledge, this code will cause en error due to violating the borrowing rules in Rust.
But if you `cargo run` it, then everything will be ok, so what's going on here?
The ability of the compiler to tell that a reference is no longer used at a point before the end of the scope, is called **Non-Lexical Lifetimes** (**NLL** for short).
With this ability the compiler knows when is the last time that a reference is used and optimizing the borrowing rules based on this knowledge.
```rust
let mut u = 0i32;
let mut v = 1i32;
let mut w = 2i32;
// lifetime of `a` = Ξ±βͺ Ξ² βͺΞ³
let mut a = &mut u; // --+ Ξ±. lifetime of `&mut u` --+ lexical "lifetime" of `&mut u`,`&mut u`, `&mut w` and `a`