-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make unused_allocation
lint against Box::new
too
#104363
Conversation
r? @nagisa (rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@rustbot label -T-libs |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7f36882
to
bd5c4f8
Compare
This comment has been minimized.
This comment has been minimized.
This unfortunately may need a full FCP at least. While the lint itself is not new, the way it is expanded in scope is going to be going from affecting approximately no users to affecting a large majority of them. If there is I guess one thing we can do before an FCP is run a crater. Could you make this lint a error-by-default so we can kick-off a run and see how much of the ecosystem actually explodes? |
The FCP makes sense, that's a significant change to the lint. However I don't really see the reasoning for running the crater. Using |
@nagisa making an FCP sounds reasonable, can you start it? I don't think running crater makes sense as this won't affect dependencies (cap-lints) and projects want breakage on new warnings if they deny warnings so it's fine. |
I'll label the issue to signal that an FCP is needed (hope I'm using the correct incantation). @rustbot label -S-waiting-on-review S-waiting-on-team needs-fcp |
The changes of this PR are documented in the main post. TLDR: we're making a lint smarter, which means it will trigger on code it previously did not trigger on. @rfcbot merge |
Team member @oli-obk has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I have done the same thing that this PR is doing in #97774 , but eventually closed it, due to the lint suggesting But in retrospect, this seems like a papercut to me: the lint does not emit any rustfixable suggestions or anything. I think this PR is good because it makes the lint less specific to box syntax, so 👍 from me. |
ping @nikomatsakis @pnkfelix @wesleywiser :) |
assert!(a.downcast::<Box<Test>>().is_err()); | ||
assert!(b.downcast::<Box<i32>>().is_err()); | ||
assert!(a.downcast::<Box<i32>>().is_err()); | ||
assert!(b.downcast::<Box<Test>>().is_err()); |
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.
It took me a fair amount of squinting before I realized why this change was an improvement to the test. :)
3a6ac2a
to
7f5338a
Compare
@Nilstrieb I'm not sure what you mean... I've already done this... |
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.
r=me after the FCP is complete and the test is changed
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
@bors r=Nilstrieb |
…rieb Make `unused_allocation` lint against `Box::new` too Previously it only linted against `box` syntax, which likely won't ever be stabilized, which is pretty useless. Even now I'm not sure if it's a meaningful lint, but it's at least something 🤷 This means that code like the following will be linted against: ```rust Box::new([1, 2, 3]).len(); f(&Box::new(1)); // where f : &i32 -> () ``` The lint works by checking if a `Box::new` (or `box`) expression has an a borrow adjustment, meaning that the code that first stores the box in a variable won't be linted against: ```rust let boxed = Box::new([1, 2, 3]); // no lint boxed.len(); ```
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104363 (Make `unused_allocation` lint against `Box::new` too) - rust-lang#106633 (Stabilize `nonzero_min_max`) - rust-lang#106844 (allow negative numeric literals in `concat!`) - rust-lang#108071 (Implement goal caching with the new solver) - rust-lang#108542 (Force parentheses around `match` expression in binary expression) - rust-lang#108690 (Place size limits on query keys and values) - rust-lang#108708 (Prevent overflow through Arc::downgrade) - rust-lang#108739 (Prevent the `start_bx` basic block in codegen from having two `Builder`s at the same time) - rust-lang#108806 (Querify register_tools and post-expansion early lints) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Always set `RUSTC_BOOTSTRAP` with `x doc` Fixes rust-lang#100060 Note that there is still a warning - the `unused_allocation` lint does not fire in stage 0, but that's just a matter of waiting for rust-lang#104363 to land in beta
Pkgsrc changes: * Adjust patches and cargo checksums to new versions. * Adjust to not cross-build to 8.0, due to LLVM using c++17, so adjust USE_LANGUAGES. Upstream changes: Version 1.70.0 (2023-06-01) ========================== Language -------- - [Relax ordering rules for `asm!` operands] (rust-lang/rust#105798) - [Properly allow macro expanded `format_args` invocations to uses captures] (rust-lang/rust#106505) - [Lint ambiguous glob re-exports] (rust-lang/rust#107880) - [Perform const and unsafe checking for expressions in `let _ = expr` position.] (rust-lang/rust#102256) Compiler -------- - [Extend -Cdebuginfo with new options and named aliases] (rust-lang/rust#109808) This provides a smaller version of debuginfo for cases that only need line number information (`-Cdebuginfo=line-tables-only`), which may eventually become the default for `-Cdebuginfo=1`. - [Make `unused_allocation` lint against `Box::new` too] (rust-lang/rust#104363) - [Detect uninhabited types early in const eval] (rust-lang/rust#109435) - [Switch to LLD as default linker for {arm,thumb}v4t-none-eabi] (rust-lang/rust#109721) - [Add tier 3 target `loongarch64-unknown-linux-gnu`] (rust-lang/rust#96971) - [Add tier 3 target for `i586-pc-nto-qnx700` (QNX Neutrino RTOS, version 7.0)] (rust-lang/rust#109173), - [Insert alignment checks for pointer dereferences as debug assertions] (rust-lang/rust#98112) This catches undefined behavior at runtime, and may cause existing code to fail. Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document NonZeroXxx layout guarantees] (rust-lang/rust#94786) - [Windows: make `Command` prefer non-verbatim paths] (rust-lang/rust#96391) - [Implement Default for some alloc/core iterators] (rust-lang/rust#99929) - [Fix handling of trailing bare CR in str::lines] (rust-lang/rust#100311) - [allow negative numeric literals in `concat!`] (rust-lang/rust#106844) - [Add documentation about the memory layout of `Cell`] (rust-lang/rust#106921) - [Use `partial_cmp` to implement tuple `lt`/`le`/`ge`/`gt`] (rust-lang/rust#108157) - [Stabilize `atomic_as_ptr`] (rust-lang/rust#108419) - [Stabilize `nonnull_slice_from_raw_parts`] (rust-lang/rust#97506) - [Partial stabilization of `once_cell`] (rust-lang/rust#105587) - [Stabilize `nonzero_min_max`] (rust-lang/rust#106633) - [Flatten/inline format_args!() and (string and int) literal arguments into format_args!()] (rust-lang/rust#106824) - [Stabilize movbe target feature] (rust-lang/rust#107711) - [don't splice from files into pipes in io::copy] (rust-lang/rust#108283) - [Add a builtin unstable `FnPtr` trait that is implemented for all function pointers] (rust-lang/rust#108080) This extends `Debug`, `Pointer`, `Hash`, `PartialEq`, `Eq`, `PartialOrd`, and `Ord` implementations for function pointers with all ABIs. Stabilized APIs --------------- - [`NonZero*::MIN/MAX`] (https://doc.rust-lang.org/stable/std/num/struct.NonZeroI8.html#associatedconstant.MIN) - [`BinaryHeap::retain`] (https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html#method.retain) - [`Default for std::collections::binary_heap::IntoIter`] (https://doc.rust-lang.org/stable/std/collections/binary_heap/struct.IntoIter.html) - [`Default for std::collections::btree_map::{IntoIter, Iter, IterMut}`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.IntoIter.html) - [`Default for std::collections::btree_map::{IntoKeys, Keys}`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.IntoKeys.html) - [`Default for std::collections::btree_map::{IntoValues, Values}`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.IntoKeys.html) - [`Default for std::collections::btree_map::Range`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.Range.html) - [`Default for std::collections::btree_set::{IntoIter, Iter}`] (https://doc.rust-lang.org/stable/std/collections/btree_set/struct.IntoIter.html) - [`Default for std::collections::btree_set::Range`] (https://doc.rust-lang.org/stable/std/collections/btree_set/struct.Range.html) - [`Default for std::collections::linked_list::{IntoIter, Iter, IterMut}`] (https://doc.rust-lang.org/stable/alloc/collections/linked_list/struct.IntoIter.html) - [`Default for std::vec::IntoIter`] (https://doc.rust-lang.org/stable/alloc/vec/struct.IntoIter.html#impl-Default-for-IntoIter%3CT,+A%3E) - [`Default for std::iter::Chain`] (https://doc.rust-lang.org/stable/std/iter/struct.Chain.html) - [`Default for std::iter::Cloned`] (https://doc.rust-lang.org/stable/std/iter/struct.Cloned.html) - [`Default for std::iter::Copied`] (https://doc.rust-lang.org/stable/std/iter/struct.Copied.html) - [`Default for std::iter::Enumerate`] (https://doc.rust-lang.org/stable/std/iter/struct.Enumerate.html) - [`Default for std::iter::Flatten`] (https://doc.rust-lang.org/stable/std/iter/struct.Flatten.html) - [`Default for std::iter::Fuse`] (https://doc.rust-lang.org/stable/std/iter/struct.Fuse.html) - [`Default for std::iter::Rev`] (https://doc.rust-lang.org/stable/std/iter/struct.Rev.html) - [`Default for std::slice::Iter`] (https://doc.rust-lang.org/stable/std/slice/struct.Iter.html) - [`Default for std::slice::IterMut`] (https://doc.rust-lang.org/stable/std/slice/struct.IterMut.html) - [`Rc::into_inner`] (https://doc.rust-lang.org/stable/alloc/rc/struct.Rc.html#method.into_inner) - [`Arc::into_inner`] (https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html#method.into_inner) - [`std::cell::OnceCell`] (https://doc.rust-lang.org/stable/std/cell/struct.OnceCell.html) - [`Option::is_some_and`] (https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.is_some_and) - [`NonNull::slice_from_raw_parts`] (https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.slice_from_raw_parts) - [`Result::is_ok_and`] (https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.is_ok_and) - [`Result::is_err_and`] (https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.is_err_and) - [`std::sync::atomic::Atomic*::as_ptr`] (https://doc.rust-lang.org/stable/std/sync/atomic/struct.AtomicU8.html#method.as_ptr) - [`std::io::IsTerminal`] (https://doc.rust-lang.org/stable/std/io/trait.IsTerminal.html) - [`std::os::linux::net::SocketAddrExt`] (https://doc.rust-lang.org/stable/std/os/linux/net/trait.SocketAddrExt.html) - [`std::os::unix::net::UnixDatagram::bind_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixDatagram.html#method.bind_addr) - [`std::os::unix::net::UnixDatagram::connect_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixDatagram.html#method.connect_addr) - [`std::os::unix::net::UnixDatagram::send_to_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixDatagram.html#method.send_to_addr) - [`std::os::unix::net::UnixListener::bind_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixListener.html#method.bind_addr) - [`std::path::Path::as_mut_os_str`] (https://doc.rust-lang.org/stable/std/path/struct.Path.html#method.as_mut_os_str) - [`std::sync::OnceLock`] (https://doc.rust-lang.org/stable/std/sync/struct.OnceLock.html) Cargo ----- - [Add `CARGO_PKG_README`] (rust-lang/cargo#11645) - [Make `sparse` the default protocol for crates.io] (rust-lang/cargo#11791) - [Accurately show status when downgrading dependencies] (rust-lang/cargo#11839) - [Use registry.default for login/logout] (rust-lang/cargo#11949) - [Stabilize `cargo logout`] (rust-lang/cargo#11950) Misc ---- - [Stabilize rustdoc `--test-run-directory`] (rust-lang/rust#103682) Compatibility Notes ------------------- - [Prevent stable `libtest` from supporting `-Zunstable-options`] (rust-lang/rust#109044) - [Perform const and unsafe checking for expressions in `let _ = expr` position.] (rust-lang/rust#102256) - [WebAssembly targets enable `sign-ext` and `mutable-globals` features in codegen] (rust-lang/rust#109807) This may cause incompatibility with older execution environments. - [Insert alignment checks for pointer dereferences as debug assertions] (rust-lang/rust#98112) This catches undefined behavior at runtime, and may cause existing code to fail. Internal Changes ---------------- These changes do not affect any public interfaces of Rust, but they represent significant improvements to the performance or internals of rustc and related tools. - [Upgrade to LLVM 16] (rust-lang/rust#109474) - [Use SipHash-1-3 instead of SipHash-2-4 for StableHasher] (rust-lang/rust#107925)
Pkgsrc changes: * Adjust patches and cargo checksums to new versions. * Add support for NetBSD/riscv64. Upstream changes: Version 1.70.0 (2023-06-01) ========================== Language -------- - [Relax ordering rules for `asm!` operands] (rust-lang/rust#105798) - [Properly allow macro expanded `format_args` invocations to uses captures] (rust-lang/rust#106505) - [Lint ambiguous glob re-exports] (rust-lang/rust#107880) - [Perform const and unsafe checking for expressions in `let _ = expr` position.] (rust-lang/rust#102256) Compiler -------- - [Extend -Cdebuginfo with new options and named aliases] (rust-lang/rust#109808) This provides a smaller version of debuginfo for cases that only need line number information (`-Cdebuginfo=line-tables-only`), which may eventually become the default for `-Cdebuginfo=1`. - [Make `unused_allocation` lint against `Box::new` too] (rust-lang/rust#104363) - [Detect uninhabited types early in const eval] (rust-lang/rust#109435) - [Switch to LLD as default linker for {arm,thumb}v4t-none-eabi] (rust-lang/rust#109721) - [Add tier 3 target `loongarch64-unknown-linux-gnu`] (rust-lang/rust#96971) - [Add tier 3 target for `i586-pc-nto-qnx700`(QNX Neutrino RTOS, version 7.0)] (rust-lang/rust#109173), - [Insert alignment checks for pointer dereferences as debug assertions] (rust-lang/rust#98112) This catches undefined behavior at runtime, and may cause existing code to fail. Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document NonZeroXxx layout guarantees] (rust-lang/rust#94786) - [Windows: make `Command` prefer non-verbatim paths] (rust-lang/rust#96391) - [Implement Default for some alloc/core iterators] (rust-lang/rust#99929) - [Fix handling of trailing bare CR in str::lines] (rust-lang/rust#100311) - [allow negative numeric literals in `concat!`] (rust-lang/rust#106844) - [Add documentation about the memory layout of `Cell`] (rust-lang/rust#106921) - [Use `partial_cmp` to implement tuple `lt`/`le`/`ge`/`gt`] (rust-lang/rust#108157) - [Stabilize `atomic_as_ptr`] (rust-lang/rust#108419) - [Stabilize `nonnull_slice_from_raw_parts`] (rust-lang/rust#97506) - [Partial stabilization of `once_cell`] (rust-lang/rust#105587) - [Stabilize `nonzero_min_max`] (rust-lang/rust#106633) - [Flatten/inline format_args!() and (string and int) literal arguments into format_args!()] (rust-lang/rust#106824) - [Stabilize movbe target feature] (rust-lang/rust#107711) - [don't splice from files into pipes in io::copy] (rust-lang/rust#108283) - [Add a builtin unstable `FnPtr` trait that is implemented for all function pointers] (rust-lang/rust#108080) This extends `Debug`, `Pointer`, `Hash`, `PartialEq`, `Eq`, `PartialOrd`, and `Ord` implementations for function pointers with all ABIs. Stabilized APIs --------------- - [`NonZero*::MIN/MAX`] (https://doc.rust-lang.org/stable/std/num/struct.NonZeroI8.html#associatedconstant.MIN) - [`BinaryHeap::retain`] (https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html#method.retain) - [`Default for std::collections::binary_heap::IntoIter`] (https://doc.rust-lang.org/stable/std/collections/binary_heap/struct.IntoIter.html) - [`Default for std::collections::btree_map::{IntoIter, Iter, IterMut}`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.IntoIter.html) - [`Default for std::collections::btree_map::{IntoKeys, Keys}`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.IntoKeys.html) - [`Default for std::collections::btree_map::{IntoValues, Values}`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.IntoKeys.html) - [`Default for std::collections::btree_map::Range`] (https://doc.rust-lang.org/stable/std/collections/btree_map/struct.Range.html) - [`Default for std::collections::btree_set::{IntoIter, Iter}`] (https://doc.rust-lang.org/stable/std/collections/btree_set/struct.IntoIter.html) - [`Default for std::collections::btree_set::Range`] (https://doc.rust-lang.org/stable/std/collections/btree_set/struct.Range.html) - [`Default for std::collections::linked_list::{IntoIter, Iter, IterMut}`] (https://doc.rust-lang.org/stable/alloc/collections/linked_list/struct.IntoIter.html) - [`Default for std::vec::IntoIter`] (https://doc.rust-lang.org/stable/alloc/vec/struct.IntoIter.html#impl-Default-for-IntoIter%3CT,+A%3E) - [`Default for std::iter::Chain`] (https://doc.rust-lang.org/stable/std/iter/struct.Chain.html) - [`Default for std::iter::Cloned`] (https://doc.rust-lang.org/stable/std/iter/struct.Cloned.html) - [`Default for std::iter::Copied`] (https://doc.rust-lang.org/stable/std/iter/struct.Copied.html) - [`Default for std::iter::Enumerate`] (https://doc.rust-lang.org/stable/std/iter/struct.Enumerate.html) - [`Default for std::iter::Flatten`] (https://doc.rust-lang.org/stable/std/iter/struct.Flatten.html) - [`Default for std::iter::Fuse`] (https://doc.rust-lang.org/stable/std/iter/struct.Fuse.html) - [`Default for std::iter::Rev`] (https://doc.rust-lang.org/stable/std/iter/struct.Rev.html) - [`Default for std::slice::Iter`] (https://doc.rust-lang.org/stable/std/slice/struct.Iter.html) - [`Default for std::slice::IterMut`] (https://doc.rust-lang.org/stable/std/slice/struct.IterMut.html) - [`Rc::into_inner`] (https://doc.rust-lang.org/stable/alloc/rc/struct.Rc.html#method.into_inner) - [`Arc::into_inner`] (https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html#method.into_inner) - [`std::cell::OnceCell`] (https://doc.rust-lang.org/stable/std/cell/struct.OnceCell.html) - [`Option::is_some_and`] (https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.is_some_and) - [`NonNull::slice_from_raw_parts`] (https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.slice_from_raw_parts) - [`Result::is_ok_and`] (https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.is_ok_and) - [`Result::is_err_and`] (https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.is_err_and) - [`std::sync::atomic::Atomic*::as_ptr`] (https://doc.rust-lang.org/stable/std/sync/atomic/struct.AtomicU8.html#method.as_ptr) - [`std::io::IsTerminal`] (https://doc.rust-lang.org/stable/std/io/trait.IsTerminal.html) - [`std::os::linux::net::SocketAddrExt`] (https://doc.rust-lang.org/stable/std/os/linux/net/trait.SocketAddrExt.html) - [`std::os::unix::net::UnixDatagram::bind_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixDatagram.html#method.bind_addr) - [`std::os::unix::net::UnixDatagram::connect_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixDatagram.html#method.connect_addr) - [`std::os::unix::net::UnixDatagram::send_to_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixDatagram.html#method.send_to_addr) - [`std::os::unix::net::UnixListener::bind_addr`] (https://doc.rust-lang.org/stable/std/os/unix/net/struct.UnixListener.html#method.bind_addr) - [`std::path::Path::as_mut_os_str`] (https://doc.rust-lang.org/stable/std/path/struct.Path.html#method.as_mut_os_str) - [`std::sync::OnceLock`] (https://doc.rust-lang.org/stable/std/sync/struct.OnceLock.html) Cargo ----- - [Add `CARGO_PKG_README`] (rust-lang/cargo#11645) - [Make `sparse` the default protocol for crates.io] (rust-lang/cargo#11791) - [Accurately show status when downgrading dependencies] (rust-lang/cargo#11839) - [Use registry.default for login/logout] (rust-lang/cargo#11949) - [Stabilize `cargo logout`] (rust-lang/cargo#11950) Misc ---- - [Stabilize rustdoc `--test-run-directory`] (rust-lang/rust#103682) Compatibility Notes ------------------- - [Prevent stable `libtest` from supporting `-Zunstable-options`] (rust-lang/rust#109044) - [Perform const and unsafe checking for expressions in `let _ = expr` position.] (rust-lang/rust#102256) - [WebAssembly targets enable `sign-ext` and `mutable-globals` features in codegen] (rust-lang/rust#109807) This may cause incompatibility with older execution environments. - [Insert alignment checks for pointer dereferences as debug assertions] (rust-lang/rust#98112) This catches undefined behavior at runtime, and may cause existing code to fail. Internal Changes ---------------- These changes do not affect any public interfaces of Rust, but they represent significant improvements to the performance or internals of rustc and related tools. - [Upgrade to LLVM 16] (rust-lang/rust#109474) - [Use SipHash-1-3 instead of SipHash-2-4 for StableHasher] (rust-lang/rust#107925)
Previously it only linted against
box
syntax, which likely won't ever be stabilized, which is pretty useless. Even now I'm not sure if it's a meaningful lint, but it's at least something 🤷This means that code like the following will be linted against:
The lint works by checking if a
Box::new
(orbox
) expression has an a borrow adjustment, meaning that the code that first stores the box in a variable won't be linted against: