1 #![feature(type_macros)]
2 #![feature(plugin_registrar, box_syntax)]
3 #![feature(rustc_private, collections)]
4 #![feature(iter_arith)]
5 #![feature(custom_attribute)]
6 #![feature(slice_patterns)]
7 #![feature(question_mark)]
8 #![feature(stmt_expr_attributes)]
9 #![allow(indexing_slicing, shadow_reuse, unknown_lints)]
11 // this only exists to allow the "dogfood" integration test to work
13 #[allow(print_stdout)]
15 println!("What are you doing? Don't run clippy as an executable");
25 // Only for the compile time checking of paths
27 extern crate collections;
29 // for unicode nfc normalization
30 extern crate unicode_normalization;
32 // for semver check in attrs.rs
36 extern crate regex_syntax;
38 // for finding minimal boolean expressions
39 extern crate quine_mc_cluskey;
41 extern crate rustc_plugin;
42 extern crate rustc_const_eval;
43 extern crate rustc_const_math;
44 use rustc_plugin::Registry;
50 // begin lints modules, do not remove this comment, it’s used in `update_lints`
52 pub mod array_indexing;
55 pub mod blacklisted_name;
56 pub mod block_in_if_condition;
58 pub mod collapsible_if;
60 pub mod cyclomatic_complexity;
66 pub mod enum_glob_use;
67 pub mod enum_variants;
70 pub mod eta_reduction;
76 pub mod items_after_statements;
88 pub mod mut_reference;
90 pub mod needless_bool;
91 pub mod needless_update;
93 pub mod new_without_default;
95 pub mod non_expressive_names;
97 pub mod overflow_check_conditional;
108 pub mod temporary_assignment;
112 pub mod unsafe_removed_from_name;
113 pub mod unused_label;
115 pub mod zero_div_zero;
116 // end lints modules, do not remove this comment, it’s used in `update_lints`
119 pub use syntax::ast::{Name, NodeId};
123 #[cfg_attr(rustfmt, rustfmt_skip)]
124 pub fn plugin_registrar(reg: &mut Registry) {
125 let conf = match utils::conf::conf_file(reg.args()) {
127 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
128 // do not require the file to exist
129 let (ref file_name, must_exist) = if let Some(ref file_name) = file_name {
132 ("clippy.toml", false)
135 let (conf, errors) = utils::conf::read_conf(&file_name, must_exist);
137 // all conf errors are non-fatal, we just use the default conf in case of error
138 for error in errors {
139 reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit();
144 Err((err, span)) => {
145 reg.sess.struct_span_err(span, err)
146 .span_note(span, "Clippy will use default configuration")
148 utils::conf::Conf::default()
152 let mut store = reg.sess.lint_store.borrow_mut();
153 store.register_removed("unstable_as_slice", "`Vec::as_slice` has been stabilized in 1.7");
154 store.register_removed("unstable_as_mut_slice", "`Vec::as_mut_slice` has been stabilized in 1.7");
155 store.register_removed("str_to_string", "using `str::to_string` is common even today and specialization will likely happen soon");
156 store.register_removed("string_to_string", "using `string::to_string` is common even today and specialization will likely happen soon");
157 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
159 reg.register_late_lint_pass(box types::TypePass);
160 reg.register_late_lint_pass(box booleans::NonminimalBool);
161 reg.register_late_lint_pass(box misc::TopLevelRefPass);
162 reg.register_late_lint_pass(box misc::CmpNan);
163 reg.register_late_lint_pass(box eq_op::EqOp);
164 reg.register_early_lint_pass(box enum_variants::EnumVariantNames);
165 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
166 reg.register_late_lint_pass(box enum_clike::EnumClikeUnportableVariant);
167 reg.register_late_lint_pass(box bit_mask::BitMask);
168 reg.register_late_lint_pass(box ptr_arg::PtrArg);
169 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
170 reg.register_late_lint_pass(box needless_bool::BoolComparison);
171 reg.register_late_lint_pass(box approx_const::ApproxConstant);
172 reg.register_late_lint_pass(box misc::FloatCmp);
173 reg.register_early_lint_pass(box precedence::Precedence);
174 reg.register_late_lint_pass(box eta_reduction::EtaPass);
175 reg.register_late_lint_pass(box identity_op::IdentityOp);
176 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
177 reg.register_late_lint_pass(box mut_mut::MutMut);
178 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
179 reg.register_late_lint_pass(box len_zero::LenZero);
180 reg.register_late_lint_pass(box misc::CmpOwned);
181 reg.register_late_lint_pass(box attrs::AttrPass);
182 reg.register_late_lint_pass(box collapsible_if::CollapsibleIf);
183 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
184 reg.register_late_lint_pass(box misc::ModuloOne);
185 reg.register_late_lint_pass(box unicode::Unicode);
186 reg.register_late_lint_pass(box strings::StringAdd);
187 reg.register_early_lint_pass(box returns::ReturnPass);
188 reg.register_late_lint_pass(box methods::MethodsPass);
189 reg.register_late_lint_pass(box shadow::ShadowPass);
190 reg.register_late_lint_pass(box types::LetPass);
191 reg.register_late_lint_pass(box types::UnitCmp);
192 reg.register_late_lint_pass(box loops::LoopsPass);
193 reg.register_late_lint_pass(box lifetimes::LifetimePass);
194 reg.register_late_lint_pass(box entry::HashMapLint);
195 reg.register_late_lint_pass(box ranges::StepByZero);
196 reg.register_late_lint_pass(box types::CastPass);
197 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
198 reg.register_late_lint_pass(box matches::MatchPass);
199 reg.register_late_lint_pass(box misc::PatternPass);
200 reg.register_late_lint_pass(box minmax::MinMaxPass);
201 reg.register_late_lint_pass(box open_options::NonSensicalOpenOptions);
202 reg.register_late_lint_pass(box zero_div_zero::ZeroDivZeroPass);
203 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
204 reg.register_late_lint_pass(box needless_update::NeedlessUpdatePass);
205 reg.register_late_lint_pass(box no_effect::NoEffectPass);
206 reg.register_late_lint_pass(box map_clone::MapClonePass);
207 reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignmentPass);
208 reg.register_late_lint_pass(box transmute::Transmute);
209 reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold));
210 reg.register_late_lint_pass(box escape::EscapePass);
211 reg.register_early_lint_pass(box misc_early::MiscEarly);
212 reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
213 reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
214 reg.register_late_lint_pass(box panic::PanicPass);
215 reg.register_late_lint_pass(box strings::StringLitAsBytes);
216 reg.register_late_lint_pass(box derive::Derive);
217 reg.register_late_lint_pass(box types::CharLitAsU8);
218 reg.register_late_lint_pass(box print::PrintLint);
219 reg.register_late_lint_pass(box vec::UselessVec);
220 reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
221 max_single_char_names: conf.max_single_char_names,
223 reg.register_late_lint_pass(box drop_ref::DropRefPass);
224 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
225 reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
226 reg.register_late_lint_pass(box regex::RegexPass::default());
227 reg.register_late_lint_pass(box copies::CopyAndPaste);
228 reg.register_late_lint_pass(box format::FormatMacLint);
229 reg.register_early_lint_pass(box formatting::Formatting);
230 reg.register_late_lint_pass(box swap::Swap);
231 reg.register_early_lint_pass(box if_not_else::IfNotElse);
232 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
233 reg.register_late_lint_pass(box unused_label::UnusedLabel);
234 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
235 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names));
236 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
237 reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents));
238 reg.register_late_lint_pass(box neg_multiply::NegMultiply);
239 reg.register_late_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
240 reg.register_late_lint_pass(box mem_forget::MemForget);
242 reg.register_lint_group("clippy_pedantic", vec![
243 array_indexing::INDEXING_SLICING,
244 booleans::NONMINIMAL_BOOL,
245 enum_glob_use::ENUM_GLOB_USE,
246 if_not_else::IF_NOT_ELSE,
247 items_after_statements::ITEMS_AFTER_STATEMENTS,
248 matches::SINGLE_MATCH_ELSE,
249 mem_forget::MEM_FORGET,
250 methods::OPTION_UNWRAP_USED,
251 methods::RESULT_UNWRAP_USED,
252 methods::WRONG_PUB_SELF_CONVENTION,
254 mutex_atomic::MUTEX_INTEGER,
257 shadow::SHADOW_REUSE,
259 shadow::SHADOW_UNRELATED,
261 strings::STRING_ADD_ASSIGN,
262 types::CAST_POSSIBLE_TRUNCATION,
263 types::CAST_POSSIBLE_WRAP,
264 types::CAST_PRECISION_LOSS,
265 types::CAST_SIGN_LOSS,
266 unicode::NON_ASCII_LITERAL,
267 unicode::UNICODE_NOT_NFC,
270 reg.register_lint_group("clippy", vec![
271 approx_const::APPROX_CONSTANT,
272 array_indexing::OUT_OF_BOUNDS_INDEXING,
273 attrs::DEPRECATED_SEMVER,
274 attrs::INLINE_ALWAYS,
275 bit_mask::BAD_BIT_MASK,
276 bit_mask::INEFFECTIVE_BIT_MASK,
277 blacklisted_name::BLACKLISTED_NAME,
278 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
279 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
281 collapsible_if::COLLAPSIBLE_IF,
282 copies::IF_SAME_THEN_ELSE,
283 copies::IFS_SAME_COND,
284 copies::MATCH_SAME_ARMS,
285 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
286 derive::DERIVE_HASH_XOR_EQ,
287 derive::EXPL_IMPL_CLONE_ON_COPY,
291 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
292 enum_variants::ENUM_VARIANT_NAMES,
295 eta_reduction::REDUNDANT_CLOSURE,
296 format::USELESS_FORMAT,
297 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
298 formatting::SUSPICIOUS_ELSE_FORMATTING,
299 functions::TOO_MANY_ARGUMENTS,
300 identity_op::IDENTITY_OP,
301 len_zero::LEN_WITHOUT_IS_EMPTY,
303 lifetimes::NEEDLESS_LIFETIMES,
304 lifetimes::UNUSED_LIFETIMES,
306 loops::EXPLICIT_COUNTER_LOOP,
307 loops::EXPLICIT_ITER_LOOP,
309 loops::FOR_LOOP_OVER_OPTION,
310 loops::FOR_LOOP_OVER_RESULT,
311 loops::ITER_NEXT_LOOP,
312 loops::NEEDLESS_RANGE_LOOP,
313 loops::REVERSE_RANGE_LOOP,
314 loops::UNUSED_COLLECT,
315 loops::WHILE_LET_LOOP,
316 loops::WHILE_LET_ON_ITERATOR,
317 map_clone::MAP_CLONE,
319 matches::MATCH_OVERLAPPING_ARM,
320 matches::MATCH_REF_PATS,
321 matches::SINGLE_MATCH,
322 methods::CHARS_NEXT_CMP,
323 methods::CLONE_DOUBLE_REF,
324 methods::CLONE_ON_COPY,
325 methods::EXTEND_FROM_SLICE,
326 methods::FILTER_NEXT,
327 methods::NEW_RET_NO_SELF,
329 methods::OPTION_MAP_UNWRAP_OR,
330 methods::OPTION_MAP_UNWRAP_OR_ELSE,
331 methods::OR_FUN_CALL,
332 methods::SEARCH_IS_SOME,
333 methods::SHOULD_IMPLEMENT_TRAIT,
334 methods::SINGLE_CHAR_PATTERN,
335 methods::TEMPORARY_CSTRING_AS_PTR,
336 methods::WRONG_SELF_CONVENTION,
342 misc::REDUNDANT_PATTERN,
343 misc::TOPLEVEL_REF_ARG,
344 misc::USED_UNDERSCORE_BINDING,
345 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
346 misc_early::REDUNDANT_CLOSURE_CALL,
347 misc_early::UNNEEDED_FIELD_PATTERN,
348 mut_reference::UNNECESSARY_MUT_PASSED,
349 mutex_atomic::MUTEX_ATOMIC,
350 needless_bool::BOOL_COMPARISON,
351 needless_bool::NEEDLESS_BOOL,
352 needless_update::NEEDLESS_UPDATE,
353 neg_multiply::NEG_MULTIPLY,
354 new_without_default::NEW_WITHOUT_DEFAULT,
355 no_effect::NO_EFFECT,
356 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
357 non_expressive_names::SIMILAR_NAMES,
358 open_options::NONSENSICAL_OPEN_OPTIONS,
359 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
361 precedence::PRECEDENCE,
363 ranges::RANGE_STEP_BY_ZERO,
364 ranges::RANGE_ZIP_WITH_LEN,
365 regex::INVALID_REGEX,
367 regex::TRIVIAL_REGEX,
368 returns::LET_AND_RETURN,
369 returns::NEEDLESS_RETURN,
370 strings::STRING_LIT_AS_BYTES,
371 swap::ALMOST_SWAPPED,
373 temporary_assignment::TEMPORARY_ASSIGNMENT,
374 transmute::CROSSPOINTER_TRANSMUTE,
375 transmute::TRANSMUTE_PTR_TO_REF,
376 transmute::USELESS_TRANSMUTE,
377 types::ABSURD_EXTREME_COMPARISONS,
379 types::CHAR_LIT_AS_U8,
380 types::INVALID_UPCAST_COMPARISONS,
381 types::LET_UNIT_VALUE,
383 types::TYPE_COMPLEXITY,
385 unicode::ZERO_WIDTH_SPACE,
386 unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
387 unused_label::UNUSED_LABEL,
389 zero_div_zero::ZERO_DIVIDED_BY_ZERO,