1
Fork 0

Enable rust_2018_idioms warning

This commit is contained in:
Mateusz Mikuła 2018-06-25 20:50:20 +02:00
parent 9f8624e5bf
commit a6601f2d02
7 changed files with 29 additions and 60 deletions

View file

@ -13,9 +13,6 @@
//! This build script was originally taken from the Rocket web framework: //! This build script was originally taken from the Rocket web framework:
//! https://github.com/SergioBenitez/Rocket //! https://github.com/SergioBenitez/Rocket
extern crate ansi_term;
extern crate rustc_version;
use ansi_term::Colour::Red; use ansi_term::Colour::Red;
use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta}; use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta};
use std::env; use std::env;

View file

@ -134,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
/// Implementation of `IF_SAME_THEN_ELSE`. /// Implementation of `IF_SAME_THEN_ELSE`.
fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) { 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) { if let Some((i, j)) = search_same_sequenced(blocks, eq) {
span_note_and_lint( span_note_and_lint(
@ -150,13 +150,13 @@ fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) {
/// Implementation of `IFS_SAME_COND`. /// Implementation of `IFS_SAME_COND`.
fn lint_same_cond(cx: &LateContext, conds: &[&Expr]) { 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); let mut h = SpanlessHash::new(cx, cx.tables);
h.hash_expr(expr); h.hash_expr(expr);
h.finish() 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) { if let Some((i, j)) = search_same(conds, hash, eq) {
span_note_and_lint( span_note_and_lint(

View file

@ -12,50 +12,23 @@
#![feature(iterator_find_map)] #![feature(iterator_find_map)]
#![feature(macro_at_most_once_rep)] #![feature(macro_at_most_once_rep)]
#![feature(rust_2018_preview)] #![feature(rust_2018_preview)]
#![warn(rust_2018_idioms)]
extern crate cargo_metadata;
#[macro_use] #[macro_use]
extern crate rustc; extern crate rustc;
extern crate rustc_target;
extern crate rustc_typeck;
extern crate syntax;
extern crate syntax_pos;
extern crate toml; use toml;
use rustc_plugin;
// 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;
#[macro_use] #[macro_use]
extern crate matches as matches_macro; extern crate matches as matches_macro;
extern crate serde;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
extern crate itertools;
extern crate pulldown_cmark;
extern crate url;
#[macro_use] #[macro_use]
extern crate if_chain; extern crate if_chain;
@ -211,7 +184,7 @@ pub mod zero_div_zero;
// end lints modules, do not remove this comment, its used in `update_lints` // end lints modules, do not remove this comment, its used in `update_lints`
mod reexport { mod reexport {
pub use syntax::ast::{Name, NodeId}; crate use syntax::ast::{Name, NodeId};
} }
#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(rustfmt, rustfmt_skip)]

View file

@ -90,7 +90,7 @@ pub(super) enum Radix {
impl Radix { impl Radix {
/// Return a reasonable digit group size for this radix. /// Return a reasonable digit group size for this radix.
pub fn suggest_grouping(&self) -> usize { crate fn suggest_grouping(&self) -> usize {
match *self { match *self {
Radix::Binary | Radix::Hexadecimal => 4, Radix::Binary | Radix::Hexadecimal => 4,
Radix::Octal | Radix::Decimal => 3, Radix::Octal | Radix::Decimal => 3,
@ -101,19 +101,19 @@ impl Radix {
#[derive(Debug)] #[derive(Debug)]
pub(super) struct DigitInfo<'a> { pub(super) struct DigitInfo<'a> {
/// Characters of a literal between the radix prefix and type suffix. /// 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. /// Which radix the literal was represented in.
pub radix: Radix, crate radix: Radix,
/// The radix prefix, if present. /// The radix prefix, if present.
pub prefix: Option<&'a str>, crate prefix: Option<&'a str>,
/// The type suffix, including preceding underscore if present. /// The type suffix, including preceding underscore if present.
pub suffix: Option<&'a str>, crate suffix: Option<&'a str>,
/// True for floating-point literals. /// True for floating-point literals.
pub float: bool, crate float: bool,
} }
impl<'a> DigitInfo<'a> { 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. // Determine delimiter for radix prefix, if present, and radix.
let radix = if lit.starts_with("0x") { let radix = if lit.starts_with("0x") {
Radix::Hexadecimal Radix::Hexadecimal
@ -160,7 +160,7 @@ impl<'a> DigitInfo<'a> {
} }
/// Returns digits grouped in a sensible way. /// 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(); let group_size = self.radix.suggest_grouping();
if self.digits.contains('.') { if self.digits.contains('.') {
let mut parts = self.digits.split('.'); let mut parts = self.digits.split('.');
@ -227,7 +227,7 @@ enum WarningType {
} }
impl 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 { match self {
WarningType::UnreadableLiteral => span_lint_and_sugg( WarningType::UnreadableLiteral => span_lint_and_sugg(
cx, cx,

View file

@ -76,6 +76,15 @@ lazy_static! {
macro_rules! define_Conf { macro_rules! define_Conf {
($(#[$doc: meta] ($rust_name: ident, $rust_name_str: expr, $default: expr => $($ty: tt)+),)+) => { ($(#[$doc: meta] ($rust_name: ident, $rust_name_str: expr, $default: expr => $($ty: tt)+),)+) => {
pub use self::helpers::Conf; 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 { mod helpers {
/// Type used to store lint configuration. /// Type used to store lint configuration.
#[derive(Deserialize)] #[derive(Deserialize)]
@ -92,7 +101,7 @@ macro_rules! define_Conf {
mod $rust_name { mod $rust_name {
use serde; use serde;
use serde::Deserialize; use serde::Deserialize;
pub fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D) crate fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D)
-> Result<define_Conf!(TY $($ty)+), D::Error> { -> Result<define_Conf!(TY $($ty)+), D::Error> {
type T = define_Conf!(TY $($ty)+); type T = define_Conf!(TY $($ty)+);
Ok(T::deserialize(deserializer).unwrap_or_else(|e| { Ok(T::deserialize(deserializer).unwrap_or_else(|e| {

View file

@ -3,16 +3,8 @@
#![feature(rustc_private)] #![feature(rustc_private)]
#![allow(unknown_lints, missing_docs_in_private_items)] #![allow(unknown_lints, missing_docs_in_private_items)]
extern crate clippy_lints; use rustc_driver::{self, driver::CompileController, Compilation};
extern crate getopts; use rustc_plugin;
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 std::process::{exit, Command}; use std::process::{exit, Command};
#[allow(print_stdout)] #[allow(print_stdout)]

View file

@ -5,12 +5,10 @@
#![feature(macro_vis_matcher)] #![feature(macro_vis_matcher)]
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(missing_docs_in_private_items)] #![allow(missing_docs_in_private_items)]
#![warn(rust_2018_idioms)]
extern crate rustc_plugin;
use rustc_plugin::Registry; use rustc_plugin::Registry;
extern crate clippy_lints;
#[plugin_registrar] #[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
reg.sess.lint_store.with_read_lock(|lint_store| { reg.sess.lint_store.with_read_lock(|lint_store| {