Skip to content

Incorrectly suggests replacing end characters of function call with double quotes #125595

Closed
@mi2ebi

Description

@mi2ebi

Code

fn example() -> char { 't' }
let mut s = "rus".to_string();
s += example();

Current output

error[E0308]: mismatched types
   --> src\tools.rs:100:10
    |
100 |     s += example();
    |          ^^^^^^^^^ expected `&str`, found `char`
    |
help: if you meant to write a string literal, use double quotes
    |
100 |     s += "xample(";
    |          ~       ~

Desired output

error[E0308]: mismatched types
   --> src\tools.rs:100:10
    |
100 |     s += example();
    |          ^^^^^^^^^ expected `&str`, found `char`
    |
help: [something better]
    |
100 |     s += &example().to_string();
    |          +         ++++++++++++

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.80.0-nightly (78a775127 2024-05-11)
binary: rustc
commit-hash: 78a77512702ab786f6f9345872d36d852454612c
commit-date: 2024-05-11
host: x86_64-pc-windows-msvc
release: 1.80.0-nightly
LLVM version: 18.1.4

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.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