-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-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 appliedgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
Defining a function that has a &mut Box<[T]>
parameter triggers the borrowed_box
lint, recommending it be replaced with a &mut [T]
. It's possible to have a function that replaces the boxed slice with a different allocation (e.g. a slice with a different size), which cannot be done if the parameter is just a slice reference.
Example:
pub fn maybe_sets_box(boxed_slice: &mut Box<[i32]>) {
if boxed_slice.is_empty() {
let mut data = Vec::with_capacity(1);
data.push(12);
*boxed_slice = data.into_boxed_slice();
}
}
EFanZh, aspurdy, programmerjake, inikulin and jmaargh
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-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 appliedgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
EFanZh commentedon Sep 14, 2019
I think Clippy should allow the usage of
&mut Box<T>
but disallow the usage of&Box<T>
since we might want to change the box pointer instead of the object it points to.jmaargh commentedon Mar 20, 2020
A (perhaps a little contrived) example: https://godbolt.org/z/LFRvd7
Fix issue rust-lang#2907.
Fix issue rust-lang#2907.
Auto merge of #5491 - smklein:borrowed_box, r=flip1995
Auto merge of #5491 - smklein:borrowed_box, r=flip1995
submodules: update clippy from 891e1a8 to b7c802b
ebroto commentedon May 15, 2020
I think this issue can be closed given that #5491 was merged