Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonsensical error message for string error inside macro #58298

Closed
eira-fransham opened this issue Feb 8, 2019 · 0 comments
Closed

Nonsensical error message for string error inside macro #58298

eira-fransham opened this issue Feb 8, 2019 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eira-fransham
Copy link

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.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 8, 2019
Centril added a commit to Centril/rust that referenced this issue Mar 29, 2019
…r=davidtwco

Do not emit incorrect borrow suggestion involving macros and fix overlapping multiline spans

Fix rust-lang#58298.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants