fix indentation + test
This commit is contained in:
parent
a791205e76
commit
dc23b5d661
@ -106,9 +106,9 @@ fn elem_snippet(cx: &LateContext<'_>, elem: &Expr<'_>, symbol_name: &str) -> Str
|
||||
fn loop_init_suggestion(elem: &str, len: &str, indent: &str) -> String {
|
||||
format!(
|
||||
r#"{{
|
||||
{indent}{indent}let mut v = Vec::with_capacity({len});
|
||||
{indent}{indent}(0..{len}).for_each(|_| v.push({elem}));
|
||||
{indent}{indent}v
|
||||
{indent} let mut v = Vec::with_capacity({len});
|
||||
{indent} (0..{len}).for_each(|_| v.push({elem}));
|
||||
{indent} v
|
||||
{indent}}}"#
|
||||
)
|
||||
}
|
||||
@ -116,8 +116,8 @@ fn loop_init_suggestion(elem: &str, len: &str, indent: &str) -> String {
|
||||
fn extract_suggestion(elem: &str, len: &str, indent: &str) -> String {
|
||||
format!(
|
||||
"{{
|
||||
{indent}{indent}let data = {elem};
|
||||
{indent}{indent}vec![data; {len}]
|
||||
{indent} let data = {elem};
|
||||
{indent} vec![data; {len}]
|
||||
{indent}}}"
|
||||
)
|
||||
}
|
||||
|
@ -7,6 +7,16 @@ fn should_warn_simple_case() {
|
||||
let v = vec![Arc::new("x".to_string()); 2];
|
||||
}
|
||||
|
||||
fn should_warn_simple_case_with_big_indentation() {
|
||||
if true {
|
||||
let k = 1;
|
||||
dbg!(k);
|
||||
if true {
|
||||
let v = vec![Arc::new("x".to_string()); 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn should_warn_complex_case() {
|
||||
let v = vec![
|
||||
std::sync::Arc::new(Mutex::new({
|
||||
|
@ -23,7 +23,30 @@ LL ~ };
|
||||
|
|
||||
|
||||
error: calling `Arc::new` in `vec![elem; len]`
|
||||
--> $DIR/arc.rs:11:13
|
||||
--> $DIR/arc.rs:15:21
|
||||
|
|
||||
LL | let v = vec![Arc::new("x".to_string()); 2];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: each element will point to the same `Arc` instance
|
||||
help: consider initializing each `Arc` element individually
|
||||
|
|
||||
LL ~ let v = {
|
||||
LL + let mut v = Vec::with_capacity(2);
|
||||
LL + (0..2).for_each(|_| v.push(Arc::new("x".to_string())));
|
||||
LL + v
|
||||
LL ~ };
|
||||
|
|
||||
help: or if this is intentional, consider extracting the `Arc` initialization to a variable
|
||||
|
|
||||
LL ~ let v = {
|
||||
LL + let data = Arc::new("x".to_string());
|
||||
LL + vec![data; 2]
|
||||
LL ~ };
|
||||
|
|
||||
|
||||
error: calling `Arc::new` in `vec![elem; len]`
|
||||
--> $DIR/arc.rs:21:13
|
||||
|
|
||||
LL | let v = vec![
|
||||
| _____________^
|
||||
@ -53,7 +76,7 @@ LL ~ };
|
||||
|
|
||||
|
||||
error: calling `Arc::new` in `vec![elem; len]`
|
||||
--> $DIR/arc.rs:20:14
|
||||
--> $DIR/arc.rs:30:14
|
||||
|
|
||||
LL | let v1 = vec![
|
||||
| ______________^
|
||||
@ -82,5 +105,5 @@ LL + vec![data; 2]
|
||||
LL ~ };
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -8,6 +8,16 @@ fn should_warn_simple_case() {
|
||||
let v = vec![Rc::new("x".to_string()); 2];
|
||||
}
|
||||
|
||||
fn should_warn_simple_case_with_big_indentation() {
|
||||
if true {
|
||||
let k = 1;
|
||||
dbg!(k);
|
||||
if true {
|
||||
let v = vec![Rc::new("x".to_string()); 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn should_warn_complex_case() {
|
||||
let v = vec![
|
||||
std::rc::Rc::new(Mutex::new({
|
||||
|
@ -23,7 +23,30 @@ LL ~ };
|
||||
|
|
||||
|
||||
error: calling `Rc::new` in `vec![elem; len]`
|
||||
--> $DIR/rc.rs:12:13
|
||||
--> $DIR/rc.rs:16:21
|
||||
|
|
||||
LL | let v = vec![Rc::new("x".to_string()); 2];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: each element will point to the same `Rc` instance
|
||||
help: consider initializing each `Rc` element individually
|
||||
|
|
||||
LL ~ let v = {
|
||||
LL + let mut v = Vec::with_capacity(2);
|
||||
LL + (0..2).for_each(|_| v.push(Rc::new("x".to_string())));
|
||||
LL + v
|
||||
LL ~ };
|
||||
|
|
||||
help: or if this is intentional, consider extracting the `Rc` initialization to a variable
|
||||
|
|
||||
LL ~ let v = {
|
||||
LL + let data = Rc::new("x".to_string());
|
||||
LL + vec![data; 2]
|
||||
LL ~ };
|
||||
|
|
||||
|
||||
error: calling `Rc::new` in `vec![elem; len]`
|
||||
--> $DIR/rc.rs:22:13
|
||||
|
|
||||
LL | let v = vec![
|
||||
| _____________^
|
||||
@ -53,7 +76,7 @@ LL ~ };
|
||||
|
|
||||
|
||||
error: calling `Rc::new` in `vec![elem; len]`
|
||||
--> $DIR/rc.rs:21:14
|
||||
--> $DIR/rc.rs:31:14
|
||||
|
|
||||
LL | let v1 = vec![
|
||||
| ______________^
|
||||
@ -82,5 +105,5 @@ LL + vec![data; 2]
|
||||
LL ~ };
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user