Skip to content

Missing parenthesis in help message #109436

Closed
@gabi-250

Description

@gabi-250

Code

struct Foo;

struct Bar;

impl From<&Foo> for Bar {
    fn from(foo: &Foo) -> Bar {
        Bar
    }
}

fn main() {
    let foo = Foo;
    let b: Bar = foo.into();
}

Current output

error[E0277]: the trait bound `Foo: Into<_>` is not satisfied
  --> src/main.rs:13:22
   |
13 |     let b: Bar = foo.into();
   |                      ^^^^ the trait `~const Into<_>` is not implemented for `Foo`
   |
   = note: required for `Foo` to implement `Into<Bar>`
help: consider borrowing here
   |
13 |     let b: Bar = &foo.into();
   |                  +

For more information about this error, try `rustc --explain E0277`.
error: could not compile `reference-loop` due to previous error

Desired output

error[E0277]: the trait bound `Foo: Into<_>` is not satisfied
  --> src/main.rs:13:22
   |
13 |     let b: Bar = foo.into();
   |                      ^^^^ the trait `~const Into<_>` is not implemented for `Foo`
   |
   = note: required for `Foo` to implement `Into<Bar>`
help: consider borrowing here
   |
13 |     let b: Bar = (&foo).into();
   |                   +

For more information about this error, try `rustc --explain E0277`.
error: could not compile `reference-loop` due to previous error

Rationale and extra context

No response

Other cases

No response

Anything else?

The help message suggests borrowing foo.into(), which obviously doesn't fix the issue (it leads to a series of other misleading errors). This happens using rustc 1.68.0 (2c8cc3432 2023-03-06).

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