Skip to content

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

Closed
@m-ou-se

Description

@m-ou-se

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.

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

No branches or pull requests

Issue actions