1
Fork 0

Adapt codebase to the tool_lints

This commit is contained in:
flip1995 2018-08-01 22:48:41 +02:00 committed by Manish Goregaokar
parent cfd4c538d4
commit f3bb161f0e
25 changed files with 39 additions and 38 deletions

View file

@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
}, },
hir::ExprKind::Assign(ref assignee, ref e) => { hir::ExprKind::Assign(ref assignee, ref e) => {
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node { if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
#[allow(cyclomatic_complexity)] #[allow(clippy::cyclomatic_complexity)]
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| { let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
let ty = cx.tables.expr_ty(assignee); let ty = cx.tables.expr_ty(assignee);
let rty = cx.tables.expr_ty(rhs); let rty = cx.tables.expr_ty(rhs);

View file

@ -118,7 +118,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
} }
for (n, expr) in self.terminals.iter().enumerate() { for (n, expr) in self.terminals.iter().enumerate() {
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e, expr) { if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e, expr) {
#[allow(cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
return Ok(Bool::Term(n as u8)); return Ok(Bool::Term(n as u8));
} }
let negated = match e.node { let negated = match e.node {
@ -150,14 +150,14 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
_ => continue, _ => continue,
}; };
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(&negated, expr) { if SpanlessEq::new(self.cx).ignore_fn().eq_expr(&negated, expr) {
#[allow(cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
return Ok(Bool::Not(Box::new(Bool::Term(n as u8)))); return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
} }
} }
let n = self.terminals.len(); let n = self.terminals.len();
self.terminals.push(e); self.terminals.push(e);
if n < 32 { if n < 32 {
#[allow(cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
Ok(Bool::Term(n as u8)) Ok(Bool::Term(n as u8))
} else { } else {
Err("too many literals".to_owned()) Err("too many literals".to_owned())

View file

@ -1,5 +1,4 @@
#![allow(cast_possible_truncation)] #![allow(clippy::float_cmp)]
#![allow(float_cmp)]
use rustc::lint::LateContext; use rustc::lint::LateContext;
use rustc::{span_bug, bug}; use rustc::{span_bug, bug};

View file

@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CCHelper<'a, 'tcx> {
} }
#[cfg(feature = "debugging")] #[cfg(feature = "debugging")]
#[allow(too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, _: NodeId) { fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, _: NodeId) {
span_bug!( span_bug!(
span, span,
@ -200,7 +200,7 @@ fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts:
); );
} }
#[cfg(not(feature = "debugging"))] #[cfg(not(feature = "debugging"))]
#[allow(too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn report_cc_bug(cx: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, id: NodeId) { fn report_cc_bug(cx: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, id: NodeId) {
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) { if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
cx.sess().span_note_without_error( cx.sess().span_note_without_error(

View file

@ -86,7 +86,7 @@ impl<'a> Iterator for Parser<'a> {
/// `syntax::parse::lexer::comments::strip_doc_comment_decoration` because we /// `syntax::parse::lexer::comments::strip_doc_comment_decoration` because we
/// need to keep track of /// need to keep track of
/// the spans but this function is inspired from the later. /// the spans but this function is inspired from the later.
#[allow(cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) { pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) {
// one-line comments lose their prefix // one-line comments lose their prefix
const ONELINERS: &[&str] = &["///!", "///", "//!", "//"]; const ONELINERS: &[&str] = &["///!", "///", "//!", "//"];

View file

@ -43,7 +43,7 @@ impl LintPass for UnportableVariant {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
#[allow(cast_possible_truncation, cast_sign_loss)] #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if cx.tcx.data_layout.pointer_size.bits() != 64 { if cx.tcx.data_layout.pointer_size.bits() != 64 {
return; return;

View file

@ -147,7 +147,7 @@ fn partial_rmatch(post: &str, name: &str) -> usize {
} }
// FIXME: #600 // FIXME: #600
#[allow(while_let_on_iterator)] #[allow(clippy::while_let_on_iterator)]
fn check_variant( fn check_variant(
cx: &EarlyContext<'_>, cx: &EarlyContext<'_>,
threshold: u64, threshold: u64,

View file

@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ge | BinOpKind::Gt => (cx.tcx.lang_items().ord_trait(), true), BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ge | BinOpKind::Gt => (cx.tcx.lang_items().ord_trait(), true),
}; };
if let Some(trait_id) = trait_id { if let Some(trait_id) = trait_id {
#[allow(match_same_arms)] #[allow(clippy::match_same_arms)]
match (&left.node, &right.node) { match (&left.node, &right.node) {
// do not suggest to dereference literals // do not suggest to dereference literals
(&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {}, (&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {},

View file

@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
} }
} }
#[allow(cast_possible_wrap)] #[allow(clippy::cast_possible_wrap)]
fn check(cx: &LateContext<'_, '_>, e: &Expr, m: i8, span: Span, arg: Span) { fn check(cx: &LateContext<'_, '_>, e: &Expr, m: i8, span: Span, arg: Span) {
if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) { if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
let check = match cx.tables.expr_ty(e).sty { let check = match cx.tables.expr_ty(e).sty {

View file

@ -53,7 +53,7 @@ enum Side {
} }
impl IntPlusOne { impl IntPlusOne {
#[allow(cast_sign_loss)] #[allow(clippy::cast_sign_loss)]
fn check_lit(&self, lit: &Lit, target_value: i128) -> bool { fn check_lit(&self, lit: &Lit, target_value: i128) -> bool {
if let LitKind::Int(value, ..) = lit.node { if let LitKind::Int(value, ..) = lit.node {
return value == (target_value as u128); return value == (target_value as u128);

View file

@ -5,9 +5,10 @@
#![feature(slice_patterns)] #![feature(slice_patterns)]
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]
#![feature(range_contains)] #![feature(range_contains)]
#![allow(unknown_lints, shadow_reuse, missing_docs_in_private_items)] #![allow(unknown_lints, clippy::shadow_reuse, clippy::missing_docs_in_private_items)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![feature(macro_at_most_once_rep)] #![feature(macro_at_most_once_rep)]
#![feature(tool_lints)]
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use toml; use toml;
@ -933,7 +934,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
// only exists to let the dogfood integration test works. // only exists to let the dogfood integration test works.
// Don't run clippy as an executable directly // Don't run clippy as an executable directly
#[allow(dead_code, print_stdout)] #[allow(dead_code, clippy::print_stdout)]
fn main() { fn main() {
panic!("Please use the cargo-clippy executable"); panic!("Please use the cargo-clippy executable");
} }

View file

@ -714,7 +714,7 @@ impl LintPass for Pass {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
#[allow(cyclomatic_complexity)] #[allow(clippy::cyclomatic_complexity)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if in_macro(expr.span) { if in_macro(expr.span) {
return; return;
@ -922,7 +922,7 @@ fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Spa
} }
/// Check for `*or(foo())`. /// Check for `*or(foo())`.
#[allow(too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn check_general_case( fn check_general_case(
cx: &LateContext<'_, '_>, cx: &LateContext<'_, '_>,
name: &str, name: &str,

View file

@ -32,7 +32,7 @@ impl LintPass for NegMultiply {
} }
} }
#[allow(match_same_arms)] #[allow(clippy::match_same_arms)]
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref l, ref r) = e.node { if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref l, ref r) = e.node {

View file

@ -1525,7 +1525,7 @@ enum FullInt {
} }
impl FullInt { impl FullInt {
#[allow(cast_sign_loss)] #[allow(clippy::cast_sign_loss)]
fn cmp_s_u(s: i128, u: u128) -> Ordering { fn cmp_s_u(s: i128, u: u128) -> Ordering {
if s < 0 { if s < 0 {
Ordering::Less Ordering::Less
@ -1744,7 +1744,7 @@ impl LintPass for ImplicitHasher {
} }
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
#[allow(cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
use syntax_pos::BytePos; use syntax_pos::BytePos;

View file

@ -1,7 +1,7 @@
//! A group of attributes that can be attached to Rust code in order //! A group of attributes that can be attached to Rust code in order
//! to generate a clippy lint detecting said code automatically. //! to generate a clippy lint detecting said code automatically.
#![allow(print_stdout, use_debug)] #![allow(clippy::print_stdout, clippy::use_debug)]
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};

View file

@ -1,6 +1,6 @@
//! Utility functions about comparison operators. //! Utility functions about comparison operators.
#![deny(missing_docs_in_private_items)] #![deny(clippy::missing_docs_in_private_items)]
use rustc::hir::{BinOpKind, Expr}; use rustc::hir::{BinOpKind, Expr};

View file

@ -1,6 +1,6 @@
//! Read configurations files. //! Read configurations files.
#![deny(missing_docs_in_private_items)] #![deny(clippy::missing_docs_in_private_items)]
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::{env, fmt, fs, io, path}; use std::{env, fmt, fs, io, path};

View file

@ -1,6 +1,6 @@
//! This module contains some useful constants. //! This module contains some useful constants.
#![deny(missing_docs_in_private_items)] #![deny(clippy::missing_docs_in_private_items)]
/// List of the built-in types names. /// List of the built-in types names.
/// ///

View file

@ -1,7 +1,7 @@
//! This module contains functions for retrieve the original AST from lowered //! This module contains functions for retrieve the original AST from lowered
//! `hir`. //! `hir`.
#![deny(missing_docs_in_private_items)] #![deny(clippy::missing_docs_in_private_items)]
use if_chain::if_chain; use if_chain::if_chain;
use rustc::{hir, ty}; use rustc::{hir, ty};

View file

@ -364,7 +364,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
}.hash(&mut self.s); }.hash(&mut self.s);
} }
#[allow(many_single_char_names)] #[allow(clippy::many_single_char_names)]
pub fn hash_expr(&mut self, e: &Expr) { pub fn hash_expr(&mut self, e: &Expr) {
if let Some(e) = constant_simple(self.cx, self.tables, e) { if let Some(e) = constant_simple(self.cx, self.tables, e) {
return e.hash(&mut self.s); return e.hash(&mut self.s);

View file

@ -1,4 +1,4 @@
#![allow(print_stdout, use_debug)] #![allow(clippy::print_stdout, clippy::use_debug)]
//! checks for attributes //! checks for attributes

View file

@ -1,7 +1,5 @@
//! Contains utility functions to generate suggestions. //! Contains utility functions to generate suggestions.
#![deny(missing_docs_in_private_items)] #![deny(clippy::missing_docs_in_private_items)]
// currently ignores lifetimes and generics
#![allow(use_self)]
use matches::matches; use matches::matches;
use rustc::hir; use rustc::hir;
@ -40,7 +38,7 @@ impl Display for Sugg<'_> {
} }
} }
#[allow(wrong_self_convention)] // ok, because of the function `as_ty` method #[allow(clippy::wrong_self_convention)] // ok, because of the function `as_ty` method
impl<'a> Sugg<'a> { impl<'a> Sugg<'a> {
/// Prepare a suggestion from an expression. /// Prepare a suggestion from an expression.
pub fn hir_opt(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option<Self> { pub fn hir_opt(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option<Self> {

View file

@ -1,13 +1,14 @@
// error-pattern:yummy // error-pattern:yummy
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![allow(unknown_lints, missing_docs_in_private_items)] #![feature(tool_lints)]
#![allow(unknown_lints, clippy::missing_docs_in_private_items)]
use rustc_driver::{self, driver::CompileController, Compilation}; use rustc_driver::{self, driver::CompileController, Compilation};
use rustc_plugin; use rustc_plugin;
use std::process::{exit, Command}; use std::process::{exit, Command};
#[allow(print_stdout)] #[allow(clippy::print_stdout)]
fn show_version() { fn show_version() {
println!(env!("CARGO_PKG_VERSION")); println!(env!("CARGO_PKG_VERSION"));
} }

View file

@ -1,8 +1,9 @@
// error-pattern:cargo-clippy // error-pattern:cargo-clippy
#![feature(plugin_registrar)] #![feature(plugin_registrar)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(tool_lints)]
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(missing_docs_in_private_items)] #![allow(clippy::missing_docs_in_private_items)]
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
use rustc_plugin::Registry; use rustc_plugin::Registry;

View file

@ -1,7 +1,8 @@
// error-pattern:yummy // error-pattern:yummy
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![allow(unknown_lints, missing_docs_in_private_items)] #![feature(tool_lints)]
#![allow(unknown_lints, clippy::missing_docs_in_private_items)]
const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code. const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
@ -28,12 +29,12 @@ it to allow or deny lints from the code, eg.:
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))] #[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
"#; "#;
#[allow(print_stdout)] #[allow(clippy::print_stdout)]
fn show_help() { fn show_help() {
println!("{}", CARGO_CLIPPY_HELP); println!("{}", CARGO_CLIPPY_HELP);
} }
#[allow(print_stdout)] #[allow(clippy::print_stdout)]
fn show_version() { fn show_version() {
println!(env!("CARGO_PKG_VERSION")); println!(env!("CARGO_PKG_VERSION"));
} }