Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Lifetime inference issue when destructuring in argument list #13167

Closed
sfackler opened this issue Mar 27, 2014 · 2 comments · Fixed by #17721
Closed

Lifetime inference issue when destructuring in argument list #13167

sfackler opened this issue Mar 27, 2014 · 2 comments · Fixed by #17721
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@sfackler
Copy link
Member

I would expect that the sadface and non-sadface versions of next would be equivalent, but the sadface one is rejected and the other is not:

use std::slice;

pub struct PhfMapEntries<'a, T> {
    priv iter: slice::Items<'a, (&'static str, T)>,
}

impl<'a, T> Iterator<(&'static str, &'a T)> for PhfMapEntries<'a, T> {
    #[cfg(sadface)]
    fn next(&mut self) -> Option<(&'static str, &'a T)> {
        self.iter.by_ref().map(|&(key, ref value)| (key, value)).next()
    }

    #[cfg(not(sadface))]
    fn next(&mut self) -> Option<(&'static str, &'a T)> {
        self.iter.by_ref().map(|e| {
            let &(key, ref value) = e;
            (key, value)
        }).next()
    }

    fn size_hint(&self) -> (uint, Option<uint>) {
        self.iter.size_hint()
    }
}

fn main() {}
~ ❯ rustc --cfg sadface test.rs
test.rs:10:40: 10:49 error: borrowed value does not live long enough
test.rs:10         self.iter.by_ref().map(|&(key, ref value)| (key, value)).next()
                                                  ^~~~~~~~~
test.rs:9:57: 11:6 note: reference must be valid for the lifetime &'a  as defined on the block at 9:56...
test.rs:9     fn next(&mut self) -> Option<(&'static str, &'a T)> {
test.rs:10         self.iter.by_ref().map(|&(key, ref value)| (key, value)).next()
test.rs:11     }
test.rs:10:9: 10:72 note: ...but borrowed value is only valid for the method call at 10:8
test.rs:10         self.iter.by_ref().map(|&(key, ref value)| (key, value)).next()
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@edwardw
Copy link
Contributor

edwardw commented Mar 27, 2014

A manifestation of #3696?

@ghost
Copy link

ghost commented Oct 1, 2014

Works as intended now but needs a test.

@alexcrichton alexcrichton added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 1, 2014
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Sep 6, 2022
feat: Implement `feature(exhaustive_patterns)` from unstable Rust

Closes rust-lang#12753

Recognize Rust's unstable `#![feature(exhaustive_patterns)]` (RFC 1872). Allow omitting visibly uninhabited variants from `match` expressions when the feature is on.

This adjusts match checking to the current implementation of the postponed RFC 1872 in rustc.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 24, 2024
Added new `non_zero_suggestions` lint

Created lint based on the suggestions in rust-lang#7291

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

----

changelog: new [`non_zero_suggestions`] lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants