-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[WIP] Also lint Box::new in unused_allocation #97774
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
610c923
to
7b94b07
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4423499
to
009228c
Compare
I'm wondering about the last commit, which changed Fundamentally the issue already exists, with & being suggested for
But that affects a nightly feature so it does not need to be as polished. I wonder if the lint needs further improvements before it can be extended to Especially I wonder: a) does the |
@@ -273,6 +273,7 @@ language_item_table! { | |||
EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None; | |||
|
|||
OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1); | |||
OwnedBoxNew, sym::owned_box_new, owned_box_new, Target::Method(MethodKind::Inherent), GenericRequirement::None; |
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.
Making it a diagnostic item instead of a lang item would be preferable in this case.
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've been planning, as a followup to this PR, to also use this for the #[rustc_box]
feature. Right now, #[rustc_box] foobar(foo)
is lowered to box foo
, irrespective of what foobar
is, even if it isn't Box::new
. In order to make it error if it's not Box::new
, I would be needing something that gives me a def id i suppose. Is a diagnostic item a good choice for such an error as well?
To explain, in a box_syntax
free world, some users might still want to use #[rustc_box]
over Box::new
and they should get a more polished feature.
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.
Right now,
#[rustc_box] foobar(foo)
is lowered tobox foo
, irrespective of whatfoobar
is, even if it isn'tBox::new
.
Which seems fine to me, given that #[rustc_box]
is an internal feature that is supposed to be removed in the future.
free world, some users might still want to use
#[rustc_box]
overBox::new
and they should get a more polished feature.
If it's supposed to be used by people and be polished, then perhaps it needs a better syntax than #[rustc_box] Box::new(expr)
, for example box expr
, oh wait.
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 didn't follow the story behind #97293 but the state in which you need to write #[rustc_box] Box::new(expr)
instead of just Box::new(expr)
or box expr
(*) seems like the worse from both worlds.
(*) Preferably the former, because whatever made Box::new(expr)
slow in #97293 can also make other much more common things like Vec::from()
/String::from()
slow, so it may be a good win if it's fixed.
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.
Box::new(foo)
is not slow in most of cases, thanks to LLVM being really good, especially post version 12 (minimum LLVM is 12 now). The issue is just that switching vec![]
to Box::new
would also switch it for the remaining few cases where it does cause regressions. For these, the PR added #[rustc_box]
as an alternative to box foo
. My ultimate goal is to remove box foo
support from the compiler, this PR is another preparation of it. Eventually this will need a lang team FCP and a "go forward" from them. Anyways, the general future of box
syntax is not discussed here but in the tracking issue (still need to make a proposal there).
It might be better if instead of doing empty promises, I add the lang item in a separate PR first that actually needs it, and then switch this PR to it.
No opinion on this, for that you can try finding some other reviewer who cares more about this case. |
009228c
to
9500150
Compare
I've marked this as WIP because of: #97774 (comment) Ideally I'd convert this into a hard error (temporarily for the experiment), run a crater run, and then see what the lint complains about and how many of those cases are not beautiful complaints. |
☔ The latest upstream changes (presumably #98673) made this pull request unmergeable. Please resolve the merge conflicts. |
Previously, only (box foo).something() would be linted, wher something takes &self or &mut self. Now, we also lint for Box::new(foo).something().
Before the unused_allocation lint has never been tested outside of its lint documentation.
9500150
to
e94a9db
Compare
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #101986) made this pull request unmergeable. Please resolve the merge conflicts. |
Previously, only
box
syntax uses would yield in theunused_allocation
lint issuing warnings. Now, equivalent unnecessary usage ofBox::new
also gives a warning. Furthermore, this PR adds a test of theunused_allocation
lint which was previously never tested anywhere in the test suite.With the changes from this pr, this snippet
gives
Just like how it lints for the equivalent snippet just with
box
instead ofBox::new
.