-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-questionCategory: QuestionsCategory: QuestionsI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestionsS-needs-discussionStatus: Needs further discussion before merging or work can be startedStatus: Needs further discussion before merging or work can be startedT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansion
Description
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
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-questionCategory: QuestionsCategory: QuestionsI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestionsS-needs-discussionStatus: Needs further discussion before merging or work can be startedStatus: Needs further discussion before merging or work can be startedT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansion
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
camsteffen commentedon Mar 5, 2021
What you're really suggesting is to always use
span.source_callsite()
instead ofspan
by default. I think this would work for 98% of cases. The problem is when we are linting code likeNow, I think some of our lints are over-conservative and just drop out at
fooey!(x)
. But there's no reason not to lint this code withredudant_closure
. If you takespan.source_callsite()
fromfoo(y)
, I think you would getfooey!(x)
which is not what you want. But I haven't confirmed this.I don't like util methods like
snippet_with_macro_callsite
which is just a layer of obfuscation overspan.source_callsite()
, but that's a different issue.camsteffen commentedon Mar 5, 2021
Actually I take that back since
foo(y)
may include an implicit deref depending on what is passed to the macro. But maybe ifx
did not originate outside the macro? I don't know, macros are sticky. But I think my main point still holds.or_then_unwrap
: suggestion preserves macro calls #15483fix `or_then_unwrap`: suggestion preserves macro calls (#15483)