Skip to content

appropriate lifetime and match #7502

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
remifontan opened this issue Jun 30, 2013 · 2 comments
Closed

appropriate lifetime and match #7502

remifontan opened this issue Jun 30, 2013 · 2 comments
Assignees
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@remifontan
Copy link

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

@nikomatsakis
Copy link
Contributor

This looks like a bug, I agree. I suspect I know the cause of the error, but I'l need to investigate.l

@ghost ghost assigned nikomatsakis Jul 3, 2013
@thestinger
Copy link
Contributor

This now compiles fine, due to the borrow checking improvements since 0.6.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 29, 2021
Rollup of 3 pull requests

Successful merges:

 - rust-lang#7279 (Adapting the lint list to Clippy's new metadata format)
 - rust-lang#7298 (Switch CI to new metadata collection)
 - rust-lang#7420 (Update lint documentation to use markdown headlines)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

changelog: rollup
flip1995 added a commit to flip1995/rust that referenced this issue Nov 4, 2021
I broke this script in rust-lang#7502, so that the stable symlink isn't generated
anymore. This reverts this change.
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 4, 2021
Fix deploy script

I broke this script in rust-lang#7502, so that the stable symlink isn't generated
anymore. This reverts this change.

changelog: none
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

3 participants