From c6c156fa4e37b3c1b05579c66b7db636b8798d53 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 2 May 2018 00:07:31 +0200 Subject: [PATCH 1/3] remove test that currently doesn't work probably because we need to enable clippy lint groups (but I don't want to spend time on this right now) --- tests/fixtures/const_static_lifetime.fixed.rs | 3 - tests/fixtures/const_static_lifetime.json | 111 ------------------ tests/fixtures/const_static_lifetime.rs | 3 - 3 files changed, 117 deletions(-) delete mode 100644 tests/fixtures/const_static_lifetime.fixed.rs delete mode 100644 tests/fixtures/const_static_lifetime.json delete mode 100644 tests/fixtures/const_static_lifetime.rs diff --git a/tests/fixtures/const_static_lifetime.fixed.rs b/tests/fixtures/const_static_lifetime.fixed.rs deleted file mode 100644 index 1160de8..0000000 --- a/tests/fixtures/const_static_lifetime.fixed.rs +++ /dev/null @@ -1,3 +0,0 @@ -const LOREM: &str = "ipsum"; - -fn main() {} diff --git a/tests/fixtures/const_static_lifetime.json b/tests/fixtures/const_static_lifetime.json deleted file mode 100644 index 6c284cd..0000000 --- a/tests/fixtures/const_static_lifetime.json +++ /dev/null @@ -1,111 +0,0 @@ -{ - "message": "Constants have by default a `'static` lifetime", - "code": { - "code": "const_static_lifetime", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/const_static_lifetime.rs", - "byte_start": 14, - "byte_end": 21, - "line_start": 1, - "line_end": 1, - "column_start": 15, - "column_end": 22, - "is_primary": true, - "text": [ - { - "text": "const LOREM: &'static str = \"ipsum\";", - "highlight_start": 15, - "highlight_end": 22 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "#[warn(const_static_lifetime)] on by default", - "code": null, - "level": "note", - "spans": [], - "children": [], - "rendered": null - }, - { - "message": "consider removing `'static`", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/const_static_lifetime.rs", - "byte_start": 13, - "byte_end": 25, - "line_start": 1, - "line_end": 1, - "column_start": 14, - "column_end": 26, - "is_primary": true, - "text": [ - { - "text": "const LOREM: &'static str = \"ipsum\";", - "highlight_start": 14, - "highlight_end": 26 - } - ], - "label": null, - "suggested_replacement": "&str", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: Constants have by default a `'static` lifetime\n --> ./tests/fixtures/const_static_lifetime.rs:1:15\n |\n1 | const LOREM: &'static str = \"ipsum\";\n | -^^^^^^^---- help: consider removing `'static`: `&str`\n |\n = note: #[warn(const_static_lifetime)] on by default\n\n" -} -{ - "message": "constant item is never used: `LOREM`", - "code": { - "code": "dead_code", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/const_static_lifetime.rs", - "byte_start": 0, - "byte_end": 36, - "line_start": 1, - "line_end": 1, - "column_start": 1, - "column_end": 37, - "is_primary": true, - "text": [ - { - "text": "const LOREM: &'static str = \"ipsum\";", - "highlight_start": 1, - "highlight_end": 37 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "#[warn(dead_code)] on by default", - "code": null, - "level": "note", - "spans": [], - "children": [], - "rendered": null - } - ], - "rendered": "warning: constant item is never used: `LOREM`\n --> ./tests/fixtures/const_static_lifetime.rs:1:1\n |\n1 | const LOREM: &'static str = \"ipsum\";\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n |\n = note: #[warn(dead_code)] on by default\n\n" -} diff --git a/tests/fixtures/const_static_lifetime.rs b/tests/fixtures/const_static_lifetime.rs deleted file mode 100644 index 665af8a..0000000 --- a/tests/fixtures/const_static_lifetime.rs +++ /dev/null @@ -1,3 +0,0 @@ -const LOREM: &'static str = "ipsum"; - -fn main() {} From 571b43a1a1777561ddd7a41b37512bf0e3452c1a Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 2 May 2018 00:07:58 +0200 Subject: [PATCH 2/3] Move `apply_suggestion{s,}` to rustfix lib --- src/lib.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 40 ++----------------------------- tests/everything.rs | 58 ++------------------------------------------- 3 files changed, 61 insertions(+), 94 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fdae6b4..71d2947 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ extern crate serde_derive; extern crate serde_json; use std::collections::HashSet; +use std::error::Error; pub mod diagnostics; use diagnostics::{Diagnostic, DiagnosticSpan}; @@ -165,3 +166,59 @@ pub fn collect_suggestions(diagnostic: &Diagnostic, }) } } + +pub fn apply_suggestion(file_content: &mut String, suggestion: &Replacement) -> String { + use std::cmp::max; + + let mut new_content = String::new(); + + // Add the lines before the section we want to replace + new_content.push_str(&file_content.lines() + .take(max(suggestion.snippet.line_range.start.line - 1, 0) as usize) + .collect::>() + .join("\n")); + new_content.push_str("\n"); + + // Parts of line before replacement + new_content.push_str(&file_content.lines() + .nth(suggestion.snippet.line_range.start.line - 1) + .unwrap_or("") + .chars() + .take(suggestion.snippet.line_range.start.column - 1) + .collect::()); + + // Insert new content! Finally! + new_content.push_str(&suggestion.replacement); + + // Parts of line after replacement + new_content.push_str(&file_content.lines() + .nth(suggestion.snippet.line_range.end.line - 1) + .unwrap_or("") + .chars() + .skip(suggestion.snippet.line_range.end.column - 1) + .collect::()); + + // Add the lines after the section we want to replace + new_content.push_str("\n"); + new_content.push_str(&file_content.lines() + .skip(suggestion.snippet.line_range.end.line as usize) + .collect::>() + .join("\n")); + new_content.push_str("\n"); + + new_content +} + +pub fn apply_suggestions(code: &str, suggestions: &[Suggestion]) -> String { + let mut fixed = code.to_string(); + + for sug in suggestions.iter().rev() { + for sol in &sug.solutions { + for r in &sol.replacements { + fixed = apply_suggestion(&mut fixed, r); + } + } + } + + fixed +} diff --git a/src/main.rs b/src/main.rs index 0c8e2b3..8cce541 100644 --- a/src/main.rs +++ b/src/main.rs @@ -398,44 +398,8 @@ fn indent(size: u32, s: &str) -> String { /// This function is as stupid as possible. Make sure you call for the replacemnts in one file in /// reverse order to not mess up the lines for replacements further down the road. fn apply_suggestion(suggestion: &Replacement) -> Result<(), ProgramError> { - use std::cmp::max; - - let file_content = try!(read_file_to_string(&suggestion.snippet.file_name)); - let mut new_content = String::new(); - - // Add the lines before the section we want to replace - new_content.push_str(&file_content.lines() - .take(max(suggestion.snippet.line_range.start.line - 1, 0) as usize) - .collect::>() - .join("\n")); - new_content.push_str("\n"); - - // Parts of line before replacement - new_content.push_str(&file_content.lines() - .nth(suggestion.snippet.line_range.start.line - 1) - .unwrap_or("") - .chars() - .take(suggestion.snippet.line_range.start.column - 1) - .collect::()); - - // Insert new content! Finally! - new_content.push_str(&suggestion.replacement); - - // Parts of line after replacement - new_content.push_str(&file_content.lines() - .nth(suggestion.snippet.line_range.end.line - 1) - .unwrap_or("") - .chars() - .skip(suggestion.snippet.line_range.end.column - 1) - .collect::()); - - // Add the lines after the section we want to replace - new_content.push_str("\n"); - new_content.push_str(&file_content.lines() - .skip(suggestion.snippet.line_range.end.line as usize) - .collect::>() - .join("\n")); - new_content.push_str("\n"); + let mut file_content = try!(read_file_to_string(&suggestion.snippet.file_name)); + let new_content = rustfix::apply_suggestion(&mut file_content, suggestion); let mut file = try!(File::create(&suggestion.snippet.file_name)); let new_content = new_content.as_bytes(); diff --git a/tests/everything.rs b/tests/everything.rs index 7cc50f7..029bf13 100644 --- a/tests/everything.rs +++ b/tests/everything.rs @@ -13,7 +13,7 @@ use std::collections::HashSet; use std::process::Output; use tempdir::TempDir; -use rustfix::Replacement; +use rustfix::{Replacement, apply_suggestions}; fn compile(file: &Path) -> Result> { let tmp = TempDir::new("rustfix-tests")?; @@ -75,48 +75,6 @@ fn read_file(path: &Path) -> Result> { Ok(buffer) } -fn apply_suggestion(file_content: &mut String, suggestion: &Replacement) -> Result> { - use std::cmp::max; - - let mut new_content = String::new(); - - // Add the lines before the section we want to replace - new_content.push_str(&file_content.lines() - .take(max(suggestion.snippet.line_range.start.line - 1, 0) as usize) - .collect::>() - .join("\n")); - new_content.push_str("\n"); - - // Parts of line before replacement - new_content.push_str(&file_content.lines() - .nth(suggestion.snippet.line_range.start.line - 1) - .unwrap_or("") - .chars() - .take(suggestion.snippet.line_range.start.column - 1) - .collect::()); - - // Insert new content! Finally! - new_content.push_str(&suggestion.replacement); - - // Parts of line after replacement - new_content.push_str(&file_content.lines() - .nth(suggestion.snippet.line_range.end.line - 1) - .unwrap_or("") - .chars() - .skip(suggestion.snippet.line_range.end.column - 1) - .collect::()); - - // Add the lines after the section we want to replace - new_content.push_str("\n"); - new_content.push_str(&file_content.lines() - .skip(suggestion.snippet.line_range.end.line as usize) - .collect::>() - .join("\n")); - new_content.push_str("\n"); - - Ok(new_content) -} - fn test_rustfix_with_file>(file: P) -> Result<(), Box> { let file: &Path = file.as_ref(); let json_file = file.with_extension("json"); @@ -141,19 +99,7 @@ fn test_rustfix_with_file>(file: P) -> Result<(), Box> { "got unexpected suggestions from clippy", ); - let mut fixed = code.clone(); - - for sug in suggestions.into_iter().rev() { - trace!("{:?}", sug); - for sol in sug.solutions { - trace!("{:?}", sol); - for r in sol.replacements { - debug!("replaced."); - trace!("{:?}", r); - fixed = apply_suggestion(&mut fixed, &r)?; - } - } - } + let fixed = apply_suggestions(&code, &suggestions); if std::env::var("RUSTFIX_TEST_RECORD_FIXED_RUST").is_ok() { use std::io::Write; From a5123f0751e5186a0cb16f6fc1462793a5d83866 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 2 May 2018 15:38:47 -0700 Subject: [PATCH 3/3] Remove tests that require clippy Looks like they're failing on nightly and hopefully we'll get enough coverage in rust-lang/rust itself to cover these use cases. --- .travis.yml | 2 - tests/everything.rs | 2 +- tests/fixtures/explicit_iter_loop.fixed.rs | 7 - tests/fixtures/explicit_iter_loop.json | 70 ------ tests/fixtures/explicit_iter_loop.rs | 7 - tests/fixtures/fold-any.fixed.rs | 7 - tests/fixtures/fold-any.json | 204 ----------------- tests/fixtures/fold-any.rs | 8 - tests/fixtures/needless_borrow.fixed.rs | 9 - tests/fixtures/needless_borrow.json | 132 ----------- tests/fixtures/needless_borrow.rs | 9 - .../fixtures/redundant_closure_call.fixed.rs | 8 - tests/fixtures/redundant_closure_call.json | 214 ------------------ tests/fixtures/redundant_closure_call.rs | 10 - 14 files changed, 1 insertion(+), 688 deletions(-) delete mode 100644 tests/fixtures/explicit_iter_loop.fixed.rs delete mode 100644 tests/fixtures/explicit_iter_loop.json delete mode 100644 tests/fixtures/explicit_iter_loop.rs delete mode 100644 tests/fixtures/fold-any.fixed.rs delete mode 100644 tests/fixtures/fold-any.json delete mode 100644 tests/fixtures/fold-any.rs delete mode 100644 tests/fixtures/needless_borrow.fixed.rs delete mode 100644 tests/fixtures/needless_borrow.json delete mode 100644 tests/fixtures/needless_borrow.rs delete mode 100644 tests/fixtures/redundant_closure_call.fixed.rs delete mode 100644 tests/fixtures/redundant_closure_call.json delete mode 100644 tests/fixtures/redundant_closure_call.rs diff --git a/.travis.yml b/.travis.yml index 51719c8..519b9dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ language: rust rust: - nightly - stable -before_script: -- if [ $TRAVIS_RUST_VERSION == nightly ]; then cargo install clippy --git https://github.com/rust-lang-nursery/rust-clippy.git --force; fi script: - cargo build - if [ $TRAVIS_RUST_VERSION == nightly ]; then cargo test -- --nocapture ; fi diff --git a/tests/everything.rs b/tests/everything.rs index 029bf13..7206db8 100644 --- a/tests/everything.rs +++ b/tests/everything.rs @@ -18,7 +18,7 @@ use rustfix::{Replacement, apply_suggestions}; fn compile(file: &Path) -> Result> { let tmp = TempDir::new("rustfix-tests")?; let better_call_clippy = cmd!( - "clippy-driver", "rustc", file, + "rustc", file, "--error-format=pretty-json", "-Zunstable-options", "--emit=metadata", "--crate-name=rustfix_test", "--out-dir", tmp.path() diff --git a/tests/fixtures/explicit_iter_loop.fixed.rs b/tests/fixtures/explicit_iter_loop.fixed.rs deleted file mode 100644 index 0ffeff1..0000000 --- a/tests/fixtures/explicit_iter_loop.fixed.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let xs = vec![1, 2, 3]; - - for x in &xs { - println!("{}", x) - } -} diff --git a/tests/fixtures/explicit_iter_loop.json b/tests/fixtures/explicit_iter_loop.json deleted file mode 100644 index 1e286de..0000000 --- a/tests/fixtures/explicit_iter_loop.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "message": "it is more idiomatic to loop over references to containers instead of using explicit iteration methods", - "code": { - "code": "explicit_iter_loop", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/explicit_iter_loop.rs", - "byte_start": 54, - "byte_end": 63, - "line_start": 4, - "line_end": 4, - "column_start": 14, - "column_end": 23, - "is_primary": true, - "text": [ - { - "text": " for x in xs.iter() {", - "highlight_start": 14, - "highlight_end": 23 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "#[warn(explicit_iter_loop)] on by default", - "code": null, - "level": "note", - "spans": [], - "children": [], - "rendered": null - }, - { - "message": "to write this more concisely, try", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/explicit_iter_loop.rs", - "byte_start": 54, - "byte_end": 63, - "line_start": 4, - "line_end": 4, - "column_start": 14, - "column_end": 23, - "is_primary": true, - "text": [ - { - "text": " for x in xs.iter() {", - "highlight_start": 14, - "highlight_end": 23 - } - ], - "label": null, - "suggested_replacement": "&xs", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: it is more idiomatic to loop over references to containers instead of using explicit iteration methods\n --> ./tests/fixtures/explicit_iter_loop.rs:4:14\n |\n4 | for x in xs.iter() {\n | ^^^^^^^^^ help: to write this more concisely, try: `&xs`\n |\n = note: #[warn(explicit_iter_loop)] on by default\n\n" -} diff --git a/tests/fixtures/explicit_iter_loop.rs b/tests/fixtures/explicit_iter_loop.rs deleted file mode 100644 index 2e9c841..0000000 --- a/tests/fixtures/explicit_iter_loop.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let xs = vec![1, 2, 3]; - - for x in xs.iter() { - println!("{}", x) - } -} diff --git a/tests/fixtures/fold-any.fixed.rs b/tests/fixtures/fold-any.fixed.rs deleted file mode 100644 index 7644508..0000000 --- a/tests/fixtures/fold-any.fixed.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let _ = (0..3).any(|x| x > 2); - - let _ = (0..3).any(|x| x > 2); - - let _ = (0..3).all(|x| x > 2); -} diff --git a/tests/fixtures/fold-any.json b/tests/fixtures/fold-any.json deleted file mode 100644 index 9a11d62..0000000 --- a/tests/fixtures/fold-any.json +++ /dev/null @@ -1,204 +0,0 @@ -{ - "message": "this `.fold` can be written more succinctly using another method", - "code": { - "code": "unnecessary_fold", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/fold-any.rs", - "byte_start": 30, - "byte_end": 65, - "line_start": 2, - "line_end": 2, - "column_start": 19, - "column_end": 54, - "is_primary": true, - "text": [ - { - "text": " let _ = (0..3).fold(false, |acc, x| acc || x > 2);", - "highlight_start": 19, - "highlight_end": 54 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "#[warn(unnecessary_fold)] on by default", - "code": null, - "level": "note", - "spans": [], - "children": [], - "rendered": null - }, - { - "message": "try", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/fold-any.rs", - "byte_start": 30, - "byte_end": 65, - "line_start": 2, - "line_end": 2, - "column_start": 19, - "column_end": 54, - "is_primary": true, - "text": [ - { - "text": " let _ = (0..3).fold(false, |acc, x| acc || x > 2);", - "highlight_start": 19, - "highlight_end": 54 - } - ], - "label": null, - "suggested_replacement": ".any(|x| x > 2)", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: this `.fold` can be written more succinctly using another method\n --> ./tests/fixtures/fold-any.rs:2:19\n |\n2 | let _ = (0..3).fold(false, |acc, x| acc || x > 2);\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`\n |\n = note: #[warn(unnecessary_fold)] on by default\n\n" -} -{ - "message": "this `.fold` can be written more succinctly using another method", - "code": { - "code": "unnecessary_fold", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/fold-any.rs", - "byte_start": 86, - "byte_end": 134, - "line_start": 4, - "line_end": 5, - "column_start": 19, - "column_end": 48, - "is_primary": true, - "text": [ - { - "text": " let _ = (0..3)", - "highlight_start": 19, - "highlight_end": 19 - }, - { - "text": " .fold(false, |acc, x| { acc || x > 2 });", - "highlight_start": 1, - "highlight_end": 48 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "try", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/fold-any.rs", - "byte_start": 86, - "byte_end": 134, - "line_start": 4, - "line_end": 5, - "column_start": 19, - "column_end": 48, - "is_primary": true, - "text": [ - { - "text": " let _ = (0..3)", - "highlight_start": 19, - "highlight_end": 19 - }, - { - "text": " .fold(false, |acc, x| { acc || x > 2 });", - "highlight_start": 1, - "highlight_end": 48 - } - ], - "label": null, - "suggested_replacement": ".any(|x| x > 2)", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: this `.fold` can be written more succinctly using another method\n --> ./tests/fixtures/fold-any.rs:4:19\n |\n4 | let _ = (0..3)\n | ___________________^\n5 | | .fold(false, |acc, x| { acc || x > 2 });\n | |_______________________________________________^ help: try: `.any(|x| x > 2)`\n\n" -} -{ - "message": "this `.fold` can be written more succinctly using another method", - "code": { - "code": "unnecessary_fold", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/fold-any.rs", - "byte_start": 155, - "byte_end": 189, - "line_start": 7, - "line_end": 7, - "column_start": 19, - "column_end": 53, - "is_primary": true, - "text": [ - { - "text": " let _ = (0..3).fold(true, |acc, x| acc && x > 2);", - "highlight_start": 19, - "highlight_end": 53 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "try", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/fold-any.rs", - "byte_start": 155, - "byte_end": 189, - "line_start": 7, - "line_end": 7, - "column_start": 19, - "column_end": 53, - "is_primary": true, - "text": [ - { - "text": " let _ = (0..3).fold(true, |acc, x| acc && x > 2);", - "highlight_start": 19, - "highlight_end": 53 - } - ], - "label": null, - "suggested_replacement": ".all(|x| x > 2)", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: this `.fold` can be written more succinctly using another method\n --> ./tests/fixtures/fold-any.rs:7:19\n |\n7 | let _ = (0..3).fold(true, |acc, x| acc && x > 2);\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.all(|x| x > 2)`\n\n" -} diff --git a/tests/fixtures/fold-any.rs b/tests/fixtures/fold-any.rs deleted file mode 100644 index acaae4f..0000000 --- a/tests/fixtures/fold-any.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - let _ = (0..3).fold(false, |acc, x| acc || x > 2); - - let _ = (0..3) - .fold(false, |acc, x| { acc || x > 2 }); - - let _ = (0..3).fold(true, |acc, x| acc && x > 2); -} diff --git a/tests/fixtures/needless_borrow.fixed.rs b/tests/fixtures/needless_borrow.fixed.rs deleted file mode 100644 index 546b6bb..0000000 --- a/tests/fixtures/needless_borrow.fixed.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let _x: &i32 = &&&&&5; - - struct Foo; - fn foo(_x: &Foo) { } - - let x = &Foo; - foo(x); -} diff --git a/tests/fixtures/needless_borrow.json b/tests/fixtures/needless_borrow.json deleted file mode 100644 index 0ef5ab3..0000000 --- a/tests/fixtures/needless_borrow.json +++ /dev/null @@ -1,132 +0,0 @@ -{ - "message": "this expression borrows a reference that is immediately dereferenced by the compiler", - "code": { - "code": "needless_borrow", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/needless_borrow.rs", - "byte_start": 31, - "byte_end": 38, - "line_start": 2, - "line_end": 2, - "column_start": 20, - "column_end": 27, - "is_primary": true, - "text": [ - { - "text": " let _x: &i32 = &&&&&&5;", - "highlight_start": 20, - "highlight_end": 27 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "#[warn(needless_borrow)] on by default", - "code": null, - "level": "note", - "spans": [], - "children": [], - "rendered": null - }, - { - "message": "change this to", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/needless_borrow.rs", - "byte_start": 31, - "byte_end": 38, - "line_start": 2, - "line_end": 2, - "column_start": 20, - "column_end": 27, - "is_primary": true, - "text": [ - { - "text": " let _x: &i32 = &&&&&&5;", - "highlight_start": 20, - "highlight_end": 27 - } - ], - "label": null, - "suggested_replacement": "&&&&&5", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: this expression borrows a reference that is immediately dereferenced by the compiler\n --> ./tests/fixtures/needless_borrow.rs:2:20\n |\n2 | let _x: &i32 = &&&&&&5;\n | ^^^^^^^ help: change this to: `&&&&&5`\n |\n = note: #[warn(needless_borrow)] on by default\n\n" -} -{ - "message": "this expression borrows a reference that is immediately dereferenced by the compiler", - "code": { - "code": "needless_borrow", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/needless_borrow.rs", - "byte_start": 109, - "byte_end": 111, - "line_start": 8, - "line_end": 8, - "column_start": 9, - "column_end": 11, - "is_primary": true, - "text": [ - { - "text": " foo(&x);", - "highlight_start": 9, - "highlight_end": 11 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "change this to", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/needless_borrow.rs", - "byte_start": 109, - "byte_end": 111, - "line_start": 8, - "line_end": 8, - "column_start": 9, - "column_end": 11, - "is_primary": true, - "text": [ - { - "text": " foo(&x);", - "highlight_start": 9, - "highlight_end": 11 - } - ], - "label": null, - "suggested_replacement": "x", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: this expression borrows a reference that is immediately dereferenced by the compiler\n --> ./tests/fixtures/needless_borrow.rs:8:9\n |\n8 | foo(&x);\n | ^^ help: change this to: `x`\n\n" -} diff --git a/tests/fixtures/needless_borrow.rs b/tests/fixtures/needless_borrow.rs deleted file mode 100644 index b24668c..0000000 --- a/tests/fixtures/needless_borrow.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let _x: &i32 = &&&&&&5; - - struct Foo; - fn foo(_x: &Foo) { } - - let x = &Foo; - foo(&x); -} diff --git a/tests/fixtures/redundant_closure_call.fixed.rs b/tests/fixtures/redundant_closure_call.fixed.rs deleted file mode 100644 index 00cc55f..0000000 --- a/tests/fixtures/redundant_closure_call.fixed.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[allow(unused_variables)] -fn main() { - let a = 42; - - let b = 42; - - let c = "x"; -} diff --git a/tests/fixtures/redundant_closure_call.json b/tests/fixtures/redundant_closure_call.json deleted file mode 100644 index ecc6030..0000000 --- a/tests/fixtures/redundant_closure_call.json +++ /dev/null @@ -1,214 +0,0 @@ -{ - "message": "Try not to call a closure in the expression where it is declared.", - "code": { - "code": "redundant_closure_call", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/redundant_closure_call.rs", - "byte_start": 51, - "byte_end": 60, - "line_start": 3, - "line_end": 3, - "column_start": 13, - "column_end": 22, - "is_primary": true, - "text": [ - { - "text": " let a = (|| 42)();", - "highlight_start": 13, - "highlight_end": 22 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "#[warn(redundant_closure_call)] on by default", - "code": null, - "level": "note", - "spans": [], - "children": [], - "rendered": null - }, - { - "message": "Try doing something like: ", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/redundant_closure_call.rs", - "byte_start": 51, - "byte_end": 60, - "line_start": 3, - "line_end": 3, - "column_start": 13, - "column_end": 22, - "is_primary": true, - "text": [ - { - "text": " let a = (|| 42)();", - "highlight_start": 13, - "highlight_end": 22 - } - ], - "label": null, - "suggested_replacement": "42", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: Try not to call a closure in the expression where it is declared.\n --> ./tests/fixtures/redundant_closure_call.rs:3:13\n |\n3 | let a = (|| 42)();\n | ^^^^^^^^^ help: Try doing something like: : `42`\n |\n = note: #[warn(redundant_closure_call)] on by default\n\n" -} -{ - "message": "Try not to call a closure in the expression where it is declared.", - "code": { - "code": "redundant_closure_call", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/redundant_closure_call.rs", - "byte_start": 75, - "byte_end": 97, - "line_start": 5, - "line_end": 7, - "column_start": 13, - "column_end": 8, - "is_primary": true, - "text": [ - { - "text": " let b = (||", - "highlight_start": 13, - "highlight_end": 16 - }, - { - "text": " 42", - "highlight_start": 1, - "highlight_end": 11 - }, - { - "text": " )();", - "highlight_start": 1, - "highlight_end": 8 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "Try doing something like: ", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/redundant_closure_call.rs", - "byte_start": 75, - "byte_end": 97, - "line_start": 5, - "line_end": 7, - "column_start": 13, - "column_end": 8, - "is_primary": true, - "text": [ - { - "text": " let b = (||", - "highlight_start": 13, - "highlight_end": 16 - }, - { - "text": " 42", - "highlight_start": 1, - "highlight_end": 11 - }, - { - "text": " )();", - "highlight_start": 1, - "highlight_end": 8 - } - ], - "label": null, - "suggested_replacement": "42", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: Try not to call a closure in the expression where it is declared.\n --> ./tests/fixtures/redundant_closure_call.rs:5:13\n |\n5 | let b = (||\n | _____________^\n6 | | 42\n7 | | )();\n | |_______^ help: Try doing something like: : `42`\n\n" -} -{ - "message": "Try not to call a closure in the expression where it is declared.", - "code": { - "code": "redundant_closure_call", - "explanation": null - }, - "level": "warning", - "spans": [ - { - "file_name": "./tests/fixtures/redundant_closure_call.rs", - "byte_start": 112, - "byte_end": 122, - "line_start": 9, - "line_end": 9, - "column_start": 13, - "column_end": 23, - "is_primary": true, - "text": [ - { - "text": " let c = (|| \"x\")();", - "highlight_start": 13, - "highlight_end": 23 - } - ], - "label": null, - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "Try doing something like: ", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/fixtures/redundant_closure_call.rs", - "byte_start": 112, - "byte_end": 122, - "line_start": 9, - "line_end": 9, - "column_start": 13, - "column_end": 23, - "is_primary": true, - "text": [ - { - "text": " let c = (|| \"x\")();", - "highlight_start": 13, - "highlight_end": 23 - } - ], - "label": null, - "suggested_replacement": "\"x\"", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "warning: Try not to call a closure in the expression where it is declared.\n --> ./tests/fixtures/redundant_closure_call.rs:9:13\n |\n9 | let c = (|| \"x\")();\n | ^^^^^^^^^^ help: Try doing something like: : `\"x\"`\n\n" -} diff --git a/tests/fixtures/redundant_closure_call.rs b/tests/fixtures/redundant_closure_call.rs deleted file mode 100644 index 1ed4268..0000000 --- a/tests/fixtures/redundant_closure_call.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[allow(unused_variables)] -fn main() { - let a = (|| 42)(); - - let b = (|| - 42 - )(); - - let c = (|| "x")(); -}