Skip to content

Suggested fix does not account for operator precedence #64919

@DomantasJ

Description

@DomantasJ

This fails (as expected):

fn foo() -> String {
    1 + 2
}

However, the help message is wrong:

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 | fn foo() -> String {
  |             ------ expected `std::string::String` because of return type
2 |     1 + 2
  |     ^^^^^
  |     |
  |     expected struct `std::string::String`, found integer
  |     help: try using a conversion method: `1 + 2.to_string()`
  |
  = note: expected type `std::string::String`
             found type `{integer}`

It should suggest (1 + 2).to_string() instead.

Rust version: 1.38.0 (stable)

Metadata

Metadata

Assignees

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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

No branches or pull requests

Issue actions