-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
mem_replace_with_default: recognize some std library ctors #6820
mem_replace_with_default: recognize some std library ctors #6820
Conversation
r? @phansch (rust-highfive has picked a reviewer for you, use r? to override) |
clippy_lints/src/mem_replace.rs
Outdated
paths::BTREEMAP_NEW.as_ref(), | ||
paths::HASHSET_NEW.as_ref(), | ||
paths::BTREESET_NEW.as_ref(), | ||
paths::BINARY_HEAP_NEW.as_ref(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paths::BINARY_HEAP_NEW.as_ref(), | |
(sym::BinaryHeap, sym::new), |
All of these types will have diagnostic items after the next sync with rustc so we should probably use those instead of adding more paths. You can use the util function is_diagnostic_assoc_item
instead of match_def_path
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of it, thanks! Makes sense to me to wait then.
I got a question related to this:
- For
Default
trait, won't we needdefault_trait
symbol specified (similar to e.g. debug_trait)? It is not defined for the Default trait. Or maybeDefault
symbol is sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that one needs to be added. Or use the current method for now. The symbol needed just depends on what the diagnostic item is named in #[rustc_diagnostic_item = "name"]
. Personally I like naming it the same as the item like Default
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that the name we need to use comes from #[rustc_diagnostic_item = "name"]
, but by that:
Or maybe
Default
symbol is sufficient?
I meant already defined Default
symbol in symbol.rs. I don't quite understand what it is then (because #[rustc_diagnostic_item="..."
is not defined for the Default
trait)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Symbol
is just an interned string. So if we add #[rustc_diagnostic_item="Default"]
and Default
is already in symbol.rs then we don't need to add to symbol.rs. We also could use sym!(Default)
which expands to Symbol::intern("Default")
. But having sym::Default
is better because it is const. I hope that answers your question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it is more clear, thanks!
Created this PR in rust repo to add diagnostic item to Default
trait.
☔ The latest upstream changes (presumably #6823) made this pull request unmergeable. Please resolve the merge conflicts. |
Marking this as |
Hi @mgacek8, the Rustup landed so the diagnostic item for the Default trait should be available in Clippy now =) |
f95b514
to
41be515
Compare
@bors r+ thanks! |
📌 Commit 41be515 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes #6562
changelog: mem_replace_with_default: recognize some common constructors equivalent to
Default::default()