From a6601f2d02389dbde250c2538b4482fa4613efab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Mon, 25 Jun 2018 20:50:20 +0200 Subject: [PATCH] Enable rust_2018_idioms warning --- build.rs | 3 -- clippy_lints/src/copies.rs | 6 ++-- clippy_lints/src/lib.rs | 35 +++------------------- clippy_lints/src/literal_representation.rs | 18 +++++------ clippy_lints/src/utils/conf.rs | 11 ++++++- src/driver.rs | 12 ++------ src/lib.rs | 4 +-- 7 files changed, 29 insertions(+), 60 deletions(-) diff --git a/build.rs b/build.rs index 1481f460fc3..241c8579a48 100644 --- a/build.rs +++ b/build.rs @@ -13,9 +13,6 @@ //! This build script was originally taken from the Rocket web framework: //! https://github.com/SergioBenitez/Rocket -extern crate ansi_term; -extern crate rustc_version; - use ansi_term::Colour::Red; use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta}; use std::env; diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index abbc4681166..2e2489cbb4a 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -134,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { /// Implementation of `IF_SAME_THEN_ELSE`. fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) { - let eq: &Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) }; + let eq: &dyn Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) }; if let Some((i, j)) = search_same_sequenced(blocks, eq) { span_note_and_lint( @@ -150,13 +150,13 @@ fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) { /// Implementation of `IFS_SAME_COND`. fn lint_same_cond(cx: &LateContext, conds: &[&Expr]) { - let hash: &Fn(&&Expr) -> u64 = &|expr| -> u64 { + let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 { let mut h = SpanlessHash::new(cx, cx.tables); h.hash_expr(expr); h.finish() }; - let eq: &Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) }; + let eq: &dyn Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) }; if let Some((i, j)) = search_same(conds, hash, eq) { span_note_and_lint( diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 34799635884..43fcd786773 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -12,50 +12,23 @@ #![feature(iterator_find_map)] #![feature(macro_at_most_once_rep)] #![feature(rust_2018_preview)] +#![warn(rust_2018_idioms)] -extern crate cargo_metadata; #[macro_use] extern crate rustc; -extern crate rustc_target; -extern crate rustc_typeck; -extern crate syntax; -extern crate syntax_pos; -extern crate toml; - -// for unicode nfc normalization - -extern crate unicode_normalization; - -// for semver check in attrs.rs - -extern crate semver; - -// for regex checking - -extern crate regex_syntax; - -// for finding minimal boolean expressions - -extern crate quine_mc_cluskey; - -extern crate rustc_errors; -extern crate rustc_plugin; +use toml; +use rustc_plugin; #[macro_use] extern crate matches as matches_macro; -extern crate serde; #[macro_use] extern crate serde_derive; #[macro_use] extern crate lazy_static; -extern crate itertools; -extern crate pulldown_cmark; -extern crate url; - #[macro_use] extern crate if_chain; @@ -211,7 +184,7 @@ pub mod zero_div_zero; // end lints modules, do not remove this comment, it’s used in `update_lints` mod reexport { - pub use syntax::ast::{Name, NodeId}; + crate use syntax::ast::{Name, NodeId}; } #[cfg_attr(rustfmt, rustfmt_skip)] diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 09b66b872e9..9b6c30f7f4c 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -90,7 +90,7 @@ pub(super) enum Radix { impl Radix { /// Return a reasonable digit group size for this radix. - pub fn suggest_grouping(&self) -> usize { + crate fn suggest_grouping(&self) -> usize { match *self { Radix::Binary | Radix::Hexadecimal => 4, Radix::Octal | Radix::Decimal => 3, @@ -101,19 +101,19 @@ impl Radix { #[derive(Debug)] pub(super) struct DigitInfo<'a> { /// Characters of a literal between the radix prefix and type suffix. - pub digits: &'a str, + crate digits: &'a str, /// Which radix the literal was represented in. - pub radix: Radix, + crate radix: Radix, /// The radix prefix, if present. - pub prefix: Option<&'a str>, + crate prefix: Option<&'a str>, /// The type suffix, including preceding underscore if present. - pub suffix: Option<&'a str>, + crate suffix: Option<&'a str>, /// True for floating-point literals. - pub float: bool, + crate float: bool, } impl<'a> DigitInfo<'a> { - pub fn new(lit: &'a str, float: bool) -> Self { + crate fn new(lit: &'a str, float: bool) -> Self { // Determine delimiter for radix prefix, if present, and radix. let radix = if lit.starts_with("0x") { Radix::Hexadecimal @@ -160,7 +160,7 @@ impl<'a> DigitInfo<'a> { } /// Returns digits grouped in a sensible way. - pub fn grouping_hint(&self) -> String { + crate fn grouping_hint(&self) -> String { let group_size = self.radix.suggest_grouping(); if self.digits.contains('.') { let mut parts = self.digits.split('.'); @@ -227,7 +227,7 @@ enum WarningType { } impl WarningType { - pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: syntax_pos::Span) { + crate fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: syntax_pos::Span) { match self { WarningType::UnreadableLiteral => span_lint_and_sugg( cx, diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index d3c7d901323..05abdd2f13c 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -76,6 +76,15 @@ lazy_static! { macro_rules! define_Conf { ($(#[$doc: meta] ($rust_name: ident, $rust_name_str: expr, $default: expr => $($ty: tt)+),)+) => { pub use self::helpers::Conf; + // FIXME(mati865): remove #[allow(rust_2018_idioms)] when it's fixed: + // + // warning: `extern crate` is not idiomatic in the new edition + // --> src/utils/conf.rs:82:22 + // | + // 82 | #[derive(Deserialize)] + // | ^^^^^^^^^^^ help: convert it to a `use` + // + #[allow(rust_2018_idioms)] mod helpers { /// Type used to store lint configuration. #[derive(Deserialize)] @@ -92,7 +101,7 @@ macro_rules! define_Conf { mod $rust_name { use serde; use serde::Deserialize; - pub fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D) + crate fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result { type T = define_Conf!(TY $($ty)+); Ok(T::deserialize(deserializer).unwrap_or_else(|e| { diff --git a/src/driver.rs b/src/driver.rs index 419f61f860b..585edcd82a6 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -3,16 +3,8 @@ #![feature(rustc_private)] #![allow(unknown_lints, missing_docs_in_private_items)] -extern crate clippy_lints; -extern crate getopts; -extern crate rustc; -extern crate rustc_codegen_utils; -extern crate rustc_driver; -extern crate rustc_errors; -extern crate rustc_plugin; -extern crate syntax; - -use rustc_driver::{driver::CompileController, Compilation}; +use rustc_driver::{self, driver::CompileController, Compilation}; +use rustc_plugin; use std::process::{exit, Command}; #[allow(print_stdout)] diff --git a/src/lib.rs b/src/lib.rs index 61e5c104bef..6ff15e2cd89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,12 +5,10 @@ #![feature(macro_vis_matcher)] #![allow(unknown_lints)] #![allow(missing_docs_in_private_items)] +#![warn(rust_2018_idioms)] -extern crate rustc_plugin; use rustc_plugin::Registry; -extern crate clippy_lints; - #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { reg.sess.lint_store.with_read_lock(|lint_store| {