Skip to content

Commit a6601f2

Browse files
committed
Enable rust_2018_idioms warning
1 parent 9f8624e commit a6601f2

File tree

7 files changed

+29
-60
lines changed

7 files changed

+29
-60
lines changed

build.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
//! This build script was originally taken from the Rocket web framework:
1414
//! https://github.com/SergioBenitez/Rocket
1515
16-
extern crate ansi_term;
17-
extern crate rustc_version;
18-
1916
use ansi_term::Colour::Red;
2017
use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta};
2118
use std::env;

clippy_lints/src/copies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
134134

135135
/// Implementation of `IF_SAME_THEN_ELSE`.
136136
fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) {
137-
let eq: &Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) };
137+
let eq: &dyn Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) };
138138

139139
if let Some((i, j)) = search_same_sequenced(blocks, eq) {
140140
span_note_and_lint(
@@ -150,13 +150,13 @@ fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) {
150150

151151
/// Implementation of `IFS_SAME_COND`.
152152
fn lint_same_cond(cx: &LateContext, conds: &[&Expr]) {
153-
let hash: &Fn(&&Expr) -> u64 = &|expr| -> u64 {
153+
let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 {
154154
let mut h = SpanlessHash::new(cx, cx.tables);
155155
h.hash_expr(expr);
156156
h.finish()
157157
};
158158

159-
let eq: &Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) };
159+
let eq: &dyn Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) };
160160

