1 // error-pattern:cargo-clippy
3 #![feature(box_syntax)]
4 #![feature(collections)]
5 #![feature(custom_attribute)]
6 #![feature(dotdot_in_tuple_patterns)]
7 #![feature(iter_arith)]
8 #![feature(question_mark)]
9 #![feature(rustc_private)]
10 #![feature(slice_patterns)]
11 #![feature(stmt_expr_attributes)]
12 #![feature(type_macros)]
14 #![allow(indexing_slicing, shadow_reuse, unknown_lints)]
23 // Only for the compile time checking of paths
25 extern crate collections;
27 // for unicode nfc normalization
28 extern crate unicode_normalization;
30 // for semver check in attrs.rs
34 extern crate regex_syntax;
36 // for finding minimal boolean expressions
37 extern crate quine_mc_cluskey;
39 extern crate rustc_serialize;
41 extern crate rustc_errors;
42 extern crate rustc_plugin;
43 extern crate rustc_const_eval;
44 extern crate rustc_const_math;
47 extern crate matches as matches_macro;
49 macro_rules! declare_restriction_lint {
50 { pub $name:tt, $description:tt } => {
51 declare_lint! { pub $name, Allow, $description }
59 // begin lints modules, do not remove this comment, it’s used in `update_lints`
62 pub mod array_indexing;
66 pub mod blacklisted_name;
67 pub mod block_in_if_condition;
69 pub mod collapsible_if;
71 pub mod cyclomatic_complexity;
77 pub mod enum_glob_use;
78 pub mod enum_variants;
81 pub mod eta_reduction;
87 pub mod items_after_statements;
100 pub mod mut_reference;
101 pub mod mutex_atomic;
102 pub mod needless_bool;
103 pub mod needless_borrow;
104 pub mod needless_update;
105 pub mod neg_multiply;
106 pub mod new_without_default;
108 pub mod non_expressive_names;
109 pub mod open_options;
110 pub mod overflow_check_conditional;
121 pub mod temporary_assignment;
125 pub mod unsafe_removed_from_name;
126 pub mod unused_label;
128 pub mod zero_div_zero;
129 // end lints modules, do not remove this comment, it’s used in `update_lints`
132 pub use syntax::ast::{Name, NodeId};
135 #[cfg_attr(rustfmt, rustfmt_skip)]
136 pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
137 let conf = match utils::conf::file(reg.args()) {
139 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
140 // do not require the file to exist
141 let (ref file_name, must_exist) = if let Some(ref file_name) = file_name {
144 ("clippy.toml", false)
147 let (conf, errors) = utils::conf::read(file_name, must_exist);
149 // all conf errors are non-fatal, we just use the default conf in case of error
150 for error in errors {
151 reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit();
156 Err((err, span)) => {
157 reg.sess.struct_span_err(span, err)
158 .span_note(span, "Clippy will use default configuration")
160 utils::conf::Conf::default()
164 let mut store = reg.sess.lint_store.borrow_mut();
165 store.register_removed("unstable_as_slice", "`Vec::as_slice` has been stabilized in 1.7");
166 store.register_removed("unstable_as_mut_slice", "`Vec::as_mut_slice` has been stabilized in 1.7");
167 store.register_removed("str_to_string", "using `str::to_string` is common even today and specialization will likely happen soon");
168 store.register_removed("string_to_string", "using `string::to_string` is common even today and specialization will likely happen soon");
169 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
171 reg.register_late_lint_pass(box types::TypePass);
172 reg.register_late_lint_pass(box booleans::NonminimalBool);
173 reg.register_late_lint_pass(box misc::TopLevelRefPass);
174 reg.register_late_lint_pass(box misc::CmpNan);
175 reg.register_late_lint_pass(box eq_op::EqOp);
176 reg.register_early_lint_pass(box enum_variants::EnumVariantNames::default());
177 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
178 reg.register_late_lint_pass(box enum_clike::UnportableVariant);
179 reg.register_late_lint_pass(box bit_mask::BitMask);
180 reg.register_late_lint_pass(box ptr_arg::PtrArg);
181 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
182 reg.register_late_lint_pass(box needless_bool::BoolComparison);
183 reg.register_late_lint_pass(box approx_const::Pass);
184 reg.register_late_lint_pass(box misc::FloatCmp);
185 reg.register_early_lint_pass(box precedence::Precedence);
186 reg.register_late_lint_pass(box eta_reduction::EtaPass);
187 reg.register_late_lint_pass(box identity_op::IdentityOp);
188 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
189 reg.register_late_lint_pass(box mut_mut::MutMut);
190 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
191 reg.register_late_lint_pass(box len_zero::LenZero);
192 reg.register_late_lint_pass(box misc::CmpOwned);
193 reg.register_late_lint_pass(box attrs::AttrPass);
194 reg.register_early_lint_pass(box collapsible_if::CollapsibleIf);
195 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
196 reg.register_late_lint_pass(box misc::ModuloOne);
197 reg.register_late_lint_pass(box unicode::Unicode);
198 reg.register_late_lint_pass(box strings::StringAdd);
199 reg.register_early_lint_pass(box returns::ReturnPass);
200 reg.register_late_lint_pass(box methods::Pass);
201 reg.register_late_lint_pass(box shadow::Pass);
202 reg.register_late_lint_pass(box types::LetPass);
203 reg.register_late_lint_pass(box types::UnitCmp);
204 reg.register_late_lint_pass(box loops::Pass);
205 reg.register_late_lint_pass(box lifetimes::LifetimePass);
206 reg.register_late_lint_pass(box entry::HashMapLint);
207 reg.register_late_lint_pass(box ranges::StepByZero);
208 reg.register_late_lint_pass(box types::CastPass);
209 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
210 reg.register_late_lint_pass(box matches::MatchPass);
211 reg.register_late_lint_pass(box misc::PatternPass);
212 reg.register_late_lint_pass(box minmax::MinMaxPass);
213 reg.register_late_lint_pass(box open_options::NonSensical);
214 reg.register_late_lint_pass(box zero_div_zero::Pass);
215 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
216 reg.register_late_lint_pass(box needless_update::Pass);
217 reg.register_late_lint_pass(box needless_borrow::NeedlessBorrow);
218 reg.register_late_lint_pass(box no_effect::Pass);
219 reg.register_late_lint_pass(box map_clone::Pass);
220 reg.register_late_lint_pass(box temporary_assignment::Pass);
221 reg.register_late_lint_pass(box transmute::Transmute);
222 reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold));
223 reg.register_late_lint_pass(box escape::Pass);
224 reg.register_early_lint_pass(box misc_early::MiscEarly);
225 reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
226 reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
227 reg.register_late_lint_pass(box panic::Pass);
228 reg.register_late_lint_pass(box strings::StringLitAsBytes);
229 reg.register_late_lint_pass(box derive::Derive);
230 reg.register_late_lint_pass(box types::CharLitAsU8);
231 reg.register_late_lint_pass(box print::Pass);
232 reg.register_late_lint_pass(box vec::Pass);
233 reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
234 max_single_char_names: conf.max_single_char_names,
236 reg.register_late_lint_pass(box drop_ref::Pass);
237 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
238 reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
239 reg.register_late_lint_pass(box regex::Pass::default());
240 reg.register_late_lint_pass(box copies::CopyAndPaste);
241 reg.register_late_lint_pass(box format::Pass);
242 reg.register_early_lint_pass(box formatting::Formatting);
243 reg.register_late_lint_pass(box swap::Swap);
244 reg.register_early_lint_pass(box if_not_else::IfNotElse);
245 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
246 reg.register_late_lint_pass(box unused_label::UnusedLabel);
247 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
248 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names));
249 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
250 reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents));
251 reg.register_late_lint_pass(box neg_multiply::NegMultiply);
252 reg.register_late_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
253 reg.register_late_lint_pass(box mem_forget::MemForget);
254 reg.register_late_lint_pass(box arithmetic::Arithmetic::default());
255 reg.register_late_lint_pass(box assign_ops::AssignOps);
256 reg.register_late_lint_pass(box let_if_seq::LetIfSeq);
258 reg.register_lint_group("clippy_restrictions", vec![
259 arithmetic::FLOAT_ARITHMETIC,
260 arithmetic::INTEGER_ARITHMETIC,
261 assign_ops::ASSIGN_OPS,
264 reg.register_lint_group("clippy_pedantic", vec![
265 array_indexing::INDEXING_SLICING,
266 booleans::NONMINIMAL_BOOL,
267 enum_glob_use::ENUM_GLOB_USE,
268 enum_variants::STUTTER,
269 if_not_else::IF_NOT_ELSE,
270 items_after_statements::ITEMS_AFTER_STATEMENTS,
271 matches::SINGLE_MATCH_ELSE,
272 mem_forget::MEM_FORGET,
274 methods::OPTION_UNWRAP_USED,
275 methods::RESULT_UNWRAP_USED,
276 methods::WRONG_PUB_SELF_CONVENTION,
277 misc::USED_UNDERSCORE_BINDING,
279 mutex_atomic::MUTEX_INTEGER,
280 non_expressive_names::SIMILAR_NAMES,
283 shadow::SHADOW_REUSE,
285 shadow::SHADOW_UNRELATED,
287 strings::STRING_ADD_ASSIGN,
288 types::CAST_POSSIBLE_TRUNCATION,
289 types::CAST_POSSIBLE_WRAP,
290 types::CAST_PRECISION_LOSS,
291 types::CAST_SIGN_LOSS,
292 types::INVALID_UPCAST_COMPARISONS,
293 unicode::NON_ASCII_LITERAL,
294 unicode::UNICODE_NOT_NFC,
297 reg.register_lint_group("clippy", vec![
298 approx_const::APPROX_CONSTANT,
299 array_indexing::OUT_OF_BOUNDS_INDEXING,
300 assign_ops::ASSIGN_OP_PATTERN,
301 attrs::DEPRECATED_SEMVER,
302 attrs::INLINE_ALWAYS,
303 bit_mask::BAD_BIT_MASK,
304 bit_mask::INEFFECTIVE_BIT_MASK,
305 blacklisted_name::BLACKLISTED_NAME,
306 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
307 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
309 collapsible_if::COLLAPSIBLE_IF,
310 copies::IF_SAME_THEN_ELSE,
311 copies::IFS_SAME_COND,
312 copies::MATCH_SAME_ARMS,
313 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
314 derive::DERIVE_HASH_XOR_EQ,
315 derive::EXPL_IMPL_CLONE_ON_COPY,
319 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
320 enum_variants::ENUM_VARIANT_NAMES,
323 eta_reduction::REDUNDANT_CLOSURE,
324 format::USELESS_FORMAT,
325 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
326 formatting::SUSPICIOUS_ELSE_FORMATTING,
327 functions::NOT_UNSAFE_PTR_ARG_DEREF,
328 functions::TOO_MANY_ARGUMENTS,
329 identity_op::IDENTITY_OP,
330 len_zero::LEN_WITHOUT_IS_EMPTY,
332 let_if_seq::USELESS_LET_IF_SEQ,
333 lifetimes::NEEDLESS_LIFETIMES,
334 lifetimes::UNUSED_LIFETIMES,
336 loops::EXPLICIT_COUNTER_LOOP,
337 loops::EXPLICIT_ITER_LOOP,
339 loops::FOR_LOOP_OVER_OPTION,
340 loops::FOR_LOOP_OVER_RESULT,
341 loops::ITER_NEXT_LOOP,
342 loops::NEEDLESS_RANGE_LOOP,
343 loops::REVERSE_RANGE_LOOP,
344 loops::UNUSED_COLLECT,
345 loops::WHILE_LET_LOOP,
346 loops::WHILE_LET_ON_ITERATOR,
347 map_clone::MAP_CLONE,
349 matches::MATCH_OVERLAPPING_ARM,
350 matches::MATCH_REF_PATS,
351 matches::SINGLE_MATCH,
352 methods::CHARS_NEXT_CMP,
353 methods::CLONE_DOUBLE_REF,
354 methods::CLONE_ON_COPY,
355 methods::EXTEND_FROM_SLICE,
356 methods::FILTER_NEXT,
358 methods::NEW_RET_NO_SELF,
360 methods::OPTION_MAP_UNWRAP_OR,
361 methods::OPTION_MAP_UNWRAP_OR_ELSE,
362 methods::OR_FUN_CALL,
363 methods::SEARCH_IS_SOME,
364 methods::SHOULD_IMPLEMENT_TRAIT,
365 methods::SINGLE_CHAR_PATTERN,
366 methods::TEMPORARY_CSTRING_AS_PTR,
367 methods::WRONG_SELF_CONVENTION,
373 misc::REDUNDANT_PATTERN,
374 misc::TOPLEVEL_REF_ARG,
375 misc_early::DOUBLE_NEG,
376 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
377 misc_early::REDUNDANT_CLOSURE_CALL,
378 misc_early::UNNEEDED_FIELD_PATTERN,
379 mut_reference::UNNECESSARY_MUT_PASSED,
380 mutex_atomic::MUTEX_ATOMIC,
381 needless_bool::BOOL_COMPARISON,
382 needless_bool::NEEDLESS_BOOL,
383 needless_borrow::NEEDLESS_BORROW,
384 needless_update::NEEDLESS_UPDATE,
385 neg_multiply::NEG_MULTIPLY,
386 new_without_default::NEW_WITHOUT_DEFAULT,
387 new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
388 no_effect::NO_EFFECT,
389 no_effect::UNNECESSARY_OPERATION,
390 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
391 open_options::NONSENSICAL_OPEN_OPTIONS,
392 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
394 precedence::PRECEDENCE,
396 ranges::RANGE_STEP_BY_ZERO,
397 ranges::RANGE_ZIP_WITH_LEN,
398 regex::INVALID_REGEX,
400 regex::TRIVIAL_REGEX,
401 returns::LET_AND_RETURN,
402 returns::NEEDLESS_RETURN,
403 strings::STRING_LIT_AS_BYTES,
404 swap::ALMOST_SWAPPED,
406 temporary_assignment::TEMPORARY_ASSIGNMENT,
407 transmute::CROSSPOINTER_TRANSMUTE,
408 transmute::TRANSMUTE_PTR_TO_REF,
409 transmute::USELESS_TRANSMUTE,
410 transmute::WRONG_TRANSMUTE,
411 types::ABSURD_EXTREME_COMPARISONS,
413 types::CHAR_LIT_AS_U8,
414 types::LET_UNIT_VALUE,
416 types::TYPE_COMPLEXITY,
418 unicode::ZERO_WIDTH_SPACE,
419 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
420 unused_label::UNUSED_LABEL,
422 zero_div_zero::ZERO_DIVIDED_BY_ZERO,
426 // only exists to let the dogfood integration test works.
427 // Don't run clippy as an executable directly
428 #[allow(dead_code, print_stdout)]
430 panic!("Please use the cargo-clippy executable");