Skip to content

Commit 7663583

Browse files
committed
adjust clippy to fix some of the issues
1 parent 7d1eeae commit 7663583

File tree

15 files changed

+77
-68
lines changed

15 files changed

+77
-68
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,6 @@ symbols! {
21292129
slice_from_raw_parts_mut,
21302130
slice_from_ref,
21312131
slice_get_unchecked,
2132-
slice_into_vec,
21332132
slice_iter,
21342133
slice_len_fn,
21352134
slice_patterns,

library/alloc/src/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ unsafe fn box_uninit_as_mut_ptr<T>(b: *mut Box<MaybeUninit<T>>) -> *mut T {
272272
#[unstable(feature = "liballoc_internals", issue = "none")]
273273
#[inline(always)]
274274
#[cfg(not(no_global_oom_handling))]
275+
#[rustc_diagnostic_item = "box_uninit_array_into_vec_unsafe"]
275276
pub fn box_uninit_array_into_vec_unsafe<T, const N: usize>(
276277
b: Box<MaybeUninit<[T; N]>>,
277278
) -> crate::vec::Vec<T> {

library/alloc/src/slice.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ impl<T> [T] {
474474
#[rustc_allow_incoherent_impl]
475475
#[stable(feature = "rust1", since = "1.0.0")]
476476
#[inline]
477-
#[rustc_diagnostic_item = "slice_into_vec"]
478477
pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
479478
unsafe {
480479
let len = self.len();

src/tools/clippy/clippy_utils/src/higher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@ impl<'a> VecArgs<'a> {
297297
// `vec![elem; size]` case
298298
Some(VecArgs::Repeat(elem, size))
299299
},
300-
(sym::slice_into_vec, [slice])
301-
if let ExprKind::Call(_, [arg]) = slice.kind
302-
&& let ExprKind::Array(args) = arg.kind =>
300+
(sym::box_uninit_array_into_vec_unsafe, [write_box_via_move])
301+
if let ExprKind::Call(_, [_box, elems]) = write_box_via_move.kind
302+
&& let ExprKind::Array(elems) = elems.kind =>
303303
{
304304
// `vec![a, b, c]` case
305-
Some(VecArgs::Vec(args))
305+
Some(VecArgs::Vec(elems))
306306
},
307307
(sym::vec_new, []) => Some(VecArgs::Vec(&[])),
308308
_ => None,

src/tools/clippy/clippy_utils/src/sym.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ generate! {
9191
author,
9292
borrow,
9393
borrow_mut,
94+
box_uninit_array_into_vec_unsafe,
9495
build_hasher,
9596
by_ref,
9697
bytes,

src/tools/clippy/tests/ui/cognitive_complexity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn kaboom() {
119119
}
120120

121121
fn bloo() {
122+
//~^ cognitive_complexity
122123
match 42 {
123124
0 => println!("hi"),
124125
1 => println!("hai"),

src/tools/clippy/tests/ui/cognitive_complexity.stderr

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,164 +17,172 @@ LL | fn kaboom() {
1717
= help: you could split it up into multiple smaller functions
1818

1919
error: the function has a cognitive complexity of (2/1)
20-
--> tests/ui/cognitive_complexity.rs:158:4
20+
--> tests/ui/cognitive_complexity.rs:121:4
21+
|
22+
LL | fn bloo() {
23+
| ^^^^
24+
|
25+
= help: you could split it up into multiple smaller functions
26+
27+
error: the function has a cognitive complexity of (2/1)
28+
--> tests/ui/cognitive_complexity.rs:159:4
2129
|
2230
LL | fn baa() {
2331
| ^^^
2432
|
2533
= help: you could split it up into multiple smaller functions
2634

2735
error: the function has a cognitive complexity of (2/1)
28-
--> tests/ui/cognitive_complexity.rs:161:13
36+
--> tests/ui/cognitive_complexity.rs:162:13
2937
|
3038
LL | let x = || match 99 {
3139
| ^^
3240
|
3341
= help: you could split it up into multiple smaller functions
3442

3543
error: the function has a cognitive complexity of (2/1)
36-
--> tests/ui/cognitive_complexity.rs:179:4
44+
--> tests/ui/cognitive_complexity.rs:180:4
3745
|
3846
LL | fn bar() {
3947
| ^^^
4048
|
4149
= help: you could split it up into multiple smaller functions
4250

4351
error: the function has a cognitive complexity of (2/1)
44-
--> tests/ui/cognitive_complexity.rs:192:4
52+
--> tests/ui/cognitive_complexity.rs:193:4
4553
|
4654
LL | fn dont_warn_on_tests() {
4755
| ^^^^^^^^^^^^^^^^^^
4856
|
4957
= help: you could split it up into multiple smaller functions
5058

5159
error: the function has a cognitive complexity of (2/1)
52-
--> tests/ui/cognitive_complexity.rs:202:4
60+
--> tests/ui/cognitive_complexity.rs:203:4
5361
|
5462
LL | fn barr() {
5563
| ^^^^
5664
|
5765
= help: you could split it up into multiple smaller functions
5866

5967
error: the function has a cognitive complexity of (3/1)
60-
--> tests/ui/cognitive_complexity.rs:214:4
68+
--> tests/ui/cognitive_complexity.rs:215:4
6169
|
6270
LL | fn barr2() {
6371
| ^^^^^
6472
|
6573
= help: you could split it up into multiple smaller functions
6674

6775
error: the function has a cognitive complexity of (2/1)
68-
--> tests/ui/cognitive_complexity.rs:232:4
76+
--> tests/ui/cognitive_complexity.rs:233:4
6977
|
7078
LL | fn barrr() {
7179
| ^^^^^
7280
|
7381
= help: you could split it up into multiple smaller functions
7482

7583
error: the function has a cognitive complexity of (3/1)
76-
--> tests/ui/cognitive_complexity.rs:244:4
84+
--> tests/ui/cognitive_complexity.rs:245:4
7785
|
7886
LL | fn barrr2() {
7987
| ^^^^^^
8088
|
8189
= help: you could split it up into multiple smaller functions
8290

8391
error: the function has a cognitive complexity of (2/1)
84-
--> tests/ui/cognitive_complexity.rs:262:4
92+
--> tests/ui/cognitive_complexity.rs:263:4
8593
|
8694
LL | fn barrrr() {
8795
| ^^^^^^
8896
|
8997
= help: you could split it up into multiple smaller functions
9098

9199
error: the function has a cognitive complexity of (3/1)
92-
--> tests/ui/cognitive_complexity.rs:274:4
100+
--> tests/ui/cognitive_complexity.rs:275:4
93101
|
94102
LL | fn barrrr2() {
95103
| ^^^^^^^
96104
|
97105
= help: you could split it up into multiple smaller functions
98106

99107
error: the function has a cognitive complexity of (2/1)
100-
--> tests/ui/cognitive_complexity.rs:292:4
108+
--> tests/ui/cognitive_complexity.rs:293:4
101109
|
102110
LL | fn cake() {
103111
| ^^^^
104112
|
105113
= help: you could split it up into multiple smaller functions
106114

107115
error: the function has a cognitive complexity of (4/1)
108-
--> tests/ui/cognitive_complexity.rs:304:8
116+
--> tests/ui/cognitive_complexity.rs:305:8
109117
|
110118
LL | pub fn read_file(input_path: &str) -> String {
111119
| ^^^^^^^^^
112120
|
113121
= help: you could split it up into multiple smaller functions
114122

115123
error: the function has a cognitive complexity of (2/1)
116-
--> tests/ui/cognitive_complexity.rs:337:4
124+
--> tests/ui/cognitive_complexity.rs:338:4
117125
|
118126
LL | fn void(void: Void) {
119127
| ^^^^
120128
|
121129
= help: you could split it up into multiple smaller functions
122130

123131
error: the function has a cognitive complexity of (8/1)
124-
--> tests/ui/cognitive_complexity.rs:390:4
132+
--> tests/ui/cognitive_complexity.rs:391:4
125133
|
126134
LL | fn early_ret() -> i32 {
127135
| ^^^^^^^^^
128136
|
129137
= help: you could split it up into multiple smaller functions
130138

131139
error: the function has a cognitive complexity of (2/1)
132-
--> tests/ui/cognitive_complexity.rs:413:13
140+
--> tests/ui/cognitive_complexity.rs:414:13
133141
|
134142
LL | let x = |a: i32, b: i32| -> i32 {
135143
| ^^^^^^^^^^^^^^^^
136144
|
137145
= help: you could split it up into multiple smaller functions
138146

139147
error: the function has a cognitive complexity of (2/1)
140-
--> tests/ui/cognitive_complexity.rs:428:8
148+
--> tests/ui/cognitive_complexity.rs:429:8
141149
|
142150
LL | fn moo(&self) {
143151
| ^^^
144152
|
145153
= help: you could split it up into multiple smaller functions
146154

147155
error: the function has a cognitive complexity of (2/1)
148-
--> tests/ui/cognitive_complexity.rs:439:14
156+
--> tests/ui/cognitive_complexity.rs:440:14
149157
|
150158
LL | async fn a() {
151159
| ^
152160
|
153161
= help: you could split it up into multiple smaller functions
154162

155163
error: the function has a cognitive complexity of (2/1)
156-
--> tests/ui/cognitive_complexity.rs:448:22
164+
--> tests/ui/cognitive_complexity.rs:449:22
157165
|
158166
LL | pub async fn async_method() {
159167
| ^^^^^^^^^^^^
160168
|
161169
= help: you could split it up into multiple smaller functions
162170

163171
error: the function has a cognitive complexity of (2/1)
164-
--> tests/ui/cognitive_complexity.rs:459:8
172+
--> tests/ui/cognitive_complexity.rs:460:8
165173
|
166174
LL | fn foo() {
167175
| ^^^
168176
|
169177
= help: you could split it up into multiple smaller functions
170178

171179
error: the function has a cognitive complexity of (2/1)
172-
--> tests/ui/cognitive_complexity.rs:466:8
180+
--> tests/ui/cognitive_complexity.rs:467:8
173181
|
174182
LL | fn bar() {
175183
| ^^^
176184
|
177185
= help: you could split it up into multiple smaller functions
178186

179-
error: aborting due to 22 previous errors
187+
error: aborting due to 23 previous errors
180188

src/tools/clippy/tests/ui/manual_map_option.fixed

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ fn main() {
113113
}
114114

115115
// #6811
116-
match Some(0) {
117-
Some(x) => Some(vec![x]),
118-
None => None,
119-
};
116+
Some(0).map(|x| vec![x]);
120117

121118
// Don't lint, coercion
122119
let x: Option<Vec<&[u8]>> = match Some(()) {

src/tools/clippy/tests/ui/manual_map_option.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ fn main() {
183183

184184
// #6811
185185
match Some(0) {
186+
//~^ manual_map
186187
Some(x) => Some(vec![x]),
187188
None => None,
188189
};

src/tools/clippy/tests/ui/manual_map_option.stderr

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,17 @@ LL | | };
173173
| |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))`
174174

175175
error: manual implementation of `Option::map`
176-
--> tests/ui/manual_map_option.rs:196:5
176+
--> tests/ui/manual_map_option.rs:185:5
177+
|
178+
LL | / match Some(0) {
179+
LL | |
180+
LL | | Some(x) => Some(vec![x]),
181+
LL | | None => None,
182+
LL | | };
183+
| |_____^ help: try: `Some(0).map(|x| vec![x])`
184+
185+
error: manual implementation of `Option::map`
186+
--> tests/ui/manual_map_option.rs:197:5
177187
|
178188
LL | / match option_env!("") {
179189
LL | |
@@ -183,7 +193,7 @@ LL | | };
183193
| |_____^ help: try: `option_env!("").map(String::from)`
184194

185195
error: manual implementation of `Option::map`
186-
--> tests/ui/manual_map_option.rs:217:12
196+
--> tests/ui/manual_map_option.rs:218:12
187197
|
188198
LL | } else if let Some(x) = Some(0) {
189199
| ____________^
@@ -195,7 +205,7 @@ LL | | };
195205
| |_____^ help: try: `{ Some(0).map(|x| x + 1) }`
196206

197207
error: manual implementation of `Option::map`
198-
--> tests/ui/manual_map_option.rs:226:12
208+
--> tests/ui/manual_map_option.rs:227:12
199209
|
200210
LL | } else if let Some(x) = Some(0) {
201211
| ____________^
@@ -206,5 +216,5 @@ LL | | None
206216
LL | | };
207217
| |_____^ help: try: `{ Some(0).map(|x| x + 1) }`
208218

209-
error: aborting due to 20 previous errors
219+
error: aborting due to 21 previous errors
210220

0 commit comments

Comments
 (0)