Skip to content

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

Closed
@pickfire

Description

@pickfire
Contributor

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.

Activity

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 May 31, 2021
added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jul 1, 2021
TaKO8Ki

TaKO8Ki commented on Sep 26, 2021

@TaKO8Ki
Member

@rustbot claim

added a commit that references this issue on Sep 27, 2021

Auto merge of rust-lang#89263 - TaKO8Ki:suggest-both-immutable-and-mu…

3e8f32e
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 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

    Participants

    @pickfire@JohnTitor@TaKO8Ki

    Issue actions

      Suggest borrowing if a trait implementation is found for &/&mut <type> regression · Issue #85865 · rust-lang/rust