Skip to content

meta: expanded macros in suggestions break code #6851

Open
@matthiaskrgr

Description

@matthiaskrgr

There have been a couple of problems already with broken suggestions with macros.
The snippet function does not deal with macros very well which is why we have snippet_with_macro_callsite which uses the original macro unexpanded.

For example if we have some kind x.map(|_| vec![]) code, the redundant_closure lint would suggest to replace vec![] with $crate::vec::Vec::new which should just be Vec::new().
cargo clippy --fix fills in the suggestion and the crate no longer builds because what is x.map(|_| $crate::......

I'm wondering, what are valid cases where DO want to have an expanded macro inside a fix suggestion?
Can we fix this class of bugs once and for all by just making the snippet fn not expand macros by default?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-questionCategory: QuestionsI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsS-needs-discussionStatus: Needs further discussion before merging or work can be startedT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions