Skip to content

Commit a124479

Browse files
committed
adjust clippy to fix some of the issues
1 parent 08383ea commit a124479

File tree

13 files changed

+47
-47
lines changed

13 files changed

+47
-47
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,6 @@ symbols! {
21282128
slice_from_raw_parts_mut,
21292129
slice_from_ref,
21302130
slice_get_unchecked,
2131-
slice_into_vec,
21322131
slice_iter,
21332132
slice_len_fn,
21342133
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
@@ -472,7 +472,6 @@ impl<T> [T] {
472472
#[rustc_allow_incoherent_impl]
473473
#[stable(feature = "rust1", since = "1.0.0")]
474474
#[inline]
475-
#[rustc_diagnostic_item = "slice_into_vec"]
476475
pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
477476
unsafe {
478477
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/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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn or_fun_call() {
5353
with_constructor.unwrap_or_else(make);
5454
//~^ or_fun_call
5555

56-
let with_new = Some(vec![1]);
56+
let with_new: Option<Vec<i32>> = Some(vec![1]);
5757
with_new.unwrap_or_default();
5858
//~^ unwrap_or_default
5959

@@ -101,7 +101,7 @@ fn or_fun_call() {
101101
real_default.unwrap_or_default();
102102
//~^ unwrap_or_default
103103

104-
let with_vec = Some(vec![1]);
104+
let with_vec: Option<Vec<i32>> = Some(vec![1]);
105105
with_vec.unwrap_or_default();
106106
//~^ unwrap_or_default
107107

@@ -329,7 +329,7 @@ mod lazy {
329329
}
330330
}
331331

332-
let with_new = Some(vec![1]);
332+
let with_new: Option<Vec<i32>> = Some(vec![1]);
333333
with_new.unwrap_or_default();
334334
//~^ unwrap_or_default
335335

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn or_fun_call() {
5353
with_constructor.unwrap_or(make());
5454
//~^ or_fun_call
5555

56-
let with_new = Some(vec![1]);
56+
let with_new: Option<Vec<i32>> = Some(vec![1]);
5757
with_new.unwrap_or(Vec::new());
5858
//~^ unwrap_or_default
5959

@@ -101,7 +101,7 @@ fn or_fun_call() {
101101
real_default.unwrap_or(<FakeDefault as Default>::default());
102102
//~^ unwrap_or_default
103103

104-
let with_vec = Some(vec![1]);
104+
let with_vec: Option<Vec<i32>> = Some(vec![1]);
105105
with_vec.unwrap_or(Vec::new());
106106
//~^ unwrap_or_default
107107

@@ -329,7 +329,7 @@ mod lazy {
329329
}
330330
}
331331

332-
let with_new = Some(vec![1]);
332+
let with_new: Option<Vec<i32>> = Some(vec![1]);
333333
with_new.unwrap_or_else(Vec::new);
334334
//~^ unwrap_or_default
335335

0 commit comments

Comments
 (0)