Skip to content

Nonsensical error message for string error inside macro #58298

Closed
@eira-fransham

Description

@eira-fransham

Apologies if this has been posted before, I couldn't find anything but many of my searches had several hundred results and I didn't want to go through pages upon pages of them for such a minor issue (yeah, I'm part of the problem, sorry).

If you have an error where you pass a String instead of a &str inside a macro, the suggestion rustc emits is meaningless:

error[E0308]: mismatched types
    --> src/tests.rs:1108:1
     |
1108 | test_select!(select32, i32);
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     | |
     | expected &str, found struct `std::string::String`
     | help: consider borrowing here: `&test_select!(select32, i32);`
     | in this macro invocation
     |
     = note: expected type `&str`
                found type `std::string::String`
     = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Note this:

help: consider borrowing here: `&test_select!(select32, i32);`

This is an item-position macro and so this suggestion will only cause a syntax error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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