Skip to content

Don't hint to add a lifetime parameter for trait impls #37363

Closed

Description

@mrmonday

Spotted on a reddit thread (https://www.reddit.com/r/rust/comments/57virt/hey_rustaceans_got_an_easy_question_ask_here/d941p6y/?context=3).

This code (playpen):

use std::str::FromStr;

pub struct Foo<'a> {
    field: &'a str,
}

impl<'a> FromStr for Foo<'a> {
    type Err = ();
    fn from_str(path: &str) -> Result<Self, ()> {
        Ok(Foo { field: path })
    }
}

Gives the following hint:

help: consider using an explicit lifetime parameter as shown: fn from_str(path: &'a str) -> Result<Self, ()>
  --> <anon>:9:5
   |
9  |     fn from_str(path: &str) -> Result<Self, ()> {
   |     ^

Which is never correct, since then there will be a lifetime mismatch between the impl and the trait.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    on Oct 23, 2016
  2. added a commit that references this issue on Nov 11, 2016
  3. added a commit that references this issue on Nov 12, 2016
  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions