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 param suggestion misses an inner 'a #17119

Closed
pnkfelix opened this issue Sep 9, 2014 · 3 comments
Closed

lifetime param suggestion misses an inner 'a #17119

pnkfelix opened this issue Sep 9, 2014 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Sep 9, 2014

Here is some playpen code: http://is.gd/0HoeAB

Within it, there is the following routine:

        fn map_inner<'a, X:'a, Y:'a>(
            f: |&X| -> Y,
            n: NodeRef<'a, X>,
            nodes: &'a TypedArena<Node<Y>>) -> NodeRef<'a, Y> {

            match n {
                None => None,
                Some(ref n) => {
                    let y = f(&n.data);
                    Some(nodes.alloc(Node {
                                        data: y,
                                        next: map_inner(f, n.next, nodes)
                                    }))
                }
            }
        }

The signature above has a bug; it omitted a lifetime on the type of nodes.

The current lifetime suggestion that rustc produces does not include that though.

The current lifetime suggestion says:

note: consider using an explicit lifetime parameter as shown: fn map_inner<'a, X: 'a,
             Y: 'a>(f: |&X| -> Y, n: NodeRef<'a, X>,
                    nodes: &'a TypedArena<Node<Y>>) -> NodeRef<'a, Y>

when I think it should be:

note: consider using an explicit lifetime parameter as shown: fn map_inner<'a, X: 'a,
             Y: 'a>(f: |&X| -> Y, n: NodeRef<'a, X>,
                    nodes: &'a TypedArena<Node<'a, Y>>) -> NodeRef<'a, Y>

(Note the additional 'ain the type ofnodes`.)

At least, after adding that, the playpen code gets further along in compilation.

(Sorry for not reducing the test case further. Hopefully I will get the chance to do so in the near future.)

@huonw
Copy link
Member

huonw commented Sep 9, 2014

The current suggestion seems to be identical to the code that exists? (Sometimes it doesn't give the full set of annotations immediately, and you have to adjust & recompile a few times to reach the final correct solution, but this doesn't seem to be the case here.)

@huonw huonw added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions labels Sep 9, 2014
@eefriedman
Copy link
Contributor

This works correctly on current Rust: https://play.rust-lang.org/?gist=266c07479fc9c8d16d38&version=stable .

@alexcrichton
Copy link
Member

Yay!

lnicola pushed a commit to lnicola/rust that referenced this issue Apr 24, 2024
internal: Extract common fields out of `ProjectWorkspace` variants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

4 participants