Skip to content

Commit 24de0be

Browse files
committed
Fix tests
1 parent bc551b9 commit 24de0be

7 files changed

+64
-66
lines changed

clippy_lints/src/assigning_clones.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare_clippy_lint! {
2525
///
2626
/// impl Clone for Thing {
2727
/// fn clone(&self) -> Self { todo!() }
28-
/// fn clone_from(&mut self, other: &Self) -> Self { todo!() }
28+
/// fn clone_from(&mut self, other: &Self) { todo!() }
2929
/// }
3030
///
3131
/// pub fn assign_to_ref(a: &mut Thing, b: Thing) {
@@ -37,7 +37,7 @@ declare_clippy_lint! {
3737
/// struct Thing;
3838
/// impl Clone for Thing {
3939
/// fn clone(&self) -> Self { todo!() }
40-
/// fn clone_from(&mut self, other: &Self) -> Self { todo!() }
40+
/// fn clone_from(&mut self, other: &Self) { todo!() }
4141
/// }
4242
///
4343
/// pub fn assign_to_ref(a: &mut Thing, b: Thing) {
@@ -142,7 +142,7 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC
142142
// TODO: This check currently bails if the local variable has no initializer.
143143
// That is overly conservative - the lint should fire even if there was no initializer,
144144
// but the variable has been initialized before `lhs` was evaluated.
145-
if let Some(Node::Local(local)) = cx.tcx.opt_hir_node(cx.tcx.hir().parent_id(local))
145+
if let Some(Node::Local(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p))
146146
&& local.init.is_none()
147147
{
148148
return false;

tests/ui/assigning_clones.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-rustfix
21
#![allow(unused)]
32
#![allow(clippy::redundant_clone)]
43
#![allow(clippy::ptr_arg)] // https://github.com/rust-lang/rust-clippy/issues/10612

tests/ui/assigning_clones.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-rustfix
21
#![allow(unused)]
32
#![allow(clippy::redundant_clone)]
43
#![allow(clippy::ptr_arg)] // https://github.com/rust-lang/rust-clippy/issues/10612

tests/ui/assigning_clones.stderr

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: assigning the result of `Clone::clone()` may be inefficient
2-
--> $DIR/assigning_clones.rs:25:5
2+
--> tests/ui/assigning_clones.rs:24:5
33
|
44
LL | *mut_thing = value_thing.clone();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(&value_thing)`
@@ -8,97 +8,97 @@ LL | *mut_thing = value_thing.clone();
88
= help: to override `-D warnings` add `#[allow(clippy::assigning_clones)]`
99

1010
error: assigning the result of `Clone::clone()` may be inefficient
11-
--> $DIR/assigning_clones.rs:29:5
11+
--> tests/ui/assigning_clones.rs:28:5
1212
|
1313
LL | *mut_thing = ref_thing.clone();
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing)`
1515

1616
error: assigning the result of `Clone::clone()` may be inefficient
17-
--> $DIR/assigning_clones.rs:33:5
17+
--> tests/ui/assigning_clones.rs:32:5
1818
|
1919
LL | mut_thing = ref_thing.clone();
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing)`
2121

2222
error: assigning the result of `Clone::clone()` may be inefficient
23-
--> $DIR/assigning_clones.rs:37:5
23+
--> tests/ui/assigning_clones.rs:36:5
2424
|
2525
LL | *mut_thing = Clone::clone(ref_thing);
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)`
2727

2828
error: assigning the result of `Clone::clone()` may be inefficient
29-
--> $DIR/assigning_clones.rs:41:5
29+
--> tests/ui/assigning_clones.rs:40:5
3030
|
3131
LL | mut_thing = Clone::clone(ref_thing);
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut mut_thing, ref_thing)`
3333

3434
error: assigning the result of `Clone::clone()` may be inefficient
35-
--> $DIR/assigning_clones.rs:45:5
35+
--> tests/ui/assigning_clones.rs:44:5
3636
|
3737
LL | *mut_thing = Clone::clone(ref_thing);
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)`
3939

4040
error: assigning the result of `Clone::clone()` may be inefficient
41-
--> $DIR/assigning_clones.rs:49:5
41+
--> tests/ui/assigning_clones.rs:48:5
4242
|
4343
LL | *mut_thing = HasCloneFrom::clone(ref_thing);
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)`
4545

4646
error: assigning the result of `Clone::clone()` may be inefficient
47-
--> $DIR/assigning_clones.rs:53:5
47+
--> tests/ui/assigning_clones.rs:52:5
4848
|
4949
LL | *mut_thing = <HasCloneFrom as Clone>::clone(ref_thing);
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)`
5151

5252
error: assigning the result of `Clone::clone()` may be inefficient
53-
--> $DIR/assigning_clones.rs:58:5
53+
--> tests/ui/assigning_clones.rs:57:5
5454
|
5555
LL | *(mut_thing + &mut HasCloneFrom) = ref_thing.clone();
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `(mut_thing + &mut HasCloneFrom).clone_from(ref_thing)`
5757

5858
error: assigning the result of `Clone::clone()` may be inefficient
59-
--> $DIR/assigning_clones.rs:63:5
59+
--> tests/ui/assigning_clones.rs:62:5
6060
|
6161
LL | *mut_thing = (ref_thing + ref_thing).clone();
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing + ref_thing)`
6363

