Skip to content

Commit 62f7694

Browse files
committed
fix pr comments
1 parent cbebf82 commit 62f7694

13 files changed

+34
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3278,7 +3278,7 @@ Released 2018-09-13
32783278
[`allow_attributes_without_reason`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason
32793279
[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
32803280
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
3281-
[`arc_new_in_vec_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#arc_new_in_vec_from_slice
3281+
[`arc_new_in_vec_from_elem`]: https://rust-lang.github.io/rust-clippy/master/index.html#arc_new_in_vec_from_elem
32823282
[`as_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions
32833283
[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
32843284
[`assign_op_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

clippy_lints/src/arc_new_in_vec_from_slice.rs renamed to clippy_lints/src/arc_new_in_vec_from_elem.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,18 @@ declare_clippy_lint! {
2626
/// let v = vec![data; 100];
2727
/// ```
2828
#[clippy::version = "1.62.0"]
29-
pub ARC_NEW_IN_VEC_FROM_SLICE,
29+
pub ARC_NEW_IN_VEC_FROM_ELEM,
3030
suspicious,
3131
"calling `Arc::new` in `vec![elem; len]`"
3232
}
33-
declare_lint_pass!(ArcNewInVecFromSlice => [ARC_NEW_IN_VEC_FROM_SLICE]);
33+
declare_lint_pass!(ArcNewInVecFromSlice => [ARC_NEW_IN_VEC_FROM_ELEM]);
3434

3535
impl LateLintPass<'_> for ArcNewInVecFromSlice {
3636
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
3737
let Some(macro_call) = root_macro_call_first_node(cx, expr) else { return; };
38-
if !macro_is_vec(cx, &macro_call) {
39-
return;
40-
}
4138

4239
if let Some(VecArgs::Repeat(elem, _)) = VecArgs::hir(cx, expr) {
43-
if !is_arc_new(elem) {
40+
if !is_arc_new(cx, elem) {
4441
return;
4542
}
4643

@@ -52,25 +49,22 @@ impl LateLintPass<'_> for ArcNewInVecFromSlice {
5249
fn yield_lint(cx: &LateContext<'_>, macro_call: &MacroCall) {
5350
span_lint_and_help(
5451
cx,
55-
ARC_NEW_IN_VEC_FROM_SLICE,
52+
ARC_NEW_IN_VEC_FROM_ELEM,
5653
macro_call.span,
5754
"calling `Arc::new` in `vec![elem; len]`",
5855
None,
5956
"consider extracting `Arc` initialization to a variable",
6057
);
6158
}
6259

63-
fn macro_is_vec(cx: &LateContext<'_>, macro_call: &MacroCall) -> bool {
64-
cx.tcx.is_diagnostic_item(sym::vec_macro, macro_call.def_id)
65-
}
66-
6760
/// Checks whether the given `expr` is a call to `Arc::new`
68-
fn is_arc_new(expr: &Expr<'_>) -> bool {
61+
fn is_arc_new(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
6962
if_chain! {
7063
if let ExprKind::Call(func, _args) = expr.kind;
71-
if let ExprKind::Path(ref func_path) = func.kind;
72-
if let ExprKind::Path(QPath::TypeRelative(ty, _)) = func.kind;
64+
if let ExprKind::Path(ref func_path @ QPath::TypeRelative(ty, _)) = func.kind;
7365
if let TyKind::Path(ref ty_path) = ty.kind;
66+
if let Some(def_id) = cx.qpath_res(ty_path, ty.hir_id).opt_def_id();
67+
if cx.tcx.is_diagnostic_item(sym::Arc, def_id);
7468

7569
then {
7670
let ty_segment = last_path_segment(ty_path);

clippy_lints/src/lib.register_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
store.register_group(true, "clippy::all", Some("clippy_all"), vec![
66
LintId::of(absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS),
77
LintId::of(approx_const::APPROX_CONSTANT),
8-
LintId::of(arc_new_in_vec_from_slice::ARC_NEW_IN_VEC_FROM_SLICE),
8+
LintId::of(arc_new_in_vec_from_elem::ARC_NEW_IN_VEC_FROM_ELEM),
99
LintId::of(assertions_on_constants::ASSERTIONS_ON_CONSTANTS),
1010
LintId::of(assign_ops::ASSIGN_OP_PATTERN),
1111
LintId::of(assign_ops::MISREFACTORED_ASSIGN_OP),

clippy_lints/src/lib.register_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ store.register_lints(&[
3535
utils::internal_lints::UNNECESSARY_SYMBOL_STR,
3636
absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS,
3737
approx_const::APPROX_CONSTANT,
38-
arc_new_in_vec_from_slice::ARC_NEW_IN_VEC_FROM_SLICE,
38+
arc_new_in_vec_from_elem::ARC_NEW_IN_VEC_FROM_ELEM,
3939
arithmetic::FLOAT_ARITHMETIC,
4040
arithmetic::INTEGER_ARITHMETIC,
4141
as_conversions::AS_CONVERSIONS,

clippy_lints/src/lib.register_suspicious.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Manual edits will be overwritten.
44

55
store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec![
6-
LintId::of(arc_new_in_vec_from_slice::ARC_NEW_IN_VEC_FROM_SLICE),
6+
LintId::of(arc_new_in_vec_from_elem::ARC_NEW_IN_VEC_FROM_ELEM),
77
LintId::of(assign_ops::MISREFACTORED_ASSIGN_OP),
88
LintId::of(attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
99
LintId::of(await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE),

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mod utils;
166166
// begin lints modules, do not remove this comment, it’s used in `update_lints`
167167
mod absurd_extreme_comparisons;
168168
mod approx_const;
169-
mod arc_new_in_vec_from_slice;
169+
mod arc_new_in_vec_from_elem;
170170
mod arithmetic;
171171
mod as_conversions;
172172
mod asm_syntax;
@@ -888,7 +888,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
888888
store.register_late_pass(|| Box::new(bytes_count_to_len::BytesCountToLen));
889889
let max_include_file_size = conf.max_include_file_size;
890890
store.register_late_pass(move || Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size)));
891-
store.register_late_pass(|| Box::new(arc_new_in_vec_from_slice::ArcNewInVecFromSlice));
891+
store.register_late_pass(|| Box::new(arc_new_in_vec_from_elem::ArcNewInVecFromSlice));
892892
// add lints here, do not remove this comment, it's used in `new_lint`
893893
}
894894

tests/ui/arc_new_in_vec_from_slice/complex_case.rs renamed to tests/ui/arc_new_in_vec_from_elem/complex_case.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::arc_new_in_vec_from_slice)]
1+
#![warn(clippy::arc_new_in_vec_from_elem)]
22
use std::sync::Mutex;
33

44
fn main() {

tests/ui/arc_new_in_vec_from_slice/complex_case.stderr renamed to tests/ui/arc_new_in_vec_from_elem/complex_case.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | | 2
1111
LL | | ];
1212
| |_____^
1313
|
14-
= note: `-D clippy::arc-new-in-vec-from-slice` implied by `-D warnings`
14+
= note: `-D clippy::arc-new-in-vec-from-elem` implied by `-D warnings`
1515
= help: consider extracting `Arc` initialization to a variable
1616

1717
error: aborting due to previous error
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![warn(clippy::arc_new_in_vec_from_elem)]
2+
3+
#[derive(Clone)]
4+
struct Arc;
5+
6+
impl Arc {
7+
fn new() -> Self {
8+
Arc
9+
}
10+
}
11+
12+
fn main() {
13+
let v = vec![Arc::new(); 2];
14+
}

tests/ui/arc_new_in_vec_from_slice/simple_case.rs renamed to tests/ui/arc_new_in_vec_from_elem/simple_case.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::arc_new_in_vec_from_slice)]
1+
#![warn(clippy::arc_new_in_vec_from_elem)]
22
use std::sync::Arc;
33

44
fn main() {

tests/ui/arc_new_in_vec_from_slice/simple_case.stderr renamed to tests/ui/arc_new_in_vec_from_elem/simple_case.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: calling `Arc::new` in `vec![elem; len]`
44
LL | let v = vec![Arc::new("x".to_string()); 2];
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::arc-new-in-vec-from-slice` implied by `-D warnings`
7+
= note: `-D clippy::arc-new-in-vec-from-elem` implied by `-D warnings`
88
= help: consider extracting `Arc` initialization to a variable
99

1010
error: aborting due to previous error

tests/ui/arc_new_in_vec_from_slice/vec_from_elem_but_not_arc.rs renamed to tests/ui/arc_new_in_vec_from_elem/vec_from_elem_but_not_arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::arc_new_in_vec_from_slice)]
1+
#![warn(clippy::arc_new_in_vec_from_elem)]
22
use std::sync::{Arc, Mutex};
33

44
fn main() {

tests/ui/arc_new_in_vec_from_slice/vec_macro_but_not_from_elem.rs renamed to tests/ui/arc_new_in_vec_from_elem/vec_macro_but_not_from_elem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::arc_new_in_vec_from_slice)]
1+
#![warn(clippy::arc_new_in_vec_from_elem)]
22
use std::sync::Arc;
33

44
fn main() {

0 commit comments

Comments
 (0)