Skip to content

Commit f49ef0e

Browse files
committed
Dogfood
1 parent 462df72 commit f49ef0e

File tree

6 files changed

+73
-75
lines changed

6 files changed

+73
-75
lines changed

clippy_lints/src/approx_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
7272
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
7373
let s = s.as_str();
7474
if s.parse::<f64>().is_ok() {
75-
for &(constant, name, min_digits) in KNOWN_CONSTS.iter() {
75+
for &(constant, name, min_digits) in &KNOWN_CONSTS {
7676
if is_approx_const(constant, &s, min_digits) {
7777
span_lint(
7878
cx,

clippy_lints/src/infinite_iter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [
139139
fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
140140
match expr.node {
141141
ExprKind::MethodCall(ref method, _, ref args) => {
142-
for &(name, len, heuristic, cap) in HEURISTICS.iter() {
142+
for &(name, len, heuristic, cap) in &HEURISTICS {
143143
if method.ident.name.as_str() == name && args.len() == len {
144144
return (match heuristic {
145145
Always => Infinite,
@@ -215,12 +215,12 @@ const INFINITE_COLLECTORS: [&[&str]; 8] = [
215215
fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
216216
match expr.node {
217217
ExprKind::MethodCall(ref method, _, ref args) => {
218-
for &(name, len) in COMPLETING_METHODS.iter() {
218+
for &(name, len) in &COMPLETING_METHODS {
219219
if method.ident.name.as_str() == name && args.len() == len {
220220
return is_infinite(cx, &args[0]);
221221
}
222222
}
223-
for &(name, len) in POSSIBLY_COMPLETING_METHODS.iter() {
223+
for &(name, len) in &POSSIBLY_COMPLETING_METHODS {
224224
if method.ident.name.as_str() == name && args.len() == len {
225225
return MaybeInfinite.and(is_infinite(cx, &args[0]));
226226
}

clippy_lints/src/methods/mod.rs

+56-61
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::fmt;
66
use std::iter;
77

88
use if_chain::if_chain;
9-
use lazy_static::lazy_static;
109
use matches::matches;
1110
use rustc::hir;
1211
use rustc::hir::def::{DefKind, Res};
@@ -17,7 +16,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
1716
use rustc_errors::Applicability;
1817
use syntax::ast;
1918
use syntax::source_map::{BytePos, Span};
20-
use syntax::symbol::{LocalInternedString, Symbol};
19+
use syntax::symbol::LocalInternedString;
2120

2221
use crate::utils::paths;
2322
use crate::utils::sugg;
@@ -914,8 +913,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
914913

915914
match self_ty.sty {
916915
ty::Ref(_, ty, _) if ty.sty == ty::Str => {
917-
for &(method, pos) in PATTERN_METHODS.iter() {
918-
if method_call.ident.name == method && args.len() > pos {
916+
for &(method, pos) in &PATTERN_METHODS {
917+
if method_call.ident.name.as_str() == method && args.len() > pos {
919918
lint_single_char_pattern(cx, expr, &args[pos]);
920919
}
921920
}
@@ -945,7 +944,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
945944
if in_external_macro(cx.sess(), implitem.span) {
946945
return;
947946
}
948-
let name = implitem.ident.name;
947+
let name = implitem.ident.name.as_str();
949948
let parent = cx.tcx.hir().get_parent_item(implitem.hir_id);
950949
let item = cx.tcx.hir().expect_item_by_hir_id(parent);
951950
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
@@ -958,7 +957,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
958957
then {
959958
if cx.access_levels.is_exported(implitem.hir_id) {
960959
// check missing trait implementations
961-
for &(method_name, n_args, self_kind, out_type, trait_name) in TRAIT_METHODS.iter() {
960+
for &(method_name, n_args, self_kind, out_type, trait_name) in &TRAIT_METHODS {
962961
if name == method_name &&
963962
sig.decl.inputs.len() == n_args &&
964963
out_type.matches(cx, &sig.decl.output) &&
@@ -973,7 +972,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
973972
// check conventions w.r.t. conversion method names and predicates
974973
let is_copy = is_copy(cx, ty);
975974
for &(ref conv, self_kinds) in &CONVENTIONS {
976-
if conv.check(&name.as_str()) {
975+
if conv.check(&name) {
977976
if !self_kinds
978977
.iter()
979978
.any(|k| k.matches(cx, first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics)) {
@@ -1032,7 +1031,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
10321031
}
10331032
}
10341033

1035-
if name == sym!(new) && !same_tys(cx, ret_ty, ty) {
1034+
if name == "new" && !same_tys(cx, ret_ty, ty) {
10361035
span_lint(
10371036
cx,
10381037
NEW_RET_NO_SELF,
@@ -2407,63 +2406,59 @@ const CONVENTIONS: [(Convention, &[SelfKind]); 7] = [
24072406
];
24082407

24092408
#[rustfmt::skip]
2410-
lazy_static! {
2411-
static ref TRAIT_METHODS: [(Symbol, usize, SelfKind, OutType, &'static str); 30] = [
2412-
(sym!(add), 2, SelfKind::Value, OutType::Any, "std::ops::Add"),
2413-
(sym!(as_mut), 1, SelfKind::RefMut, OutType::Ref, "std::convert::AsMut"),
2414-
(sym!(as_ref), 1, SelfKind::Ref, OutType::Ref, "std::convert::AsRef"),
2415-
(sym!(bitand), 2, SelfKind::Value, OutType::Any, "std::ops::BitAnd"),
2416-
(sym!(bitor), 2, SelfKind::Value, OutType::Any, "std::ops::BitOr"),
2417-
(sym!(bitxor), 2, SelfKind::Value, OutType::Any, "std::ops::BitXor"),
2418-
(sym!(borrow), 1, SelfKind::Ref, OutType::Ref, "std::borrow::Borrow"),
2419-
(sym!(borrow_mut), 1, SelfKind::RefMut, OutType::Ref, "std::borrow::BorrowMut"),
2420-
(sym!(clone), 1, SelfKind::Ref, OutType::Any, "std::clone::Clone"),
2421-
(sym!(cmp), 2, SelfKind::Ref, OutType::Any, "std::cmp::Ord"),
2422-
(sym!(default), 0, SelfKind::No, OutType::Any, "std::default::Default"),
2423-
(sym!(deref), 1, SelfKind::Ref, OutType::Ref, "std::ops::Deref"),
2424-
(sym!(deref_mut), 1, SelfKind::RefMut, OutType::Ref, "std::ops::DerefMut"),
2425-
(sym!(div), 2, SelfKind::Value, OutType::Any, "std::ops::Div"),
2426-
(sym!(drop), 1, SelfKind::RefMut, OutType::Unit, "std::ops::Drop"),
2427-
(sym!(eq), 2, SelfKind::Ref, OutType::Bool, "std::cmp::PartialEq"),
2428-
(sym!(from_iter), 1, SelfKind::No, OutType::Any, "std::iter::FromIterator"),
2429-
(sym!(from_str), 1, SelfKind::No, OutType::Any, "std::str::FromStr"),
2430-
(sym!(hash), 2, SelfKind::Ref, OutType::Unit, "std::hash::Hash"),
2431-
(sym!(index), 2, SelfKind::Ref, OutType::Ref, "std::ops::Index"),
2432-
(sym!(index_mut), 2, SelfKind::RefMut, OutType::Ref, "std::ops::IndexMut"),
2433-
(sym!(into_iter), 1, SelfKind::Value, OutType::Any, "std::iter::IntoIterator"),
2434-
(sym!(mul), 2, SelfKind::Value, OutType::Any, "std::ops::Mul"),
2435-
(sym!(neg), 1, SelfKind::Value, OutType::Any, "std::ops::Neg"),
2436-
(sym!(next), 1, SelfKind::RefMut, OutType::Any, "std::iter::Iterator"),
2437-
(sym!(not), 1, SelfKind::Value, OutType::Any, "std::ops::Not"),
2438-
(sym!(rem), 2, SelfKind::Value, OutType::Any, "std::ops::Rem"),
2439-
(sym!(shl), 2, SelfKind::Value, OutType::Any, "std::ops::Shl"),
2440-
(sym!(shr), 2, SelfKind::Value, OutType::Any, "std::ops::Shr"),
2441-
(sym!(sub), 2, SelfKind::Value, OutType::Any, "std::ops::Sub"),
2409+
const TRAIT_METHODS: [(&str, usize, SelfKind, OutType, &str); 30] = [
2410+
("add", 2, SelfKind::Value, OutType::Any, "std::ops::Add"),
2411+
("as_mut", 1, SelfKind::RefMut, OutType::Ref, "std::convert::AsMut"),
2412+
("as_ref", 1, SelfKind::Ref, OutType::Ref, "std::convert::AsRef"),
2413+
("bitand", 2, SelfKind::Value, OutType::Any, "std::ops::BitAnd"),
2414+
("bitor", 2, SelfKind::Value, OutType::Any, "std::ops::BitOr"),
2415+
("bitxor", 2, SelfKind::Value, OutType::Any, "std::ops::BitXor"),
2416+
("borrow", 1, SelfKind::Ref, OutType::Ref, "std::borrow::Borrow"),
2417+
("borrow_mut", 1, SelfKind::RefMut, OutType::Ref, "std::borrow::BorrowMut"),
2418+
("clone", 1, SelfKind::Ref, OutType::Any, "std::clone::Clone"),
2419+
("cmp", 2, SelfKind::Ref, OutType::Any, "std::cmp::Ord"),
2420+
("default", 0, SelfKind::No, OutType::Any, "std::default::Default"),
2421+
("deref", 1, SelfKind::Ref, OutType::Ref, "std::ops::Deref"),
2422+
("deref_mut", 1, SelfKind::RefMut, OutType::Ref, "std::ops::DerefMut"),
2423+
("div", 2, SelfKind::Value, OutType::Any, "std::ops::Div"),
2424+
("drop", 1, SelfKind::RefMut, OutType::Unit, "std::ops::Drop"),
2425+
("eq", 2, SelfKind::Ref, OutType::Bool, "std::cmp::PartialEq"),
2426+
("from_iter", 1, SelfKind::No, OutType::Any, "std::iter::FromIterator"),
2427+
("from_str", 1, SelfKind::No, OutType::Any, "std::str::FromStr"),
2428+
("hash", 2, SelfKind::Ref, OutType::Unit, "std::hash::Hash"),
2429+
("index", 2, SelfKind::Ref, OutType::Ref, "std::ops::Index"),
2430+
("index_mut", 2, SelfKind::RefMut, OutType::Ref, "std::ops::IndexMut"),
2431+
("into_iter", 1, SelfKind::Value, OutType::Any, "std::iter::IntoIterator"),
2432+
("mul", 2, SelfKind::Value, OutType::Any, "std::ops::Mul"),
2433+
("neg", 1, SelfKind::Value, OutType::Any, "std::ops::Neg"),
2434+
("next", 1, SelfKind::RefMut, OutType::Any, "std::iter::Iterator"),
2435+
("not", 1, SelfKind::Value, OutType::Any, "std::ops::Not"),
2436+
("rem", 2, SelfKind::Value, OutType::Any, "std::ops::Rem"),
2437+
("shl", 2, SelfKind::Value, OutType::Any, "std::ops::Shl"),
2438+
("shr", 2, SelfKind::Value, OutType::Any, "std::ops::Shr"),
2439+
("sub", 2, SelfKind::Value, OutType::Any, "std::ops::Sub"),
24422440
];
2443-
}
24442441

24452442
#[rustfmt::skip]
2446-
lazy_static! {
2447-
static ref PATTERN_METHODS: [(Symbol, usize); 17] = [
2448-
(sym!(contains), 1),
2449-
(sym!(starts_with), 1),
2450-
(sym!(ends_with), 1),
2451-
(sym!(find), 1),
2452-
(sym!(rfind), 1),
2453-
(sym!(split), 1),
2454-
(sym!(rsplit), 1),
2455-
(sym!(split_terminator), 1),
2456-
(sym!(rsplit_terminator), 1),
2457-
(sym!(splitn), 2),
2458-
(sym!(rsplitn), 2),
2459-
(sym!(matches), 1),
2460-
(sym!(rmatches), 1),
2461-
(sym!(match_indices), 1),
2462-
(sym!(rmatch_indices), 1),
2463-
(sym!(trim_start_matches), 1),
2464-
(sym!(trim_end_matches), 1),
2443+
const PATTERN_METHODS: [(&str, usize); 17] = [
2444+
("contains", 1),
2445+
("starts_with", 1),
2446+
("ends_with", 1),
2447+
("find", 1),
2448+
("rfind", 1),
2449+
("split", 1),
2450+
("rsplit", 1),
2451+
("split_terminator", 1),
2452+
("rsplit_terminator", 1),
2453+
("splitn", 2),
2454+
("rsplitn", 2),
2455+
("matches", 1),
2456+
("rmatches", 1),
2457+
("match_indices", 1),
2458+
("rmatch_indices", 1),
2459+
("trim_start_matches", 1),
2460+
("trim_end_matches", 1),
24652461
];
2466-
}
24672462

24682463
#[derive(Clone, Copy, PartialEq, Debug)]
24692464
enum SelfKind {

clippy_lints/src/replace_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts {
3737
if let hir::ExprKind::Path(ref qp) = expr.node;
3838
if let Res::Def(DefKind::Const, def_id) = cx.tables.qpath_res(qp, expr.hir_id);
3939
then {
40-
for (const_path, repl_snip) in REPLACEMENTS.iter() {
40+
for (const_path, repl_snip) in &REPLACEMENTS {
4141
if match_def_path(cx, def_id, const_path) {
4242
span_lint_and_sugg(
4343
cx,

clippy_lints/src/utils/internal_lints.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use rustc::hir::*;
77
use rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
88
use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10-
use syntax::ast::{Crate as AstCrate, Name};
10+
use syntax::ast::{Crate as AstCrate, ItemKind, Name};
1111
use syntax::source_map::Span;
12+
use syntax_pos::symbol::LocalInternedString;
1213

1314
declare_clippy_lint! {
1415
/// **What it does:** Checks for various things we like to keep tidy in clippy.
@@ -74,12 +75,15 @@ declare_clippy_lint! {
7475
declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
7576

7677
impl EarlyLintPass for ClippyLintsInternal {
77-
fn check_crate(&mut self, _cx: &EarlyContext<'_>, _krate: &AstCrate) {
78-
/*
79-
FIXME: turn back on when we get rid of all the lazy_statics
80-
if let Some(utils) = krate.module.items.iter().find(|item| item.ident.name == sym!(utils)) {
78+
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &AstCrate) {
79+
if let Some(utils) = krate
80+
.module
81+
.items
82+
.iter()
83+
.find(|item| item.ident.name.as_str() == "utils")
84+
{
8185
if let ItemKind::Mod(ref utils_mod) = utils.node {
82-
if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name == sym!(paths)) {
86+
if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name.as_str() == "paths") {
8387
if let ItemKind::Mod(ref paths_mod) = paths.node {
8488
let mut last_name: Option<LocalInternedString> = None;
8589
for item in &*paths_mod.items {
@@ -101,7 +105,6 @@ impl EarlyLintPass for ClippyLintsInternal {
101105
}
102106
}
103107
}
104-
*/
105108
}
106109
}
107110

clippy_lints/src/utils/paths.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ pub const RESULT_OK: [&str; 4] = ["core", "result", "Result", "Ok"];
9696
pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
9797
pub const SLICE_INTO_VEC: [&str; 4] = ["alloc", "slice", "<impl [T]>", "into_vec"];
9898
pub const SLICE_ITER: [&str; 3] = ["core", "slice", "Iter"];
99-
pub const STD_MEM_TRANSMUTE: [&str; 3] = ["std", "mem", "transmute"];
100-
pub const STD_PTR_NULL: [&str; 3] = ["std", "ptr", "null"];
10199
pub const STDERR: [&str; 4] = ["std", "io", "stdio", "stderr"];
102100
pub const STDOUT: [&str; 4] = ["std", "io", "stdio", "stdout"];
101+
pub const STD_MEM_TRANSMUTE: [&str; 3] = ["std", "mem", "transmute"];
102+
pub const STD_PTR_NULL: [&str; 3] = ["std", "ptr", "null"];
103103
pub const STRING: [&str; 3] = ["alloc", "string", "String"];
104104
pub const TO_OWNED: [&str; 3] = ["alloc", "borrow", "ToOwned"];
105105
pub const TO_OWNED_METHOD: [&str; 4] = ["alloc", "borrow", "ToOwned", "to_owned"];

0 commit comments

Comments
 (0)