Skip to content

Suggestions are often invalid for proc-macro produced code #85932

@m-ou-se

Description

@m-ou-se
Member

The tokens generated by proc_macro (e.g. from quote!()) use Span::call_site(), which makes some suggestions produce invalid output:

error[E0308]: mismatched types
 --> src/main.rs:3:1
  |
3 | #[hello]
  | ^^^^^^^^
  | |
  | expected `&mut i32`, found integer
  | help: consider mutably borrowing here: `&mut #[hello]`

It's a bit tricky, because this call_site span does point into the current crate (to #[hello]), so this situaiton isn't detected in the same way as external macro_rules.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-confusingDiagnostics: Confusing error or lint that should be reworked.
D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
on Jun 2, 2021
self-assigned this
on Jun 2, 2021
m-ou-se

m-ou-se commented on Jun 2, 2021

@m-ou-se
MemberAuthor

Looks like rustc_middle::lint::in_external_macro should be used in more places. That one detects this call_site span by checking if def_site is a dummy or imported.

m-ou-se

m-ou-se commented on Jun 2, 2021

@m-ou-se
MemberAuthor

I'm working on a fix specifically for these typeck/borrowing suggestions. Not sure how many other suggestions have the same problem.

estebank

estebank commented on Jun 3, 2021

@estebank
Contributor

@m-ou-se this is a prevalent problem. We need to add metadata to spans to distinguish call sites explicitly in an easy way and always ignore suggestions in them.

added 2 commits that reference this issue on Jun 3, 2021
2bd3237
99fc56b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-confusingDiagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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

    Participants

    @m-ou-se@estebank

    Issue actions

      Suggestions are often invalid for proc-macro produced code · Issue #85932 · rust-lang/rust