Skip to content

using 'self in return values doesn't appear to require a 'self parameter #5671

@thestinger

Description

@thestinger
Contributor

as shown by https://github.com/mozilla/rust/pull/5670/files

I was already using 'self in the return values for find and find_mut in the Map trait.

I'm not entirely sure this is a bug.... but it's an inconsistency.

Activity

nikomatsakis

nikomatsakis commented on Apr 2, 2013

@nikomatsakis
Contributor

It's a bug, if a minor one. cc #4846

graydon

graydon commented on Jun 6, 2013

@graydon
Contributor

This testcase:

fn main() { }
struct Foo { x: int }
impl Foo {
    fn bleh(&self) -> &'self int {
        return &self.x
    }
}

Now produces the error:

t.rs:4:29: 4:32 error: Illegal lifetime 'self: the `self` lifetime must be declared
t.rs:4     fn bleh(&self) -> &'self int {
                                    ^~~

And the error goes away if I change the impl to:

impl<'self> Foo {
    fn bleh(&'self self) -> &'self int {
        return &self.x
    }
}

So I'm going to say this is closed. Reopen if I misunderstood.

added a commit that references this issue on Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @graydon@nikomatsakis@thestinger

      Issue actions

        using 'self in return values doesn't appear to require a 'self parameter · Issue #5671 · rust-lang/rust