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