6464
error: assigning the result of `Clone::clone()` may be inefficient
65-
--> $DIR/assigning_clones.rs:69:9
65+
--> tests/ui/assigning_clones.rs:68:9
6666
|
6767
LL | a = b.clone();
6868
| ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
6969

7070
error: assigning the result of `ToOwned::to_owned()` may be inefficient
71-
--> $DIR/assigning_clones.rs:146:5
71+
--> tests/ui/assigning_clones.rs:145:5
7272
|
7373
LL | *mut_string = ref_str.to_owned();
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(mut_string)`
7575

7676
error: assigning the result of `ToOwned::to_owned()` may be inefficient
77-
--> $DIR/assigning_clones.rs:150:5
77+
--> tests/ui/assigning_clones.rs:149:5
7878
|
7979
LL | mut_string = ref_str.to_owned();
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut mut_string)`
8181

8282
error: assigning the result of `ToOwned::to_owned()` may be inefficient
83-
--> $DIR/assigning_clones.rs:171:5
83+
--> tests/ui/assigning_clones.rs:170:5
8484
|
8585
LL | **mut_box_string = ref_str.to_owned();
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
8787

8888
error: assigning the result of `ToOwned::to_owned()` may be inefficient
89-
--> $DIR/assigning_clones.rs:175:5
89+
--> tests/ui/assigning_clones.rs:174:5
9090
|
9191
LL | **mut_box_string = ref_str.to_owned();
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
9393

9494
error: assigning the result of `ToOwned::to_owned()` may be inefficient
95-
--> $DIR/assigning_clones.rs:179:5
95+
--> tests/ui/assigning_clones.rs:178:5
9696
|
9797
LL | *mut_thing = ToOwned::to_owned(ref_str);
9898
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, mut_thing)`
9999

100100
error: assigning the result of `ToOwned::to_owned()` may be inefficient
101-
--> $DIR/assigning_clones.rs:183:5
101+
--> tests/ui/assigning_clones.rs:182:5
102102
|
103103
LL | mut_thing = ToOwned::to_owned(ref_str);
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, &mut mut_thing)`

tests/ui/field_reassign_with_default.stderr

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,133 @@
11
error: field assignment outside of initializer for an instance created with Default::default()
2-
--> tests/ui/field_reassign_with_default.rs:56:5
2+
--> tests/ui/field_reassign_with_default.rs:57:5
33
|
44
LL | a.i = 42;
55
| ^^^^^^^^^
66
|
77
note: consider initializing the variable with `main::A { i: 42, ..Default::default() }` and removing relevant reassignments
8-
--> tests/ui/field_reassign_with_default.rs:55:5
8+
--> tests/ui/field_reassign_with_default.rs:56:5
99
|
1010
LL | let mut a: A = Default::default();
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
1313
= help: to override `-D warnings` add `#[allow(clippy::field_reassign_with_default)]`
1414

1515
error: field assignment outside of initializer for an instance created with Default::default()
16-
--> tests/ui/field_reassign_with_default.rs:96:5
16+
--> tests/ui/field_reassign_with_default.rs:97:5
1717
|
1818
LL | a.j = 43;
1919
| ^^^^^^^^^
2020
|
2121
note: consider initializing the variable with `main::A { j: 43, i: 42 }` and removing relevant reassignments
22-
--> tests/ui/field_reassign_with_default.rs:95:5
22+
--> tests/ui/field_reassign_with_default.rs:96:5
2323
|
2424
LL | let mut a: A = Default::default();
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626

2727
error: field assignment outside of initializer for an instance created with Default::default()
28-
--> tests/ui/field_reassign_with_default.rs:101:5
28+
--> tests/ui/field_reassign_with_default.rs:102:5
2929
|
3030
LL | a.i = 42;
3131
| ^^^^^^^^^
3232
|
3333
note: consider initializing the variable with `main::A { i: 42, j: 44 }` and removing relevant reassignments
34-
--> tests/ui/field_reassign_with_default.rs:100:5
34+
--> tests/ui/field_reassign_with_default.rs:101:5
3535
|
3636
LL | let mut a: A = Default::default();
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838

3939
error: field assignment outside of initializer for an instance created with Default::default()
40-
--> tests/ui/field_reassign_with_default.rs:107:5
40+
--> tests/ui/field_reassign_with_default.rs:108:5
4141
|
4242
LL | a.i = 42;
4343
| ^^^^^^^^^
4444
|
4545
note: consider initializing the variable with `main::A { i: 42, ..Default::default() }` and removing relevant reassignments
46-
--> tests/ui/field_reassign_with_default.rs:106:5
46+
--> tests/ui/field_reassign_with_default.rs:107:5
4747
|
4848
LL | let mut a = A::default();
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5050