161161
if let Some((i, j)) = search_same(conds, hash, eq) {
162162
span_note_and_lint(

clippy_lints/src/lib.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,23 @@
1212
#![feature(iterator_find_map)]
1313
#![feature(macro_at_most_once_rep)]
1414
#![feature(rust_2018_preview)]
15+
#![warn(rust_2018_idioms)]
1516

16-
extern crate cargo_metadata;
1717
#[macro_use]
1818
extern crate rustc;
19-
extern crate rustc_target;
20-
extern crate rustc_typeck;
21-
extern crate syntax;
22-
extern crate syntax_pos;
2319

24-
extern crate toml;
25-
26-
// for unicode nfc normalization
27-
28-
extern crate unicode_normalization;
29-
30-
// for semver check in attrs.rs
31-
32-
extern crate semver;
33-
34-
// for regex checking
35-
36-
extern crate regex_syntax;
37-
38-
// for finding minimal boolean expressions
39-
40-
extern crate quine_mc_cluskey;
41-
42-
extern crate rustc_errors;
43-
extern crate rustc_plugin;
20+
use toml;
21+
use rustc_plugin;
4422

4523
#[macro_use]
4624
extern crate matches as matches_macro;
4725

48-
extern crate serde;
4926
#[macro_use]
5027
extern crate serde_derive;
5128

5229
#[macro_use]
5330
extern crate lazy_static;
5431

55-
extern crate itertools;
56-
extern crate pulldown_cmark;
57-
extern crate url;
58-
5932
#[macro_use]
6033
extern crate if_chain;
6134

@@ -211,7 +184,7 @@ pub mod zero_div_zero;
211184
// end lints modules, do not remove this comment, it’s used in `update_lints`
212185

213186
mod reexport {
214-
pub use syntax::ast::{Name, NodeId};
187+
crate use syntax::ast::{Name, NodeId};
215188
}
216189

217190
#[cfg_attr(rustfmt, rustfmt_skip)]

clippy_lints/src/literal_representation.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub(super) enum Radix {
9090

9191
impl Radix {
9292
/// Return a reasonable digit group size for this radix.
93-
pub fn suggest_grouping(&self) -> usize {
93+
crate fn suggest_grouping(&self) -> usize {
9494
match *self {
9595
Radix::Binary | Radix::Hexadecimal => 4,
9696
Radix::Octal | Radix::Decimal => 3,
@@ -101,19 +101,19 @@ impl Radix {
101101
#[derive(Debug)]
102102
pub(super) struct DigitInfo<'a> {
103103
/// Characters of a literal between the radix prefix and type suffix.
104-
pub digits: &'a str,
104+
crate digits: &'a str,
105105
/// Which radix the literal was represented in.
106-
pub radix: Radix,
106+
crate radix: Radix,
107107
/// The radix prefix, if present.
108-
pub prefix: Option<&'a str>,
108+
crate prefix: Option<&'a str>,
109109
/// The type suffix, including preceding underscore if present.
110-
pub suffix: Option<&'a str>,
110+
crate suffix: Option<&'a str>,
111111
/// True for floating-point literals.
112-
pub float: bool,
112+
crate float: bool,
113113
}
114114

115115
impl<'a> DigitInfo<'a> {
116-
pub fn new(lit: &'a str, float: bool) -> Self {
116+
crate fn new(lit: &'a str, float: bool) -> Self {
117117
// Determine delimiter for radix prefix, if present, and radix.
118118
let radix = if lit.starts_with("0x") {
119119
Radix::Hexadecimal
@@ -160,7 +160,7 @@ impl<'a> DigitInfo<'a> {
160160
}
161161

162162
/// Returns digits grouped in a sensible way.
163-
pub fn grouping_hint(&self) -> String {
163+
crate fn grouping_hint(&self) -> String {
164164
let group_size = self.radix.suggest_grouping();
165165
if self.digits.contains('.') {
166166
let mut parts = self.digits.split('.');
@@ -227,7 +227,7 @@ enum WarningType {
227227
}
228228

229229
impl WarningType {
230-
pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: syntax_pos::Span) {
230+
crate fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: syntax_pos::Span) {
231231
match self {
232232
WarningType::UnreadableLiteral => span_lint_and_sugg(
233233
cx,

clippy_lints/src/utils/conf.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ lazy_static! {
7676
macro_rules! define_Conf {
7777
($(#[$doc: meta] ($rust_name: ident, $rust_name_str: expr, $default: expr => $($ty: tt)+),)+) => {
7878
pub use self::helpers::Conf;
79+
// FIXME(mati865): remove #[allow(rust_2018_idioms)] when it's fixed:
80+
//
81+
// warning: `extern crate` is not idiomatic in the new edition
82+
// --> src/utils/conf.rs:82:22
83+
// |
84+
// 82 | #[derive(Deserialize)]
85+
// | ^^^^^^^^^^^ help: convert it to a `use`
86+
//
87+
#[allow(rust_2018_idioms)]
7988
mod helpers {
8089
/// Type used to store lint configuration.
8190
#[derive(Deserialize)]
@@ -92,7 +101,7 @@ macro_rules! define_Conf {
92101
mod $rust_name {
93102
use serde;
94103
use serde::Deserialize;
95-
pub fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D)
104+
crate fn deserialize<'de, D: serde::Deserializer<'de>>(deserializer: D)
96105
-> Result<define_Conf!(TY $($ty)+), D::Error> {
97106
type T = define_Conf!(TY $($ty)+);
98107
Ok(T::deserialize(deserializer).unwrap_or_else(|e| {

src/driver.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33
#![feature(rustc_private)]
44
#![allow(unknown_lints, missing_docs_in_private_items)]
55

6-
extern crate clippy_lints;
7-
extern crate getopts;
8-
extern crate rustc;
9-
extern crate rustc_codegen_utils;
10-
extern crate rustc_driver;
11-
extern crate rustc_errors;
12-
extern crate rustc_plugin;
13-
extern crate syntax;
14-
15-
use rustc_driver::{driver::CompileController, Compilation};
6+
use rustc_driver::{self, driver::CompileController, Compilation};
7+
use rustc_plugin;
168
use std::process::{exit, Command};
179

1810
#[allow(print_stdout)]

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
#![feature(macro_vis_matcher)]
66
#![allow(unknown_lints)]
77
#![allow(missing_docs_in_private_items)]
8+
#![warn(rust_2018_idioms)]
89

9-
extern crate rustc_plugin;
1010
use rustc_plugin::Registry;
1111

12-
extern crate clippy_lints;
13-
1412
#[plugin_registrar]
1513
pub fn plugin_registrar(reg: &mut Registry) {
1614
reg.sess.lint_store.with_read_lock(|lint_store| {

0 commit comments

Comments
 (0)