From 81737bf85062509dbd2bd80f917aac786dd9642f Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Mon, 2 May 2022 11:31:39 +0200 Subject: [PATCH 1/4] try reading rust-version from Cargo.toml Cargo.toml can contain a field `rust-version`, that acts like a MSRV of clippy.toml file: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field This will try to read that field and use it, if the clippy.toml config has no `msrv` entry --- clippy_lints/src/lib.rs | 50 ++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 078df64a1e1f4..b6ff9bcb76d9e 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -52,6 +52,7 @@ extern crate clippy_utils; use clippy_utils::parse_msrv; use rustc_data_structures::fx::FxHashSet; use rustc_lint::LintId; +use rustc_semver::RustcVersion; use rustc_session::Session; /// Macro used to declare a Clippy lint. @@ -450,6 +451,39 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv })); } +fn read_msrv(conf: &Conf, sess: &Session) -> Option { + let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION") + .ok() + .and_then(|v| parse_msrv(&v, None, None)); + let clippy_msrv = conf.msrv.as_ref().and_then(|s| { + parse_msrv(s, None, None).or_else(|| { + sess.err(&format!( + "error reading Clippy's configuration file. `{}` is not a valid Rust version", + s + )); + None + }) + }); + + if let Some(cargo_msrv) = cargo_msrv { + if let Some(clippy_msrv) = clippy_msrv { + // if both files have an msrv, let's compare them and emit a warning if they differ + if clippy_msrv != cargo_msrv { + sess.warn(&format!( + "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{}` from `clippy.toml`", + clippy_msrv + )); + } + + Some(clippy_msrv) + } else { + Some(cargo_msrv) + } + } else { + clippy_msrv + } +} + #[doc(hidden)] pub fn read_conf(sess: &Session) -> Conf { let file_name = match utils::conf::lookup_conf_file() { @@ -465,12 +499,11 @@ pub fn read_conf(sess: &Session) -> Conf { let TryConf { conf, errors } = utils::conf::read(&file_name); // all conf errors are non-fatal, we just use the default conf in case of error for error in errors { - sess.struct_err(&format!( + sess.err(&format!( "error reading Clippy's configuration file `{}`: {}", file_name.display(), format_error(error) - )) - .emit(); + )); } conf @@ -577,16 +610,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions)); store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports)); - let msrv = conf.msrv.as_ref().and_then(|s| { - parse_msrv(s, None, None).or_else(|| { - sess.err(&format!( - "error reading Clippy's configuration file. `{}` is not a valid Rust version", - s - )); - None - }) - }); - + let msrv = read_msrv(conf, sess); let avoid_breaking_exported_api = conf.avoid_breaking_exported_api; let allow_expect_in_tests = conf.allow_expect_in_tests; let allow_unwrap_in_tests = conf.allow_unwrap_in_tests; From 83511d1d9a98b9506df710fb5bba3c20f57e8c85 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Tue, 10 May 2022 13:09:28 +0200 Subject: [PATCH 2/4] update README.md to reflect rust-version in cargo.toml --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index edbc626e354b5..136bf22ee42d6 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,14 @@ specifying the minimum supported Rust version (MSRV) in the clippy configuration msrv = "1.30.0" ``` +Alternatively, the [`rust-version` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field) +in the `Cargo.toml` can be used. + +```toml +# Cargo.toml +rust-version = "1.30" +``` + The MSRV can also be specified as an inner attribute, like below. ```rust From 63847656655bda9fe3cb822b6f99d0268fabde03 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Mon, 27 Jun 2022 11:11:52 +0200 Subject: [PATCH 3/4] parse `Cargo.toml` file in ui-cargo tests compiletest_rs is not meant to test full cargo projects, but instead only files. So we need to parse the `Cargo.toml` file ourself and set the corresponding environment variable. In this case we just set `CARGO_PKG_RUST_VERSION`, nothing more. But, of course, this can be extended. --- Cargo.toml | 1 + tests/compile-test.rs | 20 ++++++++++++++++++- .../warn/src/main.stderr | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 42455998fe790..fa4dd123ee9a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ termize = "0.1" compiletest_rs = { version = "0.8", features = ["tmp"] } tester = "0.9" regex = "1.5" +toml = "0.5" # This is used by the `collect-metadata` alias. filetime = "0.2" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index a303d90d953ed..319256814c3a6 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -130,7 +130,7 @@ fn base_config(test_dir: &str) -> compiletest::Config { let mut config = compiletest::Config { edition: Some("2021".into()), mode: TestMode::Ui, - ..compiletest::Config::default() + ..Default::default() }; if let Ok(filters) = env::var("TESTNAME") { @@ -286,6 +286,24 @@ fn run_ui_cargo() { } env::set_current_dir(&src_path)?; + + let cargo_toml_path = case.path().join("Cargo.toml"); + let cargo_content = fs::read(&cargo_toml_path)?; + let cargo_parsed: toml::Value = toml::from_str( + std::str::from_utf8(&cargo_content).expect("`Cargo.toml` is not a valid utf-8 file!"), + ) + .expect("Can't parse `Cargo.toml`"); + + let _g = VarGuard::set("CARGO_MANIFEST_DIR", case.path()); + let _h = VarGuard::set( + "CARGO_PKG_RUST_VERSION", + cargo_parsed + .get("package") + .and_then(|p| p.get("rust-version")) + .and_then(toml::Value::as_str) + .unwrap_or(""), + ); + for file in fs::read_dir(&src_path)? { let file = file?; if file.file_type()?.is_dir() { diff --git a/tests/ui-cargo/multiple_config_files/warn/src/main.stderr b/tests/ui-cargo/multiple_config_files/warn/src/main.stderr index 2abb4e3e06e64..98697e001f99a 100644 --- a/tests/ui-cargo/multiple_config_files/warn/src/main.stderr +++ b/tests/ui-cargo/multiple_config_files/warn/src/main.stderr @@ -1,2 +1,2 @@ -Using config file `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/.clippy.toml` -Warning: `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/clippy.toml` will be ignored. +Using config file `$SRC_DIR/.clippy.toml` +Warning: `$SRC_DIR/clippy.toml` will be ignored. From f0a1cd5645d6b72a621c8a80eebe72d363c00a4e Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Tue, 10 May 2022 14:46:05 +0200 Subject: [PATCH 4/4] add uitests for cargo rust-version field --- .../cargo_rust_version/fail_both_diff/Cargo.toml | 8 ++++++++ .../fail_both_diff/clippy.toml | 1 + .../fail_both_diff/src/main.rs | 11 +++++++++++ .../fail_both_diff/src/main.stderr | 16 ++++++++++++++++ .../cargo_rust_version/fail_both_same/Cargo.toml | 8 ++++++++ .../fail_both_same/clippy.toml | 1 + .../fail_both_same/src/main.rs | 11 +++++++++++ .../fail_both_same/src/main.stderr | 14 ++++++++++++++ .../cargo_rust_version/fail_cargo/Cargo.toml | 8 ++++++++ .../cargo_rust_version/fail_cargo/src/main.rs | 11 +++++++++++ .../fail_cargo/src/main.stderr | 14 ++++++++++++++ .../cargo_rust_version/fail_clippy/Cargo.toml | 7 +++++++ .../cargo_rust_version/fail_clippy/clippy.toml | 1 + .../cargo_rust_version/fail_clippy/src/main.rs | 11 +++++++++++ .../fail_clippy/src/main.stderr | 14 ++++++++++++++ .../cargo_rust_version/fail_file_attr/Cargo.toml | 8 ++++++++ .../fail_file_attr/clippy.toml | 1 + .../fail_file_attr/src/main.rs | 16 ++++++++++++++++ .../fail_file_attr/src/main.stderr | 14 ++++++++++++++ .../cargo_rust_version/pass_both_same/Cargo.toml | 8 ++++++++ .../pass_both_same/clippy.toml | 1 + .../pass_both_same/src/main.rs | 11 +++++++++++ .../cargo_rust_version/pass_cargo/Cargo.toml | 8 ++++++++ .../cargo_rust_version/pass_cargo/src/main.rs | 11 +++++++++++ .../cargo_rust_version/pass_clippy/Cargo.toml | 7 +++++++ .../cargo_rust_version/pass_clippy/clippy.toml | 1 + .../cargo_rust_version/pass_clippy/src/main.rs | 11 +++++++++++ .../cargo_rust_version/pass_file_attr/Cargo.toml | 8 ++++++++ .../pass_file_attr/src/main.rs | 13 +++++++++++++ .../cargo_rust_version/warn_both_diff/Cargo.toml | 8 ++++++++ .../warn_both_diff/clippy.toml | 1 + .../warn_both_diff/src/main.rs | 11 +++++++++++ .../warn_both_diff/src/main.stderr | 4 ++++ 33 files changed, 278 insertions(+) create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/clippy.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.stderr create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/clippy.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.stderr create mode 100644 tests/ui-cargo/cargo_rust_version/fail_cargo/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.stderr create mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/clippy.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.stderr create mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/clippy.toml create mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.stderr create mode 100644 tests/ui-cargo/cargo_rust_version/pass_both_same/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/pass_both_same/clippy.toml create mode 100644 tests/ui-cargo/cargo_rust_version/pass_both_same/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/pass_cargo/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/pass_cargo/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/pass_clippy/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/pass_clippy/clippy.toml create mode 100644 tests/ui-cargo/cargo_rust_version/pass_clippy/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/pass_file_attr/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/pass_file_attr/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/Cargo.toml create mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/clippy.toml create mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.rs create mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.stderr diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_diff/Cargo.toml b/tests/ui-cargo/cargo_rust_version/fail_both_diff/Cargo.toml new file mode 100644 index 0000000000000..73ec29c5803bd --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_diff/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fail-both-diff" +version = "0.1.0" +rust-version = "1.56" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_diff/clippy.toml b/tests/ui-cargo/cargo_rust_version/fail_both_diff/clippy.toml new file mode 100644 index 0000000000000..abe19b3a00710 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_diff/clippy.toml @@ -0,0 +1 @@ +msrv = "1.59" diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.rs b/tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.stderr b/tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.stderr new file mode 100644 index 0000000000000..9a7d802dc6d3a --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.stderr @@ -0,0 +1,16 @@ +warning: the MSRV in `clippy.toml` and `Cargo.toml` differ; using `1.59.0` from `clippy.toml` + +error: unnecessary structure name repetition + --> $DIR/main.rs:6:21 + | +LL | pub fn bar() -> Foo { + | ^^^ help: use the applicable keyword: `Self` + | +note: the lint level is defined here + --> $DIR/main.rs:1:9 + | +LL | #![deny(clippy::use_self)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error; 1 warning emitted + diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_same/Cargo.toml b/tests/ui-cargo/cargo_rust_version/fail_both_same/Cargo.toml new file mode 100644 index 0000000000000..2d6d547e4fe3a --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_same/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fail-both-same" +version = "0.1.0" +rust-version = "1.57.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_same/clippy.toml b/tests/ui-cargo/cargo_rust_version/fail_both_same/clippy.toml new file mode 100644 index 0000000000000..5cccb362c1421 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_same/clippy.toml @@ -0,0 +1 @@ +msrv = "1.57" diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.rs b/tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.stderr b/tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.stderr new file mode 100644 index 0000000000000..a280e1bacdfdc --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.stderr @@ -0,0 +1,14 @@ +error: unnecessary structure name repetition + --> $DIR/main.rs:6:21 + | +LL | pub fn bar() -> Foo { + | ^^^ help: use the applicable keyword: `Self` + | +note: the lint level is defined here + --> $DIR/main.rs:1:9 + | +LL | #![deny(clippy::use_self)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui-cargo/cargo_rust_version/fail_cargo/Cargo.toml b/tests/ui-cargo/cargo_rust_version/fail_cargo/Cargo.toml new file mode 100644 index 0000000000000..36a53bd829d9e --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_cargo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fail-cargo" +version = "0.1.0" +rust-version = "1.56.1" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.rs b/tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.stderr b/tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.stderr new file mode 100644 index 0000000000000..a280e1bacdfdc --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.stderr @@ -0,0 +1,14 @@ +error: unnecessary structure name repetition + --> $DIR/main.rs:6:21 + | +LL | pub fn bar() -> Foo { + | ^^^ help: use the applicable keyword: `Self` + | +note: the lint level is defined here + --> $DIR/main.rs:1:9 + | +LL | #![deny(clippy::use_self)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui-cargo/cargo_rust_version/fail_clippy/Cargo.toml b/tests/ui-cargo/cargo_rust_version/fail_clippy/Cargo.toml new file mode 100644 index 0000000000000..9f644a1a39a50 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_clippy/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "fail-clippy" +version = "0.1.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/fail_clippy/clippy.toml b/tests/ui-cargo/cargo_rust_version/fail_clippy/clippy.toml new file mode 100644 index 0000000000000..ddbdbc1fa2590 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_clippy/clippy.toml @@ -0,0 +1 @@ +msrv = "1.58" diff --git a/tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.rs b/tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.stderr b/tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.stderr new file mode 100644 index 0000000000000..a280e1bacdfdc --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.stderr @@ -0,0 +1,14 @@ +error: unnecessary structure name repetition + --> $DIR/main.rs:6:21 + | +LL | pub fn bar() -> Foo { + | ^^^ help: use the applicable keyword: `Self` + | +note: the lint level is defined here + --> $DIR/main.rs:1:9 + | +LL | #![deny(clippy::use_self)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui-cargo/cargo_rust_version/fail_file_attr/Cargo.toml b/tests/ui-cargo/cargo_rust_version/fail_file_attr/Cargo.toml new file mode 100644 index 0000000000000..5380e993b2936 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_file_attr/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fail-file-attr" +version = "0.1.0" +rust-version = "1.13" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/fail_file_attr/clippy.toml b/tests/ui-cargo/cargo_rust_version/fail_file_attr/clippy.toml new file mode 100644 index 0000000000000..ea5d806594b5e --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_file_attr/clippy.toml @@ -0,0 +1 @@ +msrv = "1.13.0" diff --git a/tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.rs b/tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.rs new file mode 100644 index 0000000000000..bcbffa82a5417 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.rs @@ -0,0 +1,16 @@ +// FIXME: this should produce a warning, because the attribute says 1.58 and the cargo.toml file +// says 1.13 + +#![feature(custom_inner_attributes)] +#![clippy::msrv = "1.58.0"] +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.stderr b/tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.stderr new file mode 100644 index 0000000000000..88f6e00922bc4 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.stderr @@ -0,0 +1,14 @@ +error: unnecessary structure name repetition + --> $DIR/main.rs:11:21 + | +LL | pub fn bar() -> Foo { + | ^^^ help: use the applicable keyword: `Self` + | +note: the lint level is defined here + --> $DIR/main.rs:6:9 + | +LL | #![deny(clippy::use_self)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui-cargo/cargo_rust_version/pass_both_same/Cargo.toml b/tests/ui-cargo/cargo_rust_version/pass_both_same/Cargo.toml new file mode 100644 index 0000000000000..1f9bd8f9a84e3 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_both_same/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fail-both-same" +version = "0.1.0" +rust-version = "1.13.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/pass_both_same/clippy.toml b/tests/ui-cargo/cargo_rust_version/pass_both_same/clippy.toml new file mode 100644 index 0000000000000..5e8e48b636b63 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_both_same/clippy.toml @@ -0,0 +1 @@ +msrv = "1.13" diff --git a/tests/ui-cargo/cargo_rust_version/pass_both_same/src/main.rs b/tests/ui-cargo/cargo_rust_version/pass_both_same/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_both_same/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/pass_cargo/Cargo.toml b/tests/ui-cargo/cargo_rust_version/pass_cargo/Cargo.toml new file mode 100644 index 0000000000000..77538027c0f87 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_cargo/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fail-cargo" +version = "0.1.0" +rust-version = "1.13.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/pass_cargo/src/main.rs b/tests/ui-cargo/cargo_rust_version/pass_cargo/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_cargo/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/pass_clippy/Cargo.toml b/tests/ui-cargo/cargo_rust_version/pass_clippy/Cargo.toml new file mode 100644 index 0000000000000..9f644a1a39a50 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_clippy/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "fail-clippy" +version = "0.1.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/pass_clippy/clippy.toml b/tests/ui-cargo/cargo_rust_version/pass_clippy/clippy.toml new file mode 100644 index 0000000000000..5e8e48b636b63 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_clippy/clippy.toml @@ -0,0 +1 @@ +msrv = "1.13" diff --git a/tests/ui-cargo/cargo_rust_version/pass_clippy/src/main.rs b/tests/ui-cargo/cargo_rust_version/pass_clippy/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_clippy/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/pass_file_attr/Cargo.toml b/tests/ui-cargo/cargo_rust_version/pass_file_attr/Cargo.toml new file mode 100644 index 0000000000000..f0387cd90b80f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_file_attr/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fail-file-attr" +version = "0.1.0" +rust-version = "1.59" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/pass_file_attr/src/main.rs b/tests/ui-cargo/cargo_rust_version/pass_file_attr/src/main.rs new file mode 100644 index 0000000000000..27fe4771d2d6b --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/pass_file_attr/src/main.rs @@ -0,0 +1,13 @@ +#![feature(custom_inner_attributes)] +#![clippy::msrv = "1.13.0"] +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/warn_both_diff/Cargo.toml b/tests/ui-cargo/cargo_rust_version/warn_both_diff/Cargo.toml new file mode 100644 index 0000000000000..a19d5b33fe563 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/warn_both_diff/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "warn-both-diff" +version = "0.1.0" +rust-version = "1.56.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/ui-cargo/cargo_rust_version/warn_both_diff/clippy.toml b/tests/ui-cargo/cargo_rust_version/warn_both_diff/clippy.toml new file mode 100644 index 0000000000000..5e8e48b636b63 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/warn_both_diff/clippy.toml @@ -0,0 +1 @@ +msrv = "1.13" diff --git a/tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.rs b/tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.rs new file mode 100644 index 0000000000000..5b91d5508678f --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.rs @@ -0,0 +1,11 @@ +#![deny(clippy::use_self)] + +pub struct Foo; + +impl Foo { + pub fn bar() -> Foo { + Foo + } +} + +fn main() {} diff --git a/tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.stderr b/tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.stderr new file mode 100644 index 0000000000000..eeae5b7b275e9 --- /dev/null +++ b/tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.stderr @@ -0,0 +1,4 @@ +warning: the MSRV in `clippy.toml` and `Cargo.toml` differ; using `1.13.0` from `clippy.toml` + +warning: 1 warning emitted +