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

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

Closed
MikailBag opened this issue Apr 13, 2021 · 1 comment · Fixed by #86666
Closed

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

MikailBag opened this issue Apr 13, 2021 · 1 comment · Fixed by #86666
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MikailBag
Copy link
Contributor

MikailBag commented Apr 13, 2021

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

@MikailBag MikailBag added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 13, 2021
@ptrojahn
Copy link
Contributor

@rustbot claim

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 1, 2021
Fix misleading "impl Trait" error

The kinds can't be compared directly, as types with references are treated as different because the lifetimes aren't bound in ty, but are in expected.
Closes rust-lang#84160
@bors bors closed this as completed in 61554bc Jul 1, 2021
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants