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

Support lifetime suggestion for method #13164

Closed
wants to merge 1 commit into from

Conversation

ktt3ja
Copy link
Contributor

@ktt3ja ktt3ja commented Mar 27, 2014

This includes a change to the way lifetime names are generated. Say we
figure that [#0, 'a, 'b] have to be the same lifetimes, then instead
of just generating a new lifetime 'c like before to replace them, we
would reuse 'a. This is done so that when the lifetime name comes
from an impl, we don't give something that's completely off, and we
don't have to do much work to figure out where the name came from. For
example, for the following code snippet:

struct Baz<'x> {
    bar: &'x int
}

impl<'x> Baz<'x> {
    fn baz1(&self) -> &int {
        self.bar
    }
}

[#1, 'x] (where #1 is BrAnon(1) and refers to lifetime of &int)
have to be marked the same lifetime. With the old method, we would
generate a new lifetime 'a and suggest fn baz1(&self) -> &'a int
or fn baz1<'a>(&self) -> &'a int, both of which are wrong.

@ktt3ja
Copy link
Contributor Author

ktt3ja commented Mar 27, 2014

@nikomatsakis: r?

@huonw
Copy link
Member

huonw commented Mar 27, 2014

@ktt3ja it's generally good practice to have a longer commit message (e.g. describing the change you described in your comment). :)

@ktt3ja
Copy link
Contributor Author

ktt3ja commented Mar 27, 2014

@huonw: I modified my comment a bit and moved it to the commit and PR messages.

//~^ NOTE: consider using an explicit lifetime parameter as shown: fn baz2<'b>(&self, x: &'b int) -> (&'a int, &'b int)
(self.bar, x) //~ ERROR: cannot infer
//~^ ERROR: mismatched types
//~^ ERROR: mismatched types
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, looks like test failed because I missed a ^. I will put it in there tomorrow...

@ktt3ja
Copy link
Contributor Author

ktt3ja commented Apr 3, 2014

@nikomatsakis: r?

@nikomatsakis
Copy link
Contributor

r+

This includes a change to the way lifetime names are generated. Say we
figure that `[#0, 'a, 'b]` have to be the same lifetimes, then instead
of just generating a new lifetime `'c` like before to replace them, we
would reuse `'a`. This is done so that when the lifetime name comes
from an impl, we don't give something that's completely off, and we
don't have to do much work to figure out where the name came from. For
example, for the following code snippet:

```rust
struct Baz<'x> {
    bar: &'x int
}

impl<'x> Baz<'x> {
    fn baz1(&self) -> &int {
        self.bar
    }
}
```

`[rust-lang#1, 'x]` (where `rust-lang#1` is BrAnon(1) and refers to lifetime of `&int`)
have to be marked the same lifetime. With the old method, we would
generate a new lifetime `'a` and suggest `fn baz1(&self) -> &'a int`
or `fn baz1<'a>(&self) -> &'a int`, both of which are wrong.
@ktt3ja
Copy link
Contributor Author

ktt3ja commented Apr 15, 2014

@nikomatsakis: PR got stale so I just rebased it.

bors added a commit that referenced this pull request Apr 15, 2014
…sakis

This includes a change to the way lifetime names are generated. Say we
figure that `[#0, 'a, 'b]` have to be the same lifetimes, then instead
of just generating a new lifetime `'c` like before to replace them, we
would reuse `'a`. This is done so that when the lifetime name comes
from an impl, we don't give something that's completely off, and we
don't have to do much work to figure out where the name came from. For
example, for the following code snippet:

```rust
struct Baz<'x> {
    bar: &'x int
}

impl<'x> Baz<'x> {
    fn baz1(&self) -> &int {
        self.bar
    }
}
```

`[#1, 'x]` (where `#1` is BrAnon(1) and refers to lifetime of `&int`)
have to be marked the same lifetime. With the old method, we would
generate a new lifetime `'a` and suggest `fn baz1(&self) -> &'a int`
or `fn baz1<'a>(&self) -> &'a int`, both of which are wrong.
@bors bors closed this Apr 15, 2014
@ktt3ja ktt3ja deleted the lifetime-suggestion-method branch April 16, 2014 00:18
dingxiangfei2009 pushed a commit to dingxiangfei2009/rust that referenced this pull request Jul 28, 2024
Bump ui_test version -> 0.25

r? `@Alexendoo`

cc `@GuillaumeGomez`

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants