-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.
Description
I tried this code:
#![allow(unused_mut)]
#![allow(unused_variables)]
#[cfg(all())]
fn main() {
fn only_accept_lifetime_of<'a, T: 'a>(_r: &'a T) -> fn(&'a mut T) {
fn x<'b, T: 'b>(_: &'b mut T) {}
x::<'a, T>
}
let mut a = 1;
{
let mut b = &mut a;
let f = only_accept_lifetime_of(b);
{
let mut c = &mut b;
f(c);
{
let mut d = 9;
f(&mut d);
}
c;
}
}
}only_accept_lifetime_of returns a function which early bound to a specified lifetime.
In the code above, f should only accept argument with same life time as b;
And, the following code compiles, which is a surprise:
&mut d must terminate at the end of the block containing d, c however, has a bigger lifetime, which definitely does not equal with '&mut d'.
But both f(c) and f(&mut d) are accepted.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.