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:
//! 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;

View File

@ -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(

View File

@ -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, its used in `update_lints`
mod reexport {
pub use syntax::ast::{Name, NodeId};
crate use syntax::ast::{Name, NodeId};
}
#[cfg_attr(rustfmt, rustfmt_skip)]

View File

@ -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,

View File

@ -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<define_Conf!(TY $($ty)+), D::Error> {
type T = define_Conf!(TY $($ty)+);
Ok(T::deserialize(deserializer).unwrap_or_else(|e| {

View File

@ -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)]

View File

@ -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| {