Skip to content

E0308 error message does not suggest to_string() for converting from &str to String #44672

Closed
@feadoor

Description

@feadoor

This snippet:

fn foo(s: String) {}

fn main() {
    let s = "this is a &str";
    foo(s);
}

results in the following compiler error:

error[E0308]: mismatched types
 --> src/main.rs:6:9
  |
6 |     foo(s);
  |         ^ expected struct `std::string::String`, found &str
  |
  = note: expected type `std::string::String`
             found type `&str`
  = help: here are some functions which might fulfill your needs:
          - .escape_debug()
          - .escape_default()
          - .escape_unicode()
          - .to_lowercase()
          - .to_uppercase()

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

It would be nice if this error message suggested the function which is actually most likely to be helpful here, which is to_string().

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions