Skip to content

Commit ddeac29

Browse files
committed
Rename default_box_assignments to replace_box
1 parent 78a53c2 commit ddeac29

File tree

7 files changed

+296
-295
lines changed

7 files changed

+296
-295
lines changed

CHANGELOG.md

Lines changed: 265 additions & 264 deletions
Large diffs are not rendered by default.

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
9090
crate::dbg_macro::DBG_MACRO_INFO,
9191
crate::default::DEFAULT_TRAIT_ACCESS_INFO,
9292
crate::default::FIELD_REASSIGN_WITH_DEFAULT_INFO,
93-
crate::default_box_assignments::DEFAULT_BOX_ASSIGNMENTS_INFO,
93+
crate::replace_box::REPLACE_BOX_INFO,
9494
crate::default_constructed_unit_structs::DEFAULT_CONSTRUCTED_UNIT_STRUCTS_INFO,
9595
crate::default_instead_of_iter_empty::DEFAULT_INSTEAD_OF_ITER_EMPTY_INFO,
9696
crate::default_numeric_fallback::DEFAULT_NUMERIC_FALLBACK_INFO,

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ mod crate_in_macro_def;
104104
mod create_dir;
105105
mod dbg_macro;
106106
mod default;
107-
mod default_box_assignments;
108107
mod default_constructed_unit_structs;
109108
mod default_instead_of_iter_empty;
110109
mod default_numeric_fallback;
@@ -324,6 +323,7 @@ mod ref_patterns;
324323
mod reference;
325324
mod regex;
326325
mod repeat_vec_with_capacity;
326+
mod replace_box;
327327
mod reserve_after_initialization;
328328
mod return_self_not_must_use;
329329
mod returns;
@@ -833,6 +833,6 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
833833
store.register_late_pass(|_| Box::new(coerce_container_to_any::CoerceContainerToAny));
834834
store.register_late_pass(|_| Box::new(toplevel_ref_arg::ToplevelRefArg));
835835
store.register_late_pass(|_| Box::new(volatile_composites::VolatileComposites));
836-
store.register_late_pass(|_| Box::new(default_box_assignments::DefaultBoxAssignments));
836+
store.register_late_pass(|_| Box::new(replace_box::ReplaceBox));
837837
// add lints here, do not remove this comment, it's used in `new_lint`
838838
}

clippy_lints/src/default_box_assignments.rs renamed to clippy_lints/src/replace_box.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ declare_clippy_lint! {
2828
/// let mut b = Box::new(1u32);
2929
/// *b = Default::default();
3030
/// ```
31-
#[clippy::version = "1.89.0"]
32-
pub DEFAULT_BOX_ASSIGNMENTS,
31+
#[clippy::version = "1.92.0"]
32+
pub REPLACE_BOX,
3333
perf,
3434
"assigning a newly created box to `Box<T>` is inefficient"
3535
}
36-
declare_lint_pass!(DefaultBoxAssignments => [DEFAULT_BOX_ASSIGNMENTS]);
36+
declare_lint_pass!(ReplaceBox => [REPLACE_BOX]);
3737

38-
impl LateLintPass<'_> for DefaultBoxAssignments {
38+
impl LateLintPass<'_> for ReplaceBox {
3939
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
4040
if let ExprKind::Assign(lhs, rhs, _) = &expr.kind
4141
&& !lhs.span.from_expansion()
@@ -60,7 +60,7 @@ impl LateLintPass<'_> for DefaultBoxAssignments {
6060
{
6161
span_lint_and_then(
6262
cx,
63-
DEFAULT_BOX_ASSIGNMENTS,
63+
REPLACE_BOX,
6464
expr.span,
6565
"creating a new box with default content",
6666
|diag| {
@@ -83,7 +83,7 @@ impl LateLintPass<'_> for DefaultBoxAssignments {
8383
if inner_ty.is_sized(cx.tcx, cx.typing_env())
8484
&& let Some(rhs_inner) = get_box_new_payload(cx, rhs)
8585
{
86-
span_lint_and_then(cx, DEFAULT_BOX_ASSIGNMENTS, expr.span, "creating a new box", |diag| {
86+
span_lint_and_then(cx, REPLACE_BOX, expr.span, "creating a new box", |diag| {
8787
let mut app = Applicability::MachineApplicable;
8888
let suggestion = format!(
8989
"{} = {}",

tests/ui/default_box_assignments.fixed renamed to tests/ui/replace_box.fixed

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#![warn(clippy::default_box_assignments)]
1+
#![warn(clippy::replace_box)]
22

33
fn with_default<T: Default>(b: &mut Box<T>) {
44
**b = T::default();
5-
//~^ default_box_assignments
5+
//~^ replace_box
66
}
77

88
fn with_sized<T>(b: &mut Box<T>, t: T) {
99
**b = t;
10-
//~^ default_box_assignments
10+
//~^ replace_box
1111
}
1212

1313
fn with_unsized<const N: usize>(b: &mut Box<[u32]>) {
@@ -42,9 +42,9 @@ macro_rules! mac {
4242
fn main() {
4343
let mut b = Box::new(1u32);
4444
*b = Default::default();
45-
//~^ default_box_assignments
45+
//~^ replace_box
4646
*b = Default::default();
47-
//~^ default_box_assignments
47+
//~^ replace_box
4848

4949
// No lint for assigning to the storage
5050
*b = Default::default();
@@ -56,10 +56,10 @@ fn main() {
5656
same!(b) = Default::default();
5757

5858
*b = 5;
59-
//~^ default_box_assignments
59+
//~^ replace_box
6060

6161
*b = mac!(three);
62-
//~^ default_box_assignments
62+
//~^ replace_box
6363

6464
// No lint for assigning to Box<T> where T: !Default
6565
let mut b = Box::<str>::from("hi".to_string());

tests/ui/default_box_assignments.rs renamed to tests/ui/replace_box.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#![warn(clippy::default_box_assignments)]
1+
#![warn(clippy::replace_box)]
22

33
fn with_default<T: Default>(b: &mut Box<T>) {
44
*b = Box::new(T::default());
5-
//~^ default_box_assignments
5+
//~^ replace_box
66
}
77

88
fn with_sized<T>(b: &mut Box<T>, t: T) {
99
*b = Box::new(t);
10-
//~^ default_box_assignments
10+
//~^ replace_box
1111
}
1212

1313
fn with_unsized<const N: usize>(b: &mut Box<[u32]>) {
@@ -42,9 +42,9 @@ macro_rules! mac {
4242
fn main() {
4343
let mut b = Box::new(1u32);
4444
b = Default::default();
45-
//~^ default_box_assignments
45+
//~^ replace_box
4646
b = Box::default();
47-
//~^ default_box_assignments
47+
//~^ replace_box
4848

4949
// No lint for assigning to the storage
5050
*b = Default::default();
@@ -56,10 +56,10 @@ fn main() {
5656
same!(b) = Default::default();
5757

5858
b = Box::new(5);
59-
//~^ default_box_assignments
59+
//~^ replace_box
6060

6161
b = Box::new(mac!(three));
62-
//~^ default_box_assignments
62+
//~^ replace_box
6363

6464
// No lint for assigning to Box<T> where T: !Default
6565
let mut b = Box::<str>::from("hi".to_string());

tests/ui/default_box_assignments.stderr renamed to tests/ui/replace_box.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
error: creating a new box
2-
--> tests/ui/default_box_assignments.rs:4:5
2+
--> tests/ui/replace_box.rs:4:5
33
|
44
LL | *b = Box::new(T::default());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace existing content with inner value instead: `**b = T::default()`
66
|
77
= note: this creates a needless allocation
8-
= note: `-D clippy::default-box-assignments` implied by `-D warnings`
9-
= help: to override `-D warnings` add `#[allow(clippy::default_box_assignments)]`
8+
= note: `-D clippy::replace-box` implied by `-D warnings`
9+
= help: to override `-D warnings` add `#[allow(clippy::replace_box)]`
1010

1111
error: creating a new box
12-
--> tests/ui/default_box_assignments.rs:9:5
12+
--> tests/ui/replace_box.rs:9:5
1313
|
1414
LL | *b = Box::new(t);
1515
| ^^^^^^^^^^^^^^^^ help: replace existing content with inner value instead: `**b = t`
1616
|
1717
= note: this creates a needless allocation
1818

1919
error: creating a new box with default content
20-
--> tests/ui/default_box_assignments.rs:44:5
20+
--> tests/ui/replace_box.rs:44:5
2121
|
2222
LL | b = Default::default();
2323
| ^^^^^^^^^^^^^^^^^^^^^^ help: replace existing content with default instead: `*b = Default::default()`
2424
|
2525
= note: this creates a needless allocation
2626

2727
error: creating a new box with default content
28-
--> tests/ui/default_box_assignments.rs:46:5
28+
--> tests/ui/replace_box.rs:46:5
2929
|
3030
LL | b = Box::default();
3131
| ^^^^^^^^^^^^^^^^^^ help: replace existing content with default instead: `*b = Default::default()`
3232
|
3333
= note: this creates a needless allocation
3434

3535
error: creating a new box
36-
--> tests/ui/default_box_assignments.rs:58:5
36+
--> tests/ui/replace_box.rs:58:5
3737
|
3838
LL | b = Box::new(5);
3939
| ^^^^^^^^^^^^^^^ help: replace existing content with inner value instead: `*b = 5`
4040
|
4141
= note: this creates a needless allocation
4242

4343
error: creating a new box
44-
--> tests/ui/default_box_assignments.rs:61:5
44+
--> tests/ui/replace_box.rs:61:5
4545
|
4646
LL | b = Box::new(mac!(three));
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace existing content with inner value instead: `*b = mac!(three)`

0 commit comments

Comments
 (0)