5151
error: field assignment outside of initializer for an instance created with Default::default()
52-
--> tests/ui/field_reassign_with_default.rs:117:5
52+
--> tests/ui/field_reassign_with_default.rs:118:5
5353
|
5454
LL | a.i = Default::default();
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5656
|
5757
note: consider initializing the variable with `main::A { i: Default::default(), ..Default::default() }` and removing relevant reassignments
58-
--> tests/ui/field_reassign_with_default.rs:116:5
58+
--> tests/ui/field_reassign_with_default.rs:117:5
5959
|
6060
LL | let mut a: A = Default::default();
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6262

6363
error: field assignment outside of initializer for an instance created with Default::default()
64-
--> tests/ui/field_reassign_with_default.rs:121:5
64+
--> tests/ui/field_reassign_with_default.rs:122:5
6565
|
6666
LL | a.i = Default::default();
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6868
|
6969
note: consider initializing the variable with `main::A { i: Default::default(), j: 45 }` and removing relevant reassignments
70-
--> tests/ui/field_reassign_with_default.rs:120:5
70+
--> tests/ui/field_reassign_with_default.rs:121:5
7171
|
7272
LL | let mut a: A = Default::default();
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7474

7575
error: field assignment outside of initializer for an instance created with Default::default()
76-
--> tests/ui/field_reassign_with_default.rs:143:5
76+
--> tests/ui/field_reassign_with_default.rs:144:5
7777
|
7878
LL | a.i = vec![1];
7979
| ^^^^^^^^^^^^^^
8080
|
8181
note: consider initializing the variable with `C { i: vec![1], ..Default::default() }` and removing relevant reassignments
82-
--> tests/ui/field_reassign_with_default.rs:142:5
82+
--> tests/ui/field_reassign_with_default.rs:143:5
8383
|
8484
LL | let mut a: C = C::default();
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8686

8787
error: field assignment outside of initializer for an instance created with Default::default()
88-
--> tests/ui/field_reassign_with_default.rs:161:5
88+
--> tests/ui/field_reassign_with_default.rs:162:5
8989
|
9090
LL | a.i = true;
9191
| ^^^^^^^^^^^
9292
|
9393
note: consider initializing the variable with `Wrapper::<bool> { i: true }` and removing relevant reassignments
94-
--> tests/ui/field_reassign_with_default.rs:160:5
94+
--> tests/ui/field_reassign_with_default.rs:161:5
9595
|
9696
LL | let mut a: Wrapper<bool> = Default::default();
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9898

9999
error: field assignment outside of initializer for an instance created with Default::default()
100-
--> tests/ui/field_reassign_with_default.rs:164:5
100+
--> tests/ui/field_reassign_with_default.rs:165:5
101101
|
102102
LL | a.i = 42;
103103
| ^^^^^^^^^
104104
|
105105
note: consider initializing the variable with `WrapperMulti::<i32, i64> { i: 42, ..Default::default() }` and removing relevant reassignments
106-
--> tests/ui/field_reassign_with_default.rs:163:5
106+
--> tests/ui/field_reassign_with_default.rs:164:5
107107
|
108108
LL | let mut a: WrapperMulti<i32, i64> = Default::default();
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110110

111111
error: field assignment outside of initializer for an instance created with Default::default()
112-
--> tests/ui/field_reassign_with_default.rs:235:13
112+
--> tests/ui/field_reassign_with_default.rs:236:13
113113
|
114114
LL | f.name = name.len();
115115
| ^^^^^^^^^^^^^^^^^^^^
116116
|
117117
note: consider initializing the variable with `issue6312::ImplDropAllCopy { name: name.len(), ..Default::default() }` and removing relevant reassignments
118-
--> tests/ui/field_reassign_with_default.rs:234:13
118+
--> tests/ui/field_reassign_with_default.rs:235:13
119119
|
120120
LL | let mut f = ImplDropAllCopy::default();
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
122122

123123
error: field assignment outside of initializer for an instance created with Default::default()
124-
--> tests/ui/field_reassign_with_default.rs:251:13
124+
--> tests/ui/field_reassign_with_default.rs:252:13
125125
|
126126
LL | f.name = name.len();
127127
| ^^^^^^^^^^^^^^^^^^^^
128128
|
129129
note: consider initializing the variable with `issue6312::NoDropAllCopy { name: name.len(), ..Default::default() }` and removing relevant reassignments
130-
--> tests/ui/field_reassign_with_default.rs:250:13
130+
--> tests/ui/field_reassign_with_default.rs:251:13
131131
|
132132
LL | let mut f = NoDropAllCopy::default();
133133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)