-
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
add box-default
lint
#9511
add box-default
lint
#9511
Conversation
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
r? @Alexendoo (as giraffate seems to be busy at the moment) |
/// The lint may miss some cases (e.g. Box::new(String::from(""))). | ||
/// On the other hand, it will trigger on cases where the `default` | ||
/// code comes from a macro that does something different based on | ||
/// e.g. target operating system. |
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.
Could add a check for expr.span.ctxt() == arg.span.ctxt()
to avoid linting across macro boundaries while still catching it in local macro definitions
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.
Good idea. Done.
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.
Can remove the macro note from Known problems
with that unless there's a case I'm missing
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 maybe things like Box::new(cfg_if! ... { String::new() } else { ... })
where the expressions aren't coming from the macro
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.
Exactly. Though if you want, I can remove the note until I find a clearer wording.
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'd say remove it, apparently you can't use cfg_if
in an expression position, nor #[cfg]
as attributes on expressions are unstable
Got it! r? |
Ahh right the parent of @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This adds a
box-default
lint to suggest usingBox::default()
instead ofBox::new(Default::default())
, which offers less moving parts and potentially better performance according to the perf book.changelog: add [
box_default
] lint