Skip to content

Error message mentions impl trait even though no traits are involved #84160

Description

@MikailBag

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0aed05fe97333e35dc688bc76eabd8ad

use std::path::Path;

fn path_starts_with<'a>(path: &'a Path) -> Option<&'a Path> {
    if false {
        return None;
    }
    return Path::new("/");
}

The current output is:

// ... standard error about type mismatch
= note: to return `impl Trait`, all returned values must be of the same type
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
  

The error message should not message impl Trait, because it has nothing to do with this code (from user PoV)

If I change the code to the following:

use std::path::Path;

fn path_starts_with<'a>(/*no parameter here anymore*/) -> Option<&'a Path> {
    if false {
        return None;
    }
    return Path::new("/");
}

Confusing message goes away

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 13, 2021
  2. ptrojahn commented on Jun 19, 2021

    @ptrojahn
    Contributor

    @rustbot claim

  3. added a commit that references this issue on Jul 1, 2021
    7e27209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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