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

Suggest borrowing if a trait implementation is found for &/&mut <type> regression #85865

Closed
pickfire opened this issue May 31, 2021 · 1 comment · Fixed by #89263
Closed

Suggest borrowing if a trait implementation is found for &/&mut <type> regression #85865

pickfire opened this issue May 31, 2021 · 1 comment · Fixed by #89263
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pickfire
Copy link
Contributor

pickfire commented May 31, 2021

When both &S and &mut S is implemented,

Given the following code:

trait Tr {}
struct S {}

impl Tr for &S {}
impl Tr for &mut S {}

fn foo<T: Tr>(t: T) {}

fn main() {
    let s = S {};
    foo(s);
}

The previous output was:

error[E0277]: the trait bound `S: Tr` is not satisfied
  --> src/main.rs:11:9
   |
7  | fn foo<T: Tr>(t: T) {}
   |           -- required by this bound in `foo`
...
11 |     foo(s);
   |         ^ the trait `Tr` is not implemented for `S`
   |
   = help: the following implementations were found:
             <&S as Tr>
             <&mut S as Tr>

The current output is:

error[E0277]: the trait bound `S: Tr` is not satisfied
  --> src/main.rs:11:9
   |
7  | fn foo<T: Tr>(t: T) {}
   |           -- required by this bound in `foo`
...
11 |     foo(s);
   |         ^
   |         |
   |         expected an implementor of trait `Tr`
   |         help: consider borrowing here: `&s`

Ideally the output should look like:

Not sure but it should show both &s and &mut s. The previous output seemed to do a better job there. Maybe we could keep the last part of the previous output.

   = help: the following implementations were found:
             <&S as Tr>
             <&mut S as Tr>

Caused by #85369, although it is better in the sense it is more specific but I think it omitted quite some useful details.

@pickfire pickfire 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 May 31, 2021
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 1, 2021
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Sep 26, 2021

@rustbot claim

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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.

3 participants