Skip to content

Commit 0fa1fd3

Browse files
committed
Auto merge of #11183 - Alexendoo:new-lint-template, r=xFrednet
Remove `#![allow(unused)]` and `--crate-name` from `cargo dev new_lint` generated tests changelog: none Also removes some unused flags from `ui-cargo` tests because the entrypoint is now the `Cargo.toml`, not the `.rs` files
2 parents 3dd6af9 + f539e1a commit 0fa1fd3

File tree

15 files changed

+6
-26
lines changed

15 files changed

+6
-26
lines changed

clippy_dev/src/new_lint.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
9696

9797
path.push("src");
9898
fs::create_dir(&path)?;
99-
let header = format!("//@compile-flags: --crate-name={lint_name}");
100-
write_file(path.join("main.rs"), get_test_file_contents(lint_name, Some(&header)))?;
99+
write_file(path.join("main.rs"), get_test_file_contents(lint_name))?;
101100

102101
Ok(())
103102
}
@@ -113,7 +112,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
113112
println!("Generated test directories: `{relative_test_dir}/pass`, `{relative_test_dir}/fail`");
114113
} else {
115114
let test_path = format!("tests/ui/{}.rs", lint.name);
116-
let test_contents = get_test_file_contents(lint.name, None);
115+
let test_contents = get_test_file_contents(lint.name);
117116
write_file(lint.project_root.join(&test_path), test_contents)?;
118117

119118
println!("Generated test file: `{test_path}`");
@@ -195,23 +194,16 @@ pub(crate) fn get_stabilization_version() -> String {
195194
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
196195
}
197196

198-
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
199-
let mut contents = formatdoc!(
197+
fn get_test_file_contents(lint_name: &str) -> String {
198+
formatdoc!(
200199
r#"
201-
#![allow(unused)]
202200
#![warn(clippy::{lint_name})]
203201
204202
fn main() {{
205203
// test code goes here
206204
}}
207205
"#
208-
);
209-
210-
if let Some(header) = header_commands {
211-
contents = format!("{header}\n{contents}");
212-
}
213-
214-
contents
206+
)
215207
}
216208

217209
fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=cargo_common_metadata
21
#![warn(clippy::cargo_common_metadata)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=cargo_common_metadata
21
#![warn(clippy::cargo_common_metadata)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=cargo_common_metadata
21
#![warn(clippy::cargo_common_metadata)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=cargo_common_metadata
21
#![warn(clippy::cargo_common_metadata)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=cargo_common_metadata
21
#![warn(clippy::cargo_common_metadata)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=cargo_common_metadata
21
#![warn(clippy::cargo_common_metadata)]
32

43
fn main() {}

tests/ui-cargo/feature_name/fail/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=feature_name
21
#![warn(clippy::redundant_feature_names)]
32
#![warn(clippy::negative_feature_names)]
43

tests/ui-cargo/feature_name/pass/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=feature_name
21
#![warn(clippy::redundant_feature_names)]
32
#![warn(clippy::negative_feature_names)]
43

tests/ui-cargo/module_style/fail_mod_remap/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIXME: find a way to add rustflags to ui-cargo tests
12
//@compile-flags: --remap-path-prefix {{src-base}}=/remapped
23

34
#![warn(clippy::self_named_module_files)]
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=multiple_crate_versions
21
#![warn(clippy::multiple_crate_versions)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=multiple_crate_versions
21
#![warn(clippy::multiple_crate_versions)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=multiple_crate_versions
21
#![warn(clippy::multiple_crate_versions)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=wildcard_dependencies
21
#![warn(clippy::wildcard_dependencies)]
32

43
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@compile-flags: --crate-name=wildcard_dependencies
21
#![warn(clippy::wildcard_dependencies)]
32

43
fn main() {}

0 commit comments

Comments
 (0)