Closed
Description
pub struct S<'a>(&'a int);
impl<'a> PartialEq for S<'a> {
fn eq(&self, b: &S<'a>) -> bool {
true
}
}
fn main() {
let i = 1;
let a = S(&i);
{
let j = 0;
let b = S(&j);
(a == b);
}
}
a.rs:15:20: 15:21 error: `j` does not live long enough
a.rs:15 let b = S(&j);
^
a.rs:9:11: 19:2 note: reference must be valid for the block at 9:10...
a.rs:9 fn main() {
a.rs:10 let i = 1;
a.rs:11 let a = S(&i);
a.rs:12
a.rs:13 {
a.rs:14 let j = 0;
...
a.rs:13:5: 18:6 note: ...but borrowed value is only valid for the block at 13:4
a.rs:13 {
a.rs:14 let j = 0;
a.rs:15 let b = S(&j);
a.rs:16
a.rs:17 (a == b);
a.rs:18 }
a == b
causes error but b == a
or a.eq(&b)
don't. Same for a < b
.