[go: nahoru, domu]

blob: e81a13c5ee6718a032a9d5246aa4d932b8b8d0c2 [file] [log] [blame]
#![forbid(unsafe_code)]
#![warn(nonstandard_style, rust_2018_idioms, rustdoc, unused)]
// Note: This does not guarantee compatibility with forbidding these lints in the future.
// If rustc adds a new lint, we may not be able to keep this.
#![forbid(future_incompatible, rust_2018_compatibility)]
#![allow(unknown_lints)] // for old compilers
#![warn(
box_pointers,
deprecated_in_future,
elided_lifetimes_in_paths,
explicit_outlives_requirements,
macro_use_extern_crate,
meta_variable_misuse,
missing_copy_implementations,
missing_crate_level_docs,
missing_debug_implementations,
missing_docs,
non_ascii_idents,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unaligned_references,
unreachable_pub,
unused_extern_crates,
unused_import_braces,
unused_lifetimes,
unused_qualifications,
unused_results,
variant_size_differences
)]
// absolute_paths_not_starting_with_crate, anonymous_parameters, keyword_idents, pointer_structural_match: forbidden as a part of future_incompatible
// missing_doc_code_examples, private_doc_tests, invalid_html_tags: warned as a part of rustdoc
// unsafe_block_in_unsafe_fn: unstable
// unsafe_code: forbidden
// unstable_features: deprecated: https://doc.rust-lang.org/beta/rustc/lints/listing/allowed-by-default.html#unstable-features
// unused_crate_dependencies: unrelated
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
#![warn(clippy::restriction)]
#![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally.
// Check interoperability with rustc and clippy lints.
pub mod basic {
include!("include/basic.rs");
}
pub mod box_pointers {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct {
#[pin]
pub p: Box<isize>,
pub u: Box<isize>,
}
}
}
pub mod explicit_outlives_requirements {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<'a, T, U>
where
T: ?Sized,
U: ?Sized,
{
#[pin]
pub pinned: &'a mut T,
pub unpinned: &'a mut U,
}
}
}
pub mod clippy_mut_mut {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<'a, T, U> {
#[pin]
pub pinned: &'a mut T,
pub unpinned: &'a mut U,
}
}
}
#[allow(unreachable_pub)]
mod clippy_redundant_pub_crate {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<T, U> {
#[pin]
pub pinned: T,
pub unpinned: U,
}
}
}
pub mod clippy_type_repetition_in_bounds {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<T, U>
where
Struct<T, U>: Sized,
{
#[pin]
pub pinned: T,
pub unpinned: U,
}
}
}
pub mod clippy_used_underscore_binding {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<T, U> {
#[pin]
pub _pinned: T,
pub _unpinned: U,
}
}
}
#[allow(box_pointers)]
#[allow(clippy::restriction)]
#[rustversion::attr(not(nightly), ignore)]
#[test]
fn check_lint_list() {
use std::{env, fs, path::PathBuf, process::Command, str};
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
fn assert_eq(expected_path: &str, actual: &str) -> Result<()> {
let manifest_dir = env::var_os("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.expect("CARGO_MANIFEST_DIR not set");
let expected_path = manifest_dir.join(expected_path);
let expected = fs::read_to_string(&expected_path)?;
if expected != actual {
if env::var_os("CI").map_or(false, |v| v == "true") {
panic!(
"assertion failed:\n\nEXPECTED:\n{0}\n{1}\n{0}\n\nACTUAL:\n{0}\n{2}\n{0}\n",
"-".repeat(60),
expected,
actual,
);
} else {
fs::write(&expected_path, actual)?;
}
}
Ok(())
}
(|| -> Result<()> {
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
let output = Command::new(rustc).args(&["-W", "help"]).output()?;
let new = str::from_utf8(&output.stdout)?;
assert_eq("tests/lint.txt", new)
})()
.unwrap_or_else(|e| panic!("{}", e));
}