Auto merge of #10426 - oli-obk:ui_test, r=Manishearth

Port clippy away from compiletest to ui_test

Reasons to do this:

* runs completely on stable Rust
* is easier to extend with new features
* has its own dogfood test suite, so changes can be tested in [the `ui_test` repo](https://github.com/oli-obk/ui_test)
* supports dependencies from crates.io without having to manually fiddle with command line flags
* supports `ui-cargo`, `ui`, `ui-toml` out of the box, no need to find and run the tests ourselves

One thing that is a big difference to `compiletest` is that if a test emits *any* error, you need to mark all of them with `//~ ERROR:` annotations. Since many clippy tests did not have annotations, I changed many lints to be `warn` in their test so that only the `stderr` output is tested.

TODO:

* [ ] check that this still works as a subtree in the rustc repo

changelog: none
<!-- changelog_checked -->

Note: at present the latest changes needed for clippy are only available as a git dependency, but I expect to publish a new crates.io version soon
This commit is contained in:
bors 2023-06-26 17:32:51 +00:00
commit 15ed281699
272 changed files with 1949 additions and 1455 deletions

View File

@ -1,5 +1,7 @@
[alias]
uitest = "test --test compile-test"
uibless = "test --test compile-test -- -- --bless"
bless = "test -- -- --bless"
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored"

View File

@ -27,27 +27,14 @@ tempfile = { version = "3.2", optional = true }
termize = "0.1"
[dev-dependencies]
compiletest_rs = { version = "0.10", features = ["tmp"] }
ui_test = "0.11.5"
tester = "0.9"
regex = "1.5"
toml = "0.7.3"
walkdir = "2.3"
# This is used by the `collect-metadata` alias.
filetime = "0.2"
# UI test dependencies
clap = { version = "4.1.4", features = ["derive"] }
clippy_utils = { path = "clippy_utils" }
derive-new = "0.5"
if_chain = "1.0"
itertools = "0.10.1"
quote = "1.0"
serde = { version = "1.0.125", features = ["derive"] }
syn = { version = "2.0", features = ["full"] }
futures = "0.3"
parking_lot = "0.12"
tokio = { version = "1", features = ["io-util"] }
rustc-semver = "1.1"
[build-dependencies]
rustc_tools_util = "0.3.0"
@ -60,3 +47,7 @@ internal = ["clippy_lints/internal", "tempfile"]
[package.metadata.rust-analyzer]
# This package uses #[feature(rustc_private)]
rustc_private = true
[[test]]
name = "compile-test"
harness = false

View File

@ -122,20 +122,17 @@ fn main() {
}
```
Now we can run the test with `TESTNAME=foo_functions cargo uitest`, currently
Now we can run the test with `TESTNAME=foo_functions cargo uibless`, currently
this test is meaningless though.
While we are working on implementing our lint, we can keep running the UI test.
That allows us to check if the output is turning into what we want.
That allows us to check if the output is turning into what we want by checking the
`.stderr` file that gets updated on every test run.
Once we are satisfied with the output, we need to run `cargo dev bless` to
update the `.stderr` file for our lint. Please note that, we should run
`TESTNAME=foo_functions cargo uitest` every time before running `cargo dev
bless`. Running `TESTNAME=foo_functions cargo uitest` should pass then. When we
Running `TESTNAME=foo_functions cargo uitest` should pass on its own. When we
commit our lint, we need to commit the generated `.stderr` files, too. In
general, you should only commit files changed by `cargo dev bless` for the
specific lint you are creating/editing. Note that if the generated files are
empty, they should be removed.
general, you should only commit files changed by `cargo bless` for the
specific lint you are creating/editing.
> _Note:_ you can run multiple test files by specifying a comma separated list:
> `TESTNAME=foo_functions,test2,test3`.
@ -169,7 +166,7 @@ additionally run [rustfix] for that test. Rustfix will apply the suggestions
from the lint to the code of the test file and compare that to the contents of a
`.fixed` file.
Use `cargo dev bless` to automatically generate the `.fixed` file after running
Use `cargo bless` to automatically generate the `.fixed` file while running
the tests.
[rustfix]: https://github.com/rust-lang/rustfix

View File

@ -66,7 +66,7 @@ If the output of a [UI test] differs from the expected output, you can update
the reference file with:
```bash
cargo dev bless
cargo bless
```
For example, this is necessary if you fix a typo in an error message of a lint,

View File

@ -1,60 +0,0 @@
//! `bless` updates the reference files in the repo with changed output files
//! from the last test run.
use crate::cargo_clippy_path;
use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use walkdir::{DirEntry, WalkDir};
static CLIPPY_BUILD_TIME: LazyLock<Option<std::time::SystemTime>> =
LazyLock::new(|| cargo_clippy_path().metadata().ok()?.modified().ok());
/// # Panics
///
/// Panics if the path to a test file is broken
pub fn bless(ignore_timestamp: bool) {
let extensions = ["stdout", "stderr", "fixed"].map(OsStr::new);
WalkDir::new(build_dir())
.into_iter()
.map(Result::unwrap)
.filter(|entry| entry.path().extension().map_or(false, |ext| extensions.contains(&ext)))
.for_each(|entry| update_reference_file(&entry, ignore_timestamp));
}
fn update_reference_file(test_output_entry: &DirEntry, ignore_timestamp: bool) {
let test_output_path = test_output_entry.path();
let reference_file_name = test_output_entry.file_name().to_str().unwrap().replace(".stage-id", "");
let reference_file_path = Path::new("tests")
.join(test_output_path.strip_prefix(build_dir()).unwrap())
.with_file_name(reference_file_name);
// If the test output was not updated since the last clippy build, it may be outdated
if !ignore_timestamp && !updated_since_clippy_build(test_output_entry).unwrap_or(true) {
return;
}
let test_output_file = fs::read(test_output_path).expect("Unable to read test output file");
let reference_file = fs::read(&reference_file_path).unwrap_or_default();
if test_output_file != reference_file {
// If a test run caused an output file to change, update the reference file
println!("updating {}", reference_file_path.display());
fs::copy(test_output_path, &reference_file_path).expect("Could not update reference file");
}
}
fn updated_since_clippy_build(entry: &DirEntry) -> Option<bool> {
let clippy_build_time = (*CLIPPY_BUILD_TIME)?;
let modified = entry.metadata().ok()?.modified().ok()?;
Some(modified >= clippy_build_time)
}
fn build_dir() -> PathBuf {
let mut path = std::env::current_exe().unwrap();
path.set_file_name("test");
path
}

View File

@ -14,7 +14,6 @@ use std::io;
use std::path::PathBuf;
use std::process::{self, ExitStatus};
pub mod bless;
pub mod dogfood;
pub mod fmt;
pub mod lint;

View File

@ -3,7 +3,7 @@
#![warn(rust_2018_idioms, unused_lifetimes)]
use clap::{Arg, ArgAction, ArgMatches, Command};
use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, update_lints};
use indoc::indoc;
use std::convert::Infallible;
@ -11,8 +11,8 @@ fn main() {
let matches = get_clap_config();
match matches.subcommand() {
Some(("bless", matches)) => {
bless::bless(matches.get_flag("ignore-timestamp"));
Some(("bless", _)) => {
eprintln!("use `cargo bless` to automatically replace `.stderr` and `.fixed` files as tests are being run");
},
Some(("dogfood", matches)) => {
dogfood::dogfood(

View File

@ -96,7 +96,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
path.push("src");
fs::create_dir(&path)?;
let header = format!("// compile-flags: --crate-name={lint_name}");
let header = format!("//@compile-flags: --crate-name={lint_name}");
write_file(path.join("main.rs"), get_test_file_contents(lint_name, Some(&header)))?;
Ok(())

View File

@ -0,0 +1,25 @@
[package]
name = "clippy_test_deps"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.1.4", features = ["derive"] }
clippy_utils = { path = "../clippy_utils" }
derive-new = "0.5"
if_chain = "1.0"
itertools = "0.10.1"
quote = "1.0"
serde = { version = "1.0.125", features = ["derive"] }
syn = { version = "2.0", features = ["full"] }
futures = "0.3"
parking_lot = "0.12"
tokio = { version = "1", features = ["io-util"] }
rustc-semver = "1.1"
regex = "1.5"
clippy_lints = { path = "../clippy_lints" }
[features]
internal = ["clippy_lints/internal"]

View File

@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View File

@ -2397,7 +2397,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol
/// Checks if the function containing the given `HirId` is a `#[test]` function
///
/// Note: Add `// compile-flags: --test` to UI tests with a `#[test]` function
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[test]` function
pub fn is_in_test_function(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
with_test_item_names(tcx, tcx.parent_module(id), |names| {
tcx.hir()
@ -2419,7 +2419,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
/// Checks if the item containing the given `HirId` has `#[cfg(test)]` attribute applied
///
/// Note: Add `// compile-flags: --test` to UI tests with a `#[cfg(test)]` function
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[cfg(test)]` function
pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
fn is_cfg_test(attr: &Attribute) -> bool {
if attr.has_name(sym::cfg)
@ -2441,7 +2441,7 @@ pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
/// Checks whether item either has `test` attribute applied, or
/// is a module with `test` in its name.
///
/// Note: Add `// compile-flags: --test` to UI tests with a `#[test]` function
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[test]` function
pub fn is_test_module_or_function(tcx: TyCtxt<'_>, item: &Item<'_>) -> bool {
is_in_test_function(tcx, item.hir_id())
|| matches!(item.kind, ItemKind::Mod(..))

View File

@ -4,16 +4,14 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2018_idioms, unused_lifetimes)]
use compiletest_rs as compiletest;
use compiletest_rs::common::Mode as TestMode;
use compiletest::{status_emitter, CommandBuilder};
use ui_test as compiletest;
use ui_test::Mode as TestMode;
use std::collections::HashMap;
use std::env::{self, remove_var, set_var, var_os};
use std::ffi::{OsStr, OsString};
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use test_utils::IS_RUSTC_TEST_SUITE;
mod test_utils;
@ -21,143 +19,41 @@ mod test_utils;
// whether to run internal tests or not
const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal");
/// All crates used in UI tests are listed here
static TEST_DEPENDENCIES: &[&str] = &[
"clippy_lints",
"clippy_utils",
"derive_new",
"futures",
"if_chain",
"itertools",
"quote",
"regex",
"serde",
"serde_derive",
"syn",
"tokio",
"parking_lot",
"rustc_semver",
];
// Test dependencies may need an `extern crate` here to ensure that they show up
// in the depinfo file (otherwise cargo thinks they are unused)
#[allow(unused_extern_crates)]
extern crate clippy_lints;
#[allow(unused_extern_crates)]
extern crate clippy_utils;
#[allow(unused_extern_crates)]
extern crate derive_new;
#[allow(unused_extern_crates)]
extern crate futures;
#[allow(unused_extern_crates)]
extern crate if_chain;
#[allow(unused_extern_crates)]
extern crate itertools;
#[allow(unused_extern_crates)]
extern crate parking_lot;
#[allow(unused_extern_crates)]
extern crate quote;
#[allow(unused_extern_crates)]
extern crate rustc_semver;
#[allow(unused_extern_crates)]
extern crate syn;
#[allow(unused_extern_crates)]
extern crate tokio;
/// Produces a string with an `--extern` flag for all UI test crate
/// dependencies.
///
/// The dependency files are located by parsing the depinfo file for this test
/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
/// dependencies must be added to Cargo.toml at the project root. Test
/// dependencies that are not *directly* used by this test module require an
/// `extern crate` declaration.
static EXTERN_FLAGS: LazyLock<String> = LazyLock::new(|| {
let current_exe_depinfo = {
let mut path = env::current_exe().unwrap();
path.set_extension("d");
fs::read_to_string(path).unwrap()
};
let mut crates: HashMap<&str, &str> = HashMap::with_capacity(TEST_DEPENDENCIES.len());
for line in current_exe_depinfo.lines() {
// each dependency is expected to have a Makefile rule like `/path/to/crate-hash.rlib:`
let parse_name_path = || {
if line.starts_with(char::is_whitespace) {
return None;
}
let path_str = line.strip_suffix(':')?;
let path = Path::new(path_str);
if !matches!(path.extension()?.to_str()?, "rlib" | "so" | "dylib" | "dll") {
return None;
}
let (name, _hash) = path.file_stem()?.to_str()?.rsplit_once('-')?;
// the "lib" prefix is not present for dll files
let name = name.strip_prefix("lib").unwrap_or(name);
Some((name, path_str))
};
if let Some((name, path)) = parse_name_path() {
if TEST_DEPENDENCIES.contains(&name) {
// A dependency may be listed twice if it is available in sysroot,
// and the sysroot dependencies are listed first. As of the writing,
// this only seems to apply to if_chain.
crates.insert(name, path);
}
}
}
let not_found: Vec<&str> = TEST_DEPENDENCIES
.iter()
.copied()
.filter(|n| !crates.contains_key(n))
.collect();
assert!(
not_found.is_empty(),
"dependencies not found in depinfo: {not_found:?}\n\
help: Make sure the `-Z binary-dep-depinfo` rust flag is enabled\n\
help: Try adding to dev-dependencies in Cargo.toml\n\
help: Be sure to also add `extern crate ...;` to tests/compile-test.rs",
);
crates
.into_iter()
.map(|(name, path)| format!(" --extern {name}={path}"))
.collect()
});
fn base_config(test_dir: &str) -> compiletest::Config {
let mut config = compiletest::Config {
edition: Some("2021".into()),
mode: TestMode::Ui,
strict_headers: true,
..Default::default()
mode: TestMode::Yolo,
stderr_filters: vec![],
stdout_filters: vec![],
output_conflict_handling: if std::env::args().any(|arg| arg == "--bless") {
compiletest::OutputConflictHandling::Bless
} else {
compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into())
},
dependencies_crate_manifest_path: Some("clippy_test_deps/Cargo.toml".into()),
target: None,
out_dir: "target/ui_test".into(),
..compiletest::Config::rustc(Path::new("tests").join(test_dir))
};
if let Ok(filters) = env::var("TESTNAME") {
config.filters = filters.split(',').map(ToString::to_string).collect();
}
if let Some(path) = option_env!("RUSTC_LIB_PATH") {
let path = PathBuf::from(path);
config.run_lib_path = path.clone();
config.compile_lib_path = path;
if let Some(_path) = option_env!("RUSTC_LIB_PATH") {
//let path = PathBuf::from(path);
//config.run_lib_path = path.clone();
//config.compile_lib_path = path;
}
let current_exe_path = env::current_exe().unwrap();
let deps_path = current_exe_path.parent().unwrap();
let profile_path = deps_path.parent().unwrap();
// Using `-L dependency={}` enforces that external dependencies are added with `--extern`.
// This is valuable because a) it allows us to monitor what external dependencies are used
// and b) it ensures that conflicting rlibs are resolved properly.
let host_libs = option_env!("HOST_LIBS")
.map(|p| format!(" -L dependency={}", Path::new(p).join("deps").display()))
.unwrap_or_default();
config.target_rustcflags = Some(format!(
"--emit=metadata -Dwarnings -Zui-testing -L dependency={}{host_libs}{}",
deps_path.display(),
&*EXTERN_FLAGS,
));
config.program.args.push("--emit=metadata".into());
config.program.args.push("-Aunused".into());
config.program.args.push("-Zui-testing".into());
config.program.args.push("-Dwarnings".into());
config.src_base = Path::new("tests").join(test_dir);
config.build_base = profile_path.join("test").join(test_dir);
config.rustc_path = profile_path.join(if cfg!(windows) {
// Normalize away slashes in windows paths.
config.stderr_filter(r#"\\"#, "/");
//config.build_base = profile_path.join("test").join(test_dir);
config.program.program = profile_path.join(if cfg!(windows) {
"clippy-driver.exe"
} else {
"clippy-driver"
@ -165,9 +61,23 @@ fn base_config(test_dir: &str) -> compiletest::Config {
config
}
fn test_filter() -> Box<dyn Sync + Fn(&Path) -> bool> {
if let Ok(filters) = env::var("TESTNAME") {
let filters: Vec<_> = filters.split(',').map(ToString::to_string).collect();
Box::new(move |path| {
filters.is_empty()
|| filters
.iter()
.any(|f| path.file_stem().map_or(false, |stem| stem == f.as_str()))
})
} else {
Box::new(|_| true)
}
}
fn run_ui() {
let mut config = base_config("ui");
config.rustfix_coverage = true;
let config = base_config("ui");
//config.rustfix_coverage = true;
// use tests/clippy.toml
let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap());
let _threads = VarGuard::set(
@ -179,7 +89,19 @@ fn run_ui() {
.to_string()
}),
);
compiletest::run_tests(&config);
eprintln!(" Compiler: {}", config.program.display());
let name = config.root_dir.display().to_string();
let test_filter = test_filter();
compiletest::run_tests_generic(
config,
move |path| compiletest::default_file_filter(path) && test_filter(path),
compiletest::default_per_file_config,
(status_emitter::Text, status_emitter::Gha::<true> { name }),
)
.unwrap();
check_rustfix_coverage();
}
@ -188,177 +110,115 @@ fn run_internal_tests() {
if !RUN_INTERNAL_TESTS {
return;
}
let config = base_config("ui-internal");
compiletest::run_tests(&config);
let mut config = base_config("ui-internal");
config.dependency_builder.args.push("--features".into());
config.dependency_builder.args.push("internal".into());
compiletest::run_tests(config).unwrap();
}
fn run_ui_toml() {
fn run_tests(config: &compiletest::Config, mut tests: Vec<tester::TestDescAndFn>) -> Result<bool, io::Error> {
let mut result = true;
let opts = compiletest::test_opts(config);
for dir in fs::read_dir(&config.src_base)? {
let dir = dir?;
if !dir.file_type()?.is_dir() {
continue;
}
let dir_path = dir.path();
let _g = VarGuard::set("CARGO_MANIFEST_DIR", &dir_path);
for file in fs::read_dir(&dir_path)? {
let file = file?;
let file_path = file.path();
if file.file_type()?.is_dir() {
continue;
}
if file_path.extension() != Some(OsStr::new("rs")) {
continue;
}
let paths = compiletest::common::TestPaths {
file: file_path,
base: config.src_base.clone(),
relative_dir: dir_path.file_name().unwrap().into(),
};
let test_name = compiletest::make_test_name(config, &paths);
let index = tests
.iter()
.position(|test| test.desc.name == test_name)
.expect("The test should be in there");
result &= tester::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
}
}
Ok(result)
}
let mut config = base_config("ui-toml");
config.src_base = config.src_base.canonicalize().unwrap();
let tests = compiletest::make_tests(&config);
config.stderr_filter(
&regex::escape(
&std::path::Path::new(file!())
.parent()
.unwrap()
.canonicalize()
.unwrap()
.parent()
.unwrap()
.display()
.to_string()
.replace('\\', "/"),
),
"$$DIR",
);
let res = run_tests(&config, tests);
match res {
Ok(true) => {},
Ok(false) => panic!("Some tests failed"),
Err(e) => {
panic!("I/O failure during tests: {e:?}");
let name = config.root_dir.display().to_string();
let test_filter = test_filter();
ui_test::run_tests_generic(
config,
|path| test_filter(path) && path.extension() == Some("rs".as_ref()),
|config, path| {
let mut config = config.clone();
config
.program
.envs
.push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into())));
Some(config)
},
}
(status_emitter::Text, status_emitter::Gha::<true> { name }),
)
.unwrap();
}
fn run_ui_cargo() {
fn run_tests(
config: &compiletest::Config,
filters: &[String],
mut tests: Vec<tester::TestDescAndFn>,
) -> Result<bool, io::Error> {
let mut result = true;
let opts = compiletest::test_opts(config);
for dir in fs::read_dir(&config.src_base)? {
let dir = dir?;
if !dir.file_type()?.is_dir() {
continue;
}
// Use the filter if provided
let dir_path = dir.path();
for filter in filters {
if !dir_path.ends_with(filter) {
continue;
}
}
for case in fs::read_dir(&dir_path)? {
let case = case?;
if !case.file_type()?.is_dir() {
continue;
}
let src_path = case.path().join("src");
// When switching between branches, if the previous branch had a test
// that the current branch does not have, the directory is not removed
// because an ignored Cargo.lock file exists.
if !src_path.exists() {
continue;
}
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() {
continue;
}
// Search for the main file to avoid running a test for each file in the project
let file_path = file.path();
match file_path.file_name().and_then(OsStr::to_str) {
Some("main.rs") => {},
_ => continue,
}
let _g = VarGuard::set("CLIPPY_CONF_DIR", case.path());
let paths = compiletest::common::TestPaths {
file: file_path,
base: config.src_base.clone(),
relative_dir: src_path.strip_prefix(&config.src_base).unwrap().into(),
};
let test_name = compiletest::make_test_name(config, &paths);
let index = tests
.iter()
.position(|test| test.desc.name == test_name)
.expect("The test should be in there");
result &= tester::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
}
}
}
Ok(result)
}
if IS_RUSTC_TEST_SUITE {
return;
}
let mut config = base_config("ui-cargo");
config.src_base = config.src_base.canonicalize().unwrap();
config.program.input_file_flag = CommandBuilder::cargo().input_file_flag;
config.program.out_dir_flag = CommandBuilder::cargo().out_dir_flag;
config.program.args = vec!["clippy".into(), "--color".into(), "never".into(), "--quiet".into()];
config
.program
.envs
.push(("RUSTFLAGS".into(), Some("-Dwarnings".into())));
// We need to do this while we still have a rustc in the `program` field.
config.fill_host_and_target().unwrap();
config.dependencies_crate_manifest_path = None;
config.program.program.set_file_name(if cfg!(windows) {
"cargo-clippy.exe"
} else {
"cargo-clippy"
});
config.edition = None;
let tests = compiletest::make_tests(&config);
config.stderr_filter(
&regex::escape(
&std::path::Path::new(file!())
.parent()
.unwrap()
.canonicalize()
.unwrap()
.parent()
.unwrap()
.display()
.to_string()
.replace('\\', "/"),
),
"$$DIR",
);
let current_dir = env::current_dir().unwrap();
let res = run_tests(&config, &config.filters, tests);
env::set_current_dir(current_dir).unwrap();
let name = config.root_dir.display().to_string();
match res {
Ok(true) => {},
Ok(false) => panic!("Some tests failed"),
Err(e) => {
panic!("I/O failure during tests: {e:?}");
let test_filter = test_filter();
ui_test::run_tests_generic(
config,
|path| test_filter(path) && path.ends_with("Cargo.toml"),
|config, path| {
let mut config = config.clone();
config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap());
Some(config)
},
}
(status_emitter::Text, status_emitter::Gha::<true> { name }),
)
.unwrap();
}
#[test]
fn compile_test() {
fn main() {
set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
run_ui();
run_ui_toml();
run_ui_cargo();
run_internal_tests();
rustfix_coverage_known_exceptions_accuracy();
ui_cargo_toml_metadata();
}
const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[
@ -384,7 +244,6 @@ const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[
"needless_for_each_unfixable.rs",
"nonminimal_bool.rs",
"print_literal.rs",
"print_with_newline.rs",
"redundant_static_lifetimes_multiple.rs",
"ref_binding_to_reference.rs",
"repl_uninit.rs",
@ -399,7 +258,6 @@ const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[
"unnecessary_lazy_eval_unfixable.rs",
"write_literal.rs",
"write_literal_2.rs",
"write_with_newline.rs",
];
fn check_rustfix_coverage() {
@ -432,25 +290,16 @@ fn check_rustfix_coverage() {
}
}
#[test]
fn rustfix_coverage_known_exceptions_accuracy() {
for filename in RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS {
let rs_path = Path::new("tests/ui").join(filename);
assert!(
rs_path.exists(),
"`{}` does not exist",
rs_path.strip_prefix(env!("CARGO_MANIFEST_DIR")).unwrap().display()
);
assert!(rs_path.exists(), "`{}` does not exist", rs_path.display());
let fixed_path = rs_path.with_extension("fixed");
assert!(
!fixed_path.exists(),
"`{}` exists",
fixed_path.strip_prefix(env!("CARGO_MANIFEST_DIR")).unwrap().display()
);
println!("{}", fixed_path.display());
assert!(!fixed_path.exists(), "`{}` exists", fixed_path.display());
}
}
#[test]
fn ui_cargo_toml_metadata() {
let ui_cargo_path = Path::new("tests/ui-cargo");
let cargo_common_metadata_path = ui_cargo_path.join("cargo_common_metadata");

View File

@ -41,8 +41,8 @@ fn explore_directory(dir: &Path) -> Vec<String> {
x.path().extension().and_then(OsStr::to_str),
y.path().extension().and_then(OsStr::to_str),
) {
(Some("rs"), _) => Ordering::Less,
(_, Some("rs")) => Ordering::Greater,
(Some("rs" | "toml"), _) => Ordering::Less,
(_, Some("rs" | "toml")) => Ordering::Greater,
_ => Ordering::Equal,
}
});
@ -54,7 +54,7 @@ fn explore_directory(dir: &Path) -> Vec<String> {
let file_prefix = path.file_prefix().unwrap().to_str().unwrap().to_string();
if let Some(ext) = path.extension() {
match ext.to_str().unwrap() {
"rs" => current_file = file_prefix.clone(),
"rs" | "toml" => current_file = file_prefix.clone(),
"stderr" | "stdout" => {
if file_prefix != current_file {
missing_files.push(path.to_str().unwrap().to_string());

View File

@ -1,6 +1,6 @@
error: package `cargo_common_metadata_fail` is missing `package.description` metadata
|
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
error: package `cargo_common_metadata_fail` is missing `either package.license or package.license_file` metadata
@ -12,5 +12,4 @@ error: package `cargo_common_metadata_fail` is missing `package.keywords` metada
error: package `cargo_common_metadata_fail` is missing `package.categories` metadata
error: aborting due to 6 previous errors
error: could not compile `cargo_common_metadata_fail` (bin "cargo_common_metadata_fail") due to 6 previous errors

View File

@ -1,6 +1,6 @@
error: package `cargo_common_metadata_fail_publish` is missing `package.description` metadata
|
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
error: package `cargo_common_metadata_fail_publish` is missing `either package.license or package.license_file` metadata
@ -12,5 +12,4 @@ error: package `cargo_common_metadata_fail_publish` is missing `package.keywords
error: package `cargo_common_metadata_fail_publish` is missing `package.categories` metadata
error: aborting due to 6 previous errors
error: could not compile `cargo_common_metadata_fail_publish` (bin "cargo_common_metadata_fail_publish") due to 6 previous errors

View File

@ -1,6 +1,6 @@
error: package `cargo_common_metadata_fail_publish_true` is missing `package.description` metadata
|
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
|
= note: `-D clippy::cargo-common-metadata` implied by `-D warnings`
error: package `cargo_common_metadata_fail_publish_true` is missing `either package.license or package.license_file` metadata
@ -12,5 +12,4 @@ error: package `cargo_common_metadata_fail_publish_true` is missing `package.key
error: package `cargo_common_metadata_fail_publish_true` is missing `package.categories` metadata
error: aborting due to 6 previous errors
error: could not compile `cargo_common_metadata_fail_publish_true` (bin "cargo_common_metadata_fail_publish_true") due to 6 previous errors

View File

@ -0,0 +1,21 @@
warning: the MSRV in `clippy.toml` and `Cargo.toml` differ; using `1.59.0` from `clippy.toml`
error: unnecessary structure name repetition
--> src/main.rs:6:21
|
6 | pub fn bar() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(clippy::use_self)]
| ^^^^^^^^^^^^^^^^
error: unnecessary structure name repetition
--> src/main.rs:7:9
|
7 | Foo
| ^^^ help: use the applicable keyword: `Self`
error: could not compile `fail-both-diff` (bin "fail-both-diff") due to 2 previous errors; 1 warning emitted

View File

@ -1,22 +0,0 @@
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: unnecessary structure name repetition
--> $DIR/main.rs:7:9
|
LL | Foo
| ^^^ help: use the applicable keyword: `Self`
error: aborting due to 2 previous errors; 1 warning emitted

View File

@ -0,0 +1,19 @@
error: unnecessary structure name repetition
--> src/main.rs:6:21
|
6 | pub fn bar() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(clippy::use_self)]
| ^^^^^^^^^^^^^^^^
error: unnecessary structure name repetition
--> src/main.rs:7:9
|
7 | Foo
| ^^^ help: use the applicable keyword: `Self`
error: could not compile `fail-both-same` (bin "fail-both-same") due to 2 previous errors

View File

@ -1,20 +0,0 @@
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: unnecessary structure name repetition
--> $DIR/main.rs:7:9
|
LL | Foo
| ^^^ help: use the applicable keyword: `Self`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,19 @@
error: unnecessary structure name repetition
--> src/main.rs:6:21
|
6 | pub fn bar() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(clippy::use_self)]
| ^^^^^^^^^^^^^^^^
error: unnecessary structure name repetition
--> src/main.rs:7:9
|
7 | Foo
| ^^^ help: use the applicable keyword: `Self`
error: could not compile `fail-cargo` (bin "fail-cargo") due to 2 previous errors

View File

@ -1,20 +0,0 @@
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: unnecessary structure name repetition
--> $DIR/main.rs:7:9
|
LL | Foo
| ^^^ help: use the applicable keyword: `Self`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,19 @@
error: unnecessary structure name repetition
--> src/main.rs:6:21
|
6 | pub fn bar() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(clippy::use_self)]
| ^^^^^^^^^^^^^^^^
error: unnecessary structure name repetition
--> src/main.rs:7:9
|
7 | Foo
| ^^^ help: use the applicable keyword: `Self`
error: could not compile `fail-clippy` (bin "fail-clippy") due to 2 previous errors

View File

@ -1,20 +0,0 @@
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: unnecessary structure name repetition
--> $DIR/main.rs:7:9
|
LL | Foo
| ^^^ help: use the applicable keyword: `Self`
error: aborting due to 2 previous errors

View File

@ -1,20 +1,19 @@
error: unnecessary structure name repetition
--> $DIR/main.rs:11:21
--> src/main.rs:11:21
|
LL | pub fn bar() -> Foo {
11 | pub fn bar() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
|
note: the lint level is defined here
--> $DIR/main.rs:6:9
--> src/main.rs:6:9
|
LL | #![deny(clippy::use_self)]
6 | #![deny(clippy::use_self)]
| ^^^^^^^^^^^^^^^^
error: unnecessary structure name repetition
--> $DIR/main.rs:12:9
--> src/main.rs:12:9
|
LL | Foo
12 | Foo
| ^^^ help: use the applicable keyword: `Self`
error: aborting due to 2 previous errors
error: could not compile `fail-file-attr` (bin "fail-file-attr") due to 2 previous errors

View File

@ -1,4 +1,2 @@
warning: the MSRV in `clippy.toml` and `Cargo.toml` differ; using `1.13.0` from `clippy.toml`
warning: 1 warning emitted

View File

@ -0,0 +1,52 @@
error: file is loaded as a module multiple times: `src/b.rs`
--> src/main.rs:5:1
|
5 | mod b;
| ^^^^^^ first loaded here
6 | / #[path = "b.rs"]
7 | | mod b2;
| |_______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
= note: `-D clippy::duplicate-mod` implied by `-D warnings`
error: file is loaded as a module multiple times: `src/c.rs`
--> src/main.rs:9:1
|
9 | mod c;
| ^^^^^^ first loaded here
10 | / #[path = "c.rs"]
11 | | mod c2;
| |_______^ loaded again here
12 | / #[path = "c.rs"]
13 | | mod c3;
| |_______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
error: file is loaded as a module multiple times: `src/d.rs`
--> src/main.rs:18:1
|
18 | mod d;
| ^^^^^^ first loaded here
19 | / #[path = "d.rs"]
20 | | mod d2;
| |_______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
error: file is loaded as a module multiple times: `src/from_other_module.rs`
--> src/main.rs:15:1
|
15 | mod from_other_module;
| ^^^^^^^^^^^^^^^^^^^^^^ first loaded here
|
::: src/other_module/mod.rs:1:1
|
1 | / #[path = "../from_other_module.rs"]
2 | | mod m;
| |______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
error: could not compile `duplicate_mod` (bin "duplicate_mod") due to 4 previous errors

View File

@ -1,53 +0,0 @@
error: file is loaded as a module multiple times: `$DIR/b.rs`
--> $DIR/main.rs:5:1
|
LL | mod b;
| ^^^^^^ first loaded here
LL | / #[path = "b.rs"]
LL | | mod b2;
| |_______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
= note: `-D clippy::duplicate-mod` implied by `-D warnings`
error: file is loaded as a module multiple times: `$DIR/c.rs`
--> $DIR/main.rs:9:1
|
LL | mod c;
| ^^^^^^ first loaded here
LL | / #[path = "c.rs"]
LL | | mod c2;
| |_______^ loaded again here
LL | / #[path = "c.rs"]
LL | | mod c3;
| |_______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
error: file is loaded as a module multiple times: `$DIR/d.rs`
--> $DIR/main.rs:18:1
|
LL | mod d;
| ^^^^^^ first loaded here
LL | / #[path = "d.rs"]
LL | | mod d2;
| |_______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
error: file is loaded as a module multiple times: `$DIR/from_other_module.rs`
--> $DIR/main.rs:15:1
|
LL | mod from_other_module;
| ^^^^^^^^^^^^^^^^^^^^^^ first loaded here
|
::: $DIR/other_module/mod.rs:1:1
|
LL | / #[path = "../from_other_module.rs"]
LL | | mod m;
| |______^ loaded again here
|
= help: replace all but one `mod` item with `use` items
error: aborting due to 4 previous errors

View File

@ -0,0 +1,43 @@
error: the "no-" prefix in the feature name "no-qaq" is negative
|
= help: consider renaming the feature to "qaq", but make sure the feature adds functionality
= note: `-D clippy::negative-feature-names` implied by `-D warnings`
error: the "no_" prefix in the feature name "no_qaq" is negative
|
= help: consider renaming the feature to "qaq", but make sure the feature adds functionality
error: the "not-" prefix in the feature name "not-orz" is negative
|
= help: consider renaming the feature to "orz", but make sure the feature adds functionality
error: the "not_" prefix in the feature name "not_orz" is negative
|
= help: consider renaming the feature to "orz", but make sure the feature adds functionality
error: the "-support" suffix in the feature name "qvq-support" is redundant
|
= help: consider renaming the feature to "qvq"
= note: `-D clippy::redundant-feature-names` implied by `-D warnings`
error: the "_support" suffix in the feature name "qvq_support" is redundant
|
= help: consider renaming the feature to "qvq"
error: the "use-" prefix in the feature name "use-qwq" is redundant
|
= help: consider renaming the feature to "qwq"
error: the "use_" prefix in the feature name "use_qwq" is redundant
|
= help: consider renaming the feature to "qwq"
error: the "with-" prefix in the feature name "with-owo" is redundant
|
= help: consider renaming the feature to "owo"
error: the "with_" prefix in the feature name "with_owo" is redundant
|
= help: consider renaming the feature to "owo"
error: could not compile `feature_name` (bin "feature_name") due to 10 previous errors

View File

@ -1,44 +0,0 @@
error: the "no-" prefix in the feature name "no-qaq" is negative
|
= help: consider renaming the feature to "qaq", but make sure the feature adds functionality
= note: `-D clippy::negative-feature-names` implied by `-D warnings`
error: the "no_" prefix in the feature name "no_qaq" is negative
|
= help: consider renaming the feature to "qaq", but make sure the feature adds functionality
error: the "not-" prefix in the feature name "not-orz" is negative
|
= help: consider renaming the feature to "orz", but make sure the feature adds functionality
error: the "not_" prefix in the feature name "not_orz" is negative
|
= help: consider renaming the feature to "orz", but make sure the feature adds functionality
error: the "-support" suffix in the feature name "qvq-support" is redundant
|
= help: consider renaming the feature to "qvq"
= note: `-D clippy::redundant-feature-names` implied by `-D warnings`
error: the "_support" suffix in the feature name "qvq_support" is redundant
|
= help: consider renaming the feature to "qvq"
error: the "use-" prefix in the feature name "use-qwq" is redundant
|
= help: consider renaming the feature to "qwq"
error: the "use_" prefix in the feature name "use_qwq" is redundant
|
= help: consider renaming the feature to "qwq"
error: the "with-" prefix in the feature name "with-owo" is redundant
|
= help: consider renaming the feature to "owo"
error: the "with_" prefix in the feature name "with_owo" is redundant
|
= help: consider renaming the feature to "owo"
error: aborting due to 10 previous errors

View File

@ -0,0 +1,18 @@
error: `mod.rs` files are required, found `src/bad/inner.rs`
--> src/bad/inner.rs:1:1
|
1 | pub mod stuff;
| ^
|
= help: move `src/bad/inner.rs` to `src/bad/inner/mod.rs`
= note: `-D clippy::self-named-module-files` implied by `-D warnings`
error: `mod.rs` files are required, found `src/bad/inner/stuff.rs`
--> src/bad/inner/stuff.rs:1:1
|
1 | pub mod most;
| ^
|
= help: move `src/bad/inner/stuff.rs` to `src/bad/inner/stuff/mod.rs`
error: could not compile `fail-mod` (bin "fail-mod") due to 2 previous errors

View File

@ -1,19 +0,0 @@
error: `mod.rs` files are required, found `bad/inner.rs`
--> $DIR/bad/inner.rs:1:1
|
LL | pub mod stuff;
| ^
|
= help: move `bad/inner.rs` to `bad/inner/mod.rs`
= note: `-D clippy::self-named-module-files` implied by `-D warnings`
error: `mod.rs` files are required, found `bad/inner/stuff.rs`
--> $DIR/bad/inner/stuff.rs:1:1
|
LL | pub mod most;
| ^
|
= help: move `bad/inner/stuff.rs` to `bad/inner/stuff/mod.rs`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,10 @@
error: `mod.rs` files are required, found `src/bad.rs`
--> src/bad.rs:1:1
|
1 | pub mod inner;
| ^
|
= help: move `src/bad.rs` to `src/bad/mod.rs`
= note: `-D clippy::self-named-module-files` implied by `-D warnings`
error: could not compile `fail-mod-remap` (bin "fail-mod-remap") due to previous error

View File

@ -1,11 +0,0 @@
error: `mod.rs` files are required, found `bad.rs`
--> /remapped/module_style/fail_mod_remap/src/bad.rs:1:1
|
LL | pub mod inner;
| ^
|
= help: move `bad.rs` to `bad/mod.rs`
= note: `-D clippy::self-named-module-files` implied by `-D warnings`
error: aborting due to previous error

View File

@ -0,0 +1,10 @@
error: `mod.rs` files are not allowed, found `src/bad/mod.rs`
--> src/bad/mod.rs:1:1
|
1 | pub struct Thing;
| ^
|
= help: move `src/bad/mod.rs` to `src/bad.rs`
= note: `-D clippy::mod-module-files` implied by `-D warnings`
error: could not compile `fail-no-mod` (bin "fail-no-mod") due to previous error

View File

@ -1,11 +0,0 @@
error: `mod.rs` files are not allowed, found `bad/mod.rs`
--> $DIR/bad/mod.rs:1:1
|
LL | pub struct Thing;
| ^
|
= help: move `bad/mod.rs` to `bad.rs`
= note: `-D clippy::mod-module-files` implied by `-D warnings`
error: aborting due to previous error

View File

@ -0,0 +1,2 @@
warning: using config file `$DIR/$DIR/.clippy.toml`, `$DIR/$DIR/clippy.toml` will be ignored

View File

@ -1,4 +0,0 @@
warning: using config file `$SRC_DIR/.clippy.toml`, `$SRC_DIR/clippy.toml` will be ignored
warning: 1 warning emitted

View File

@ -0,0 +1,5 @@
error: multiple versions for dependency `winapi`: 0.2.8, 0.3.9
|
= note: `-D clippy::multiple-crate-versions` implied by `-D warnings`
error: could not compile `multiple_crate_versions` (bin "multiple_crate_versions") due to previous error

View File

@ -1,6 +0,0 @@
error: multiple versions for dependency `winapi`: 0.2.8, 0.3.9
|
= note: `-D clippy::multiple-crate-versions` implied by `-D warnings`
error: aborting due to previous error

View File

@ -1,3 +1,3 @@
#!/bin/bash
echo "Please use 'cargo dev bless' instead."
echo "Please use 'cargo bless' instead."

View File

@ -0,0 +1,5 @@
error: wildcard dependency for `regex`
|
= note: `-D clippy::wildcard-dependencies` implied by `-D warnings`
error: could not compile `wildcard_dependencies` (bin "wildcard_dependencies") due to previous error

View File

@ -1,6 +0,0 @@
error: wildcard dependency for `regex`
|
= note: `-D clippy::wildcard-dependencies` implied by `-D warnings`
error: aborting due to previous error

View File

@ -7,7 +7,7 @@ note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy
note: rustc <version> running on <target>
note: compiler flags: -C prefer-dynamic -Z ui-testing
note: compiler flags: -Z ui-testing
query stack during panic:
thread panicked while processing panic. aborting.

View File

@ -1 +1,3 @@
//@error-in-other-file: error reading Clippy's configuration file: expected `.`, `=`
fn main() {}

View File

@ -1,5 +1,5 @@
error: error reading Clippy's configuration file: expected `.`, `=`
--> $DIR/clippy.toml:1:4
--> $DIR/$DIR/clippy.toml:1:4
|
LL | fn this_is_obviously(not: a, toml: file) {
| ^

View File

@ -1 +1,3 @@
//@error-in-other-file: invalid type: integer `42`, expected a sequence
fn main() {}

View File

@ -1,5 +1,5 @@
error: error reading Clippy's configuration file: invalid type: integer `42`, expected a sequence
--> $DIR/clippy.toml:1:20
--> $DIR/$DIR/clippy.toml:1:20
|
LL | disallowed-names = 42
| ^^

View File

@ -1,11 +1,11 @@
warning: error reading Clippy's configuration file: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
--> $DIR/clippy.toml:2:1
--> $DIR/$DIR/clippy.toml:2:1
|
LL | cyclomatic-complexity-threshold = 2
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: error reading Clippy's configuration file: deprecated field `blacklisted-names`. Please use `disallowed-names` instead
--> $DIR/clippy.toml:3:1
--> $DIR/$DIR/clippy.toml:3:1
|
LL | blacklisted-names = [ "..", "wibble" ]
| ^^^^^^^^^^^^^^^^^

View File

@ -1 +1,3 @@
//@error-in-other-file: duplicate key `cognitive-complexity-threshold`
fn main() {}

View File

@ -1,5 +1,5 @@
error: error reading Clippy's configuration file: duplicate key `cognitive-complexity-threshold` in document root
--> $DIR/clippy.toml:2:1
--> $DIR/$DIR/clippy.toml:2:1
|
LL | cognitive-complexity-threshold = 4
| ^

View File

@ -1,11 +1,11 @@
error: error reading Clippy's configuration file: duplicate field `cognitive_complexity_threshold` (provided as `cyclomatic_complexity_threshold`)
--> $DIR/clippy.toml:3:1
--> $DIR/$DIR/clippy.toml:3:1
|
LL | cyclomatic-complexity-threshold = 3
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: error reading Clippy's configuration file: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
--> $DIR/clippy.toml:3:1
--> $DIR/$DIR/clippy.toml:3:1
|
LL | cyclomatic-complexity-threshold = 3
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,11 +1,11 @@
error: error reading Clippy's configuration file: duplicate field `cognitive-complexity-threshold`
--> $DIR/clippy.toml:4:1
--> $DIR/$DIR/clippy.toml:4:1
|
LL | cognitive-complexity-threshold = 4
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: error reading Clippy's configuration file: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
--> $DIR/clippy.toml:2:1
--> $DIR/$DIR/clippy.toml:2:1
|
LL | cyclomatic-complexity-threshold = 3
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,9 +1,5 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
// NOTE: Copied from `ui/auxiliary/proc_macros.rs`, couldn't get `../` to work for some reason
#![crate_type = "proc-macro"]
#![feature(let_chains)]
#![feature(proc_macro_span)]
#![allow(clippy::excessive_nesting, dead_code)]

View File

@ -1,4 +1,4 @@
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![rustfmt::skip]
#![feature(custom_inner_attributes)]
#![allow(unused)]

View File

@ -1,3 +1,5 @@
//@error-in-other-file: `invalid.version` is not a valid Rust version
#![allow(clippy::redundant_clone)]
fn main() {}

View File

@ -1,5 +1,5 @@
#![allow(clippy::excessive_precision)]
#[deny(clippy::unreadable_literal)]
#![warn(clippy::unreadable_literal)]
fn allow_inconsistent_digit_grouping() {
#![allow(clippy::inconsistent_digit_grouping)]

View File

@ -6,5 +6,13 @@ LL | let _fail1 = 100_200_300.123456789;
|
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings`
error: aborting due to previous error
error: long literal lacking separators
--> $DIR/test.rs:22:18
|
LL | let _fail2 = 100200300.300200100;
| ^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.300_200_100`
|
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
error: aborting due to 2 previous errors

View File

@ -3,6 +3,7 @@
fn below_limit() {
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
if let Some(slice) = slice {
//~^ ERROR: binding can be a slice pattern
// This would usually not be linted but is included now due to the
// index limit in the config file
println!("{}", slice[7]);

View File

@ -41,7 +41,7 @@ fn match_like_matches() {
fn match_same_arms() {
match (1, 2, 3) {
(1, .., 3) => 42,
(.., 3) => 42, //~ ERROR match arms have same body
(.., 3) => 42,
_ => 0,
};
}
@ -49,7 +49,7 @@ fn match_same_arms() {
fn match_same_arms2() {
let _ = match Some(42) {
Some(_) => 24,
None => 24, //~ ERROR match arms have same body
None => 24,
};
}

View File

@ -1,8 +1,3 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::TokenStream;

View File

@ -1,4 +1,4 @@
//@aux-build:proc_macro_derive.rs
//@aux-build:proc_macro_derive.rs:proc-macro
//@run-rustfix
#![warn(clippy::nonstandard_macro_braces)]

View File

@ -1,4 +1,4 @@
//@aux-build:proc_macro_derive.rs
//@aux-build:proc_macro_derive.rs:proc-macro
//@run-rustfix
#![warn(clippy::nonstandard_macro_braces)]

View File

@ -13,6 +13,7 @@
const ARR: [i32; 2] = [1, 2];
const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
//~^ ERROR: failed
const fn idx() -> usize {
1
@ -34,6 +35,8 @@ fn main() {
x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
const { &ARR[idx()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
//
//~^^ ERROR: failed
let y = &x;
y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021

View File

@ -1,17 +1,17 @@
error[E0080]: evaluation of `main::{constant#3}` failed
--> $DIR/test.rs:36:14
--> $DIR/test.rs:37:14
|
LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
note: erroneous constant used
--> $DIR/test.rs:36:5
--> $DIR/test.rs:37:5
|
LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
| ^^^^^^^^^^^^^^^^^^^^^^
error: indexing may panic
--> $DIR/test.rs:27:5
--> $DIR/test.rs:28:5
|
LL | x[index];
| ^^^^^^^^
@ -20,7 +20,7 @@ LL | x[index];
= note: `-D clippy::indexing-slicing` implied by `-D warnings`
error: indexing may panic
--> $DIR/test.rs:43:5
--> $DIR/test.rs:46:5
|
LL | v[0];
| ^^^^
@ -28,7 +28,7 @@ LL | v[0];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
--> $DIR/test.rs:44:5
--> $DIR/test.rs:47:5
|
LL | v[10];
| ^^^^^
@ -36,7 +36,7 @@ LL | v[10];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
--> $DIR/test.rs:45:5
--> $DIR/test.rs:48:5
|
LL | v[1 << 3];
| ^^^^^^^^^
@ -44,7 +44,7 @@ LL | v[1 << 3];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
--> $DIR/test.rs:51:5
--> $DIR/test.rs:54:5
|
LL | v[N];
| ^^^^
@ -52,7 +52,7 @@ LL | v[N];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
--> $DIR/test.rs:52:5
--> $DIR/test.rs:55:5
|
LL | v[M];
| ^^^^

View File

@ -1,7 +1,7 @@
//@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)"
//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![deny(clippy::trivially_copy_pass_by_ref)]
#![warn(clippy::trivially_copy_pass_by_ref)]
#[derive(Copy, Clone)]
struct Foo(u8);

View File

@ -4,11 +4,7 @@ error: this argument (N byte) is passed by reference, but would be more efficien
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `u16`
|
note: the lint level is defined here
--> $DIR/test.rs:4:9
|
LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:14:20

View File

@ -1,3 +1,3 @@
//@error-pattern: unknown field `foobar`, expected one of
//@error-in-other-file: unknown field `foobar`, expected one of
fn main() {}

View File

@ -61,7 +61,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
vec-box-size-threshold
verbose-bit-mask-threshold
warn-on-all-wildcard-imports
--> $DIR/clippy.toml:2:1
--> $DIR/$DIR/clippy.toml:2:1
|
LL | foobar = 42
| ^^^^^^
@ -129,7 +129,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
vec-box-size-threshold
verbose-bit-mask-threshold
warn-on-all-wildcard-imports
--> $DIR/clippy.toml:4:1
--> $DIR/$DIR/clippy.toml:4:1
|
LL | barfoo = 53
| ^^^^^^

View File

@ -1,8 +1,3 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::{Delimiter, Group, Ident, TokenStream, TokenTree};

View File

@ -1,4 +1,4 @@
//@aux-build:proc_macro_unsafe.rs
//@aux-build:proc_macro_unsafe.rs:proc-macro
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
#![allow(deref_nullptr, clippy::let_unit_value, clippy::missing_safety_doc)]

View File

@ -7,7 +7,7 @@
clippy::useless_vec
)]
#![warn(clippy::unwrap_used)]
#![deny(clippy::get_unwrap)]
#![warn(clippy::get_unwrap)]
use std::collections::BTreeMap;
use std::collections::HashMap;

View File

@ -4,11 +4,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _ = boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]`
|
note: the lint level is defined here
--> $DIR/unwrap_used.rs:10:9
|
LL | #![deny(clippy::get_unwrap)]
| ^^^^^^^^^^^^^^^^^^
= note: `-D clippy::get-unwrap` implied by `-D warnings`
error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:40:17

View File

@ -1,3 +1,3 @@
#!/bin/bash
echo "Please use 'cargo dev bless' instead."
echo "Please use 'cargo bless' instead."

View File

@ -1,5 +1,5 @@
//@run-rustfix
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![allow(unused)]
#![warn(clippy::allow_attributes)]
#![feature(lint_reasons)]

View File

@ -1,5 +1,5 @@
//@run-rustfix
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![allow(unused)]
#![warn(clippy::allow_attributes)]
#![feature(lint_reasons)]

View File

@ -1,4 +1,4 @@
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![feature(lint_reasons)]
#![deny(clippy::allow_attributes_without_reason)]
#![allow(unfulfilled_lint_expectations)]

View File

@ -1,6 +1,6 @@
//@run-rustfix
//@edition:2018
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]

View File

@ -1,6 +1,6 @@
//@run-rustfix
//@edition:2018
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]

View File

@ -1,4 +1,4 @@
//@aux-build:proc_macro_derive.rs
//@aux-build:proc_macro_derive.rs:proc-macro
#![allow(
clippy::assign_op_pattern,

View File

@ -1,4 +1,4 @@
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::as_conversions)]
#![allow(clippy::borrow_as_ptr, unused)]

View File

@ -1,5 +1,5 @@
//@only-x86_64
//@ignore-aarch64
//@only-target-x86_64
//@ignore-target-aarch64
#[warn(clippy::inline_asm_x86_intel_syntax)]
mod warn_intel {

View File

@ -1,3 +1,5 @@
//@aux-build:macro_rules.rs
extern crate macro_rules;
// STMT

View File

@ -1,7 +1,3 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_hygiene, proc_macro_quote, box_patterns)]
#![allow(incomplete_features)]
#![allow(clippy::useless_conversion, clippy::uninlined_format_args)]

View File

@ -1,7 +1,3 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_quote)]
#![allow(incomplete_features)]
#![allow(clippy::field_reassign_with_default)]

View File

@ -1,8 +1,3 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::{token_stream, Delimiter, Group, Ident, Span, TokenStream, TokenTree};

View File

@ -1,8 +1,3 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::{Delimiter, Group, Ident, TokenStream, TokenTree};

View File

@ -1,7 +1,3 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(let_chains)]
#![feature(proc_macro_span)]
#![allow(clippy::needless_if, dead_code)]

View File

@ -1,5 +1,5 @@
//@run-rustfix
//@aux-build: proc_macros.rs
//@aux-build: proc_macros.rs:proc-macro
#![allow(dead_code, unused_variables)]

View File

@ -1,5 +1,5 @@
//@run-rustfix
//@aux-build: proc_macros.rs
//@aux-build: proc_macros.rs:proc-macro
#![allow(dead_code, unused_variables)]

View File

@ -1,6 +1,6 @@
//@aux-build:helper.rs
#![warn(clippy::borrow_interior_mutable_const)]
#![deny(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const)]
// this file (mostly) replicates its `declare` counterpart. Please see it for more discussions.
@ -19,7 +19,7 @@ const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true));
const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
fn borrow_optional_cell() {
let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
let _ = &UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &FROZEN_VARIANT;
}
@ -34,11 +34,11 @@ trait AssocConsts {
// This is the "suboptimal behavior" mentioned in `is_value_unfrozen`
// caused by a similar reason to unfrozen types without any default values
// get linted even if it has frozen variants'.
let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR: interior mutability
// The lint ignores default values because an impl of this trait can set
// an unfrozen variant to `DEFAULTED_ON_FROZEN_VARIANT` and use the default impl for `function`.
let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior mutable
let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR: interior mutability
}
}
@ -47,9 +47,9 @@ impl AssocConsts for u64 {
const TO_BE_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
fn function() {
let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &<Self as AssocConsts>::TO_BE_FROZEN_VARIANT;
let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mutable
let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT;
}
}
@ -67,11 +67,11 @@ trait AssocTypes {
impl AssocTypes for u64 {
type ToBeUnfrozen = AtomicUsize;
const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4));
const TO_BE_FROZEN_VARIANT: Option<Self::ToBeUnfrozen> = None;
fn function() {
let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &<Self as AssocTypes>::TO_BE_FROZEN_VARIANT;
}
}
@ -83,19 +83,19 @@ enum BothOfCellAndGeneric<T> {
}
impl<T> BothOfCellAndGeneric<T> {
const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null()));
const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null());
const FROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Frozen(5);
fn function() {
let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
let _ = &Self::UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &Self::GENERIC_VARIANT; //~ ERROR: interior mutability
let _ = &Self::FROZEN_VARIANT;
}
}
fn main() {
// constants defined in foreign crates
let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR interior mutability
let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &helper::WRAPPED_PRIVATE_FROZEN_VARIANT;
}

View File

@ -1,16 +1,20 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:22:14
|
LL | let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
LL | let _ = &UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
note: the lint level is defined here
--> $DIR/enums.rs:3:9
|
LL | #![deny(clippy::borrow_interior_mutable_const)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:37:18
|
LL | let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
LL | let _ = &Self::TO_BE_FROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -18,7 +22,7 @@ LL | let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:41:18
|
LL | let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior mutable
LL | let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -26,7 +30,7 @@ LL | let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior muta
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:50:18
|
LL | let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
LL | let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -34,7 +38,7 @@ LL | let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR i
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:52:18
|
LL | let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mutable
LL | let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -42,7 +46,7 @@ LL | let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mu
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:74:18
|
LL | let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
LL | let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -50,7 +54,7 @@ LL | let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR in
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:91:18
|
LL | let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
LL | let _ = &Self::UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -58,7 +62,7 @@ LL | let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:92:18
|
LL | let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
LL | let _ = &Self::GENERIC_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -66,7 +70,7 @@ LL | let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:99:14
|
LL | let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR interior mutability
LL | let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here

View File

@ -1,4 +1,4 @@
#![warn(clippy::borrow_interior_mutable_const)]
#![deny(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const, clippy::needless_borrow)]
#![allow(const_item_mutation)]
@ -51,14 +51,14 @@ impl<T> std::ops::Deref for StaticRef<T> {
const CELL_REF: StaticRef<(UnsafeCell<u32>,)> = unsafe { StaticRef::new(std::ptr::null()) };
fn main() {
ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
ATOMIC.store(1, Ordering::SeqCst); //~ ERROR: interior mutability
assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR: interior mutability
let _once = ONCE_INIT;
let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
let _once_ref = &ONCE_INIT; //~ ERROR: interior mutability
let _once_ref_2 = &&ONCE_INIT; //~ ERROR: interior mutability
let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR: interior mutability
let _once_mut = &mut ONCE_INIT; //~ ERROR: interior mutability
let _atomic_into_inner = ATOMIC.into_inner();
// these should be all fine.
let _twice = (ONCE_INIT, ONCE_INIT);
@ -69,23 +69,23 @@ fn main() {
let _ref_array_once = &[ONCE_INIT, ONCE_INIT][0];
// referencing projection is still bad.
let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
let _ = &ATOMIC_TUPLE; //~ ERROR: interior mutability
let _ = &ATOMIC_TUPLE.0; //~ ERROR: interior mutability
let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR: interior mutability
let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR: interior mutability
let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR: interior mutability
let _ = &*ATOMIC_TUPLE.1;
let _ = &ATOMIC_TUPLE.2;
let _ = (&&&&ATOMIC_TUPLE).0;
let _ = (&&&&ATOMIC_TUPLE).2;
let _ = ATOMIC_TUPLE.0;
let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
let _ = ATOMIC_TUPLE.0[0]; //~ ERROR: interior mutability
let _ = ATOMIC_TUPLE.1.into_iter();
let _ = ATOMIC_TUPLE.2;
let _ = &{ ATOMIC_TUPLE };
CELL.set(2); //~ ERROR interior mutability
assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
CELL.set(2); //~ ERROR: interior mutability
assert_eq!(CELL.get(), 6); //~ ERROR: interior mutability
assert_eq!(INTEGER, 8);
assert!(STRING.is_empty());

View File

@ -1,16 +1,20 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:54:5
|
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
LL | ATOMIC.store(1, Ordering::SeqCst);
| ^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
note: the lint level is defined here
--> $DIR/others.rs:1:9
|
LL | #![deny(clippy::borrow_interior_mutable_const)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:55:16
|
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5);
| ^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -18,7 +22,7 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutabi
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:58:22
|
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
LL | let _once_ref = &ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -26,7 +30,7 @@ LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:59:25
|
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
LL | let _once_ref_2 = &&ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -34,7 +38,7 @@ LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:60:27
|
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
LL | let _once_ref_4 = &&&&ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -42,7 +46,7 @@ LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:61:26
|
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
LL | let _once_mut = &mut ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -50,7 +54,7 @@ LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:72:14
|
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
LL | let _ = &ATOMIC_TUPLE;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -58,7 +62,7 @@ LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:73:14
|
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
LL | let _ = &ATOMIC_TUPLE.0;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -66,7 +70,7 @@ LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:74:19
|
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
LL | let _ = &(&&&&ATOMIC_TUPLE).0;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -74,7 +78,7 @@ LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:75:14
|
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
LL | let _ = &ATOMIC_TUPLE.0[0];
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -82,7 +86,7 @@ LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:76:13
|
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst);
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -90,7 +94,7 @@ LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mu
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:82:13
|
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
LL | let _ = ATOMIC_TUPLE.0[0];
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -98,7 +102,7 @@ LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:87:5
|
LL | CELL.set(2); //~ ERROR interior mutability
LL | CELL.set(2);
| ^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -106,7 +110,7 @@ LL | CELL.set(2); //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:88:16
|
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
LL | assert_eq!(CELL.get(), 6);
| ^^^^
|
= help: assign this const to a local or static variable, and use the variable here

View File

@ -1,4 +1,4 @@
#![warn(clippy::borrow_interior_mutable_const)]
#![deny(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const)]
// this file replicates its `declare` counterpart. Please see it for more discussions.
@ -12,7 +12,7 @@ trait ConcreteTypes {
const STRING: String;
fn function() {
let _ = &Self::ATOMIC; //~ ERROR interior mutable
let _ = &Self::ATOMIC; //~ ERROR: interior mutability
let _ = &Self::STRING;
}
}
@ -23,7 +23,7 @@ impl ConcreteTypes for u64 {
fn function() {
// Lint this again since implementers can choose not to borrow it.
let _ = &Self::ATOMIC; //~ ERROR interior mutable
let _ = &Self::ATOMIC; //~ ERROR: interior mutability
let _ = &Self::STRING;
}
}
@ -48,7 +48,7 @@ impl<T: ConstDefault> GenericTypes<T, AtomicUsize> for Vec<T> {
fn function() {
let _ = &Self::TO_REMAIN_GENERIC;
let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
let _ = &Self::TO_BE_CONCRETE; //~ ERROR: interior mutability
}
}
@ -83,8 +83,8 @@ impl<T: ConstDefault> AssocTypes for Vec<T> {
fn function() {
let _ = &Self::TO_BE_FROZEN;
let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
let _ = &Self::TO_BE_UNFROZEN; //~ ERROR: interior mutability
let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR: interior mutability
let _ = &Self::WRAPPED_TO_BE_GENERIC_PARAM;
}
}
@ -106,7 +106,7 @@ where
fn function() {
let _ = &Self::NOT_BOUNDED;
let _ = &Self::BOUNDED; //~ ERROR interior mutable
let _ = &Self::BOUNDED; //~ ERROR: interior mutability
}
}
@ -119,7 +119,7 @@ where
fn function() {
let _ = &Self::NOT_BOUNDED;
let _ = &Self::BOUNDED; //~ ERROR interior mutable
let _ = &Self::BOUNDED; //~ ERROR: interior mutability
}
}
@ -148,8 +148,8 @@ impl SelfType for AtomicUsize {
const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21));
fn function() {
let _ = &Self::SELF; //~ ERROR interior mutable
let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
let _ = &Self::SELF; //~ ERROR: interior mutability
let _ = &Self::WRAPPED_SELF; //~ ERROR: interior mutability
}
}
@ -159,7 +159,7 @@ trait BothOfCellAndGeneric<T> {
fn function() {
let _ = &Self::DIRECT;
let _ = &Self::INDIRECT; //~ ERROR interior mutable
let _ = &Self::INDIRECT; //~ ERROR: interior mutability
}
}
@ -169,7 +169,7 @@ impl<T: ConstDefault> BothOfCellAndGeneric<T> for Vec<T> {
fn function() {
let _ = &Self::DIRECT;
let _ = &Self::INDIRECT; //~ ERROR interior mutable
let _ = &Self::INDIRECT; //~ ERROR: interior mutability
}
}
@ -188,15 +188,15 @@ where
const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19);
fn function() {
let _ = &Self::ATOMIC; //~ ERROR interior mutable
let _ = &Self::ATOMIC; //~ ERROR: interior mutability
let _ = &Self::COW;
let _ = &Self::GENERIC_TYPE;
let _ = &Self::ASSOC_TYPE;
let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR: interior mutability
}
}
fn main() {
u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR: interior mutability
assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR: interior mutability
}

View File

@ -1,16 +1,20 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:15:18
|
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
LL | let _ = &Self::ATOMIC;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
note: the lint level is defined here
--> $DIR/traits.rs:1:9
|
LL | #![deny(clippy::borrow_interior_mutable_const)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:26:18
|
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
LL | let _ = &Self::ATOMIC;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -18,7 +22,7 @@ LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:51:18
|
LL | let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
LL | let _ = &Self::TO_BE_CONCRETE;
| ^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -26,7 +30,7 @@ LL | let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:86:18
|
LL | let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
LL | let _ = &Self::TO_BE_UNFROZEN;
| ^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -34,7 +38,7 @@ LL | let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:87:18
|
LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -42,7 +46,7 @@ LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:109:18
|
LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
LL | let _ = &Self::BOUNDED;
| ^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -50,7 +54,7 @@ LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:122:18
|
LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
LL | let _ = &Self::BOUNDED;
| ^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -58,7 +62,7 @@ LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:151:18
|
LL | let _ = &Self::SELF; //~ ERROR interior mutable
LL | let _ = &Self::SELF;
| ^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -66,7 +70,7 @@ LL | let _ = &Self::SELF; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:152:18
|
LL | let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
LL | let _ = &Self::WRAPPED_SELF;
| ^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -74,7 +78,7 @@ LL | let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:162:18
|
LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
LL | let _ = &Self::INDIRECT;
| ^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -82,7 +86,7 @@ LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:172:18
|
LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
LL | let _ = &Self::INDIRECT;
| ^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -90,7 +94,7 @@ LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:191:18
|
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
LL | let _ = &Self::ATOMIC;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -98,7 +102,7 @@ LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:195:18
|
LL | let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
LL | let _ = &Self::BOUNDED_ASSOC_TYPE;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -106,7 +110,7 @@ LL | let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:200:5
|
LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
LL | u64::ATOMIC.store(5, Ordering::SeqCst);
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@ -114,7 +118,7 @@ LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:201:16
|
LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9);
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here

View File

@ -3,7 +3,7 @@
fn foo<u32>(a: u32) -> u32 {
42
// ^ rustc's type error
//~^ ERROR: mismatched types
}
fn main() {}

View File

@ -31,7 +31,7 @@ struct Foo;
impl PartialEq for Foo {
// Allow this here, because it emits the lint
// without a suggestion. This is tested in
// `tests/ui/cmp_owned/without_suggestion.rs`
// `$DIR/without_suggestion.rs`
#[allow(clippy::cmp_owned)]
fn eq(&self, other: &Self) -> bool {
self.to_owned() == *other

View File

@ -39,6 +39,14 @@ LL | fn bar() {
|
= help: you could split it up into multiple smaller functions
error: the function has a cognitive complexity of (2/1)
--> $DIR/cognitive_complexity.rs:178:4
|
LL | fn dont_warn_on_tests() {
| ^^^^^^^^^^^^^^^^^^
|
= help: you could split it up into multiple smaller functions
error: the function has a cognitive complexity of (2/1)
--> $DIR/cognitive_complexity.rs:186:4
|
@ -151,5 +159,5 @@ LL | pub async fn async_method() {
|
= help: you could split it up into multiple smaller functions
error: aborting due to 19 previous errors
error: aborting due to 20 previous errors

View File

@ -1,13 +1,5 @@
//@compile-flags: --emit=link
//@no-prefer-dynamic
// ^ compiletest by default builds all aux files as dylibs, but we don't want that for proc-macro
// crates. If we don't set this, compiletest will override the `crate_type` attribute below and
// compile this as dylib. Removing this then causes the test to fail because a `dylib` crate can't
// contain a proc-macro.
#![feature(repr128)]
#![allow(incomplete_features)]
#![crate_type = "proc-macro"]
extern crate proc_macro;

Some files were not shown because too many files have changed in this diff Show More