Closed
Description
following code does not compile:
struct Vec { x:float, y:float, z:float }
impl Vec {
pub fn getRef<'a>(&'a mut self, i:uint) -> &'a mut float {
// if(i==0) { &mut self.x }
// else if(i==1) { &mut self.x }
// else {&mut self.x }
match(i) {
0 => &mut self.x,
1 => &mut self.y,
_ => &mut self.z
}
}
}
I get following errors:
rustc test.rs -o test-test --test
test.rs:122:17: 122:28 error: cannot infer an appropriate lifetime due to conflicting requirements
test.rs:122 _ => &mut self.z
^~~~~~~~~~~
test.rs:121:17: 121:28 note: first, the lifetime must be contained by the expression at 121:17...
test.rs:121 1 => &mut self.y,
^~~~~~~~~~~
test.rs:121:17: 121:28 note: ...due to the following expression
test.rs:121 1 => &mut self.y,
^~~~~~~~~~~
test.rs:120:17: 120:28 note: but, the lifetime must also be contained by the expression at 120:17...
test.rs:120 0 => &mut self.x,
^~~~~~~~~~~
test.rs:120:17: 120:28 note: ...due to the following expression
test.rs:120 0 => &mut self.x,
^~~~~~~~~~~
error: aborting due to previous error
make: *** [test-test] Error 101
The commented version that is using if statements does compile correctly.
I haven't tried yet with very latest build, so I'm not sure whether the problem is still there with rust 0.7
cheers,
Rémi
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
nikomatsakis commentedon Jul 3, 2013
This looks like a bug, I agree. I suspect I know the cause of the error, but I'l need to investigate.l
thestinger commentedon Sep 23, 2013
This now compiles fine, due to the borrow checking improvements since 0.6.
Auto merge of rust-lang#7502 - flip1995:rollup-y3ho3w0, r=flip1995
Fix deploy script
Auto merge of rust-lang#7857 - flip1995:fix_deploy, r=xFrednet