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");
23 extern crate rustc_front;
27 // Only for the compile time checking of paths
29 extern crate collections;
31 // for unicode nfc normalization
32 extern crate unicode_normalization;
34 // for semver check in attrs.rs
38 extern crate regex_syntax;
40 // for finding minimal boolean expressions
41 extern crate quine_mc_cluskey;
43 extern crate rustc_plugin;
44 extern crate rustc_const_eval;
45 extern crate rustc_const_math;
46 use rustc_plugin::Registry;
52 // begin lints modules, do not remove this comment, it’s used in `update_lints`
54 pub mod array_indexing;
57 pub mod blacklisted_name;
58 pub mod block_in_if_condition;
60 pub mod collapsible_if;
62 pub mod cyclomatic_complexity;
68 pub mod enum_glob_use;
69 pub mod enum_variants;
72 pub mod eta_reduction;
78 pub mod items_after_statements;
89 pub mod mut_reference;
91 pub mod needless_bool;
92 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 unused_label;
114 pub mod zero_div_zero;
115 // end lints modules, do not remove this comment, it’s used in `update_lints`
118 pub use syntax::ast::{Name, NodeId};
122 #[cfg_attr(rustfmt, rustfmt_skip)]
123 pub fn plugin_registrar(reg: &mut Registry) {
124 let conf = match utils::conf::conf_file(reg.args()) {
126 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
127 // do not require the file to exist
128 let (ref file_name, must_exist) = if let Some(ref file_name) = file_name {
131 ("clippy.toml", false)
134 let (conf, errors) = utils::conf::read_conf(&file_name, must_exist);
136 // all conf errors are non-fatal, we just use the default conf in case of error
137 for error in errors {
138 reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit();
143 Err((err, span)) => {
144 reg.sess.struct_span_err(span, err)
145 .span_note(span, "Clippy will use default configuration")
147 utils::conf::Conf::default()
151 let mut store = reg.sess.lint_store.borrow_mut();
152 store.register_removed("unstable_as_slice", "`Vec::as_slice` has been stabilized in 1.7");
153 store.register_removed("unstable_as_mut_slice", "`Vec::as_mut_slice` has been stabilized in 1.7");
154 store.register_removed("str_to_string", "using `str::to_string` is common even today and specialization will likely happen soon");
155 store.register_removed("string_to_string", "using `string::to_string` is common even today and specialization will likely happen soon");
156 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
158 reg.register_late_lint_pass(box types::TypePass);
159 reg.register_late_lint_pass(box booleans::NonminimalBool);
160 reg.register_late_lint_pass(box misc::TopLevelRefPass);
161 reg.register_late_lint_pass(box misc::CmpNan);
162 reg.register_late_lint_pass(box eq_op::EqOp);
163 reg.register_early_lint_pass(box enum_variants::EnumVariantNames);
164 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
165 reg.register_late_lint_pass(box enum_clike::EnumClikeUnportableVariant);
166 reg.register_late_lint_pass(box bit_mask::BitMask);
167 reg.register_late_lint_pass(box ptr_arg::PtrArg);
168 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
169 reg.register_late_lint_pass(box needless_bool::BoolComparison);
170 reg.register_late_lint_pass(box approx_const::ApproxConstant);
171 reg.register_late_lint_pass(box misc::FloatCmp);
172 reg.register_early_lint_pass(box precedence::Precedence);
173 reg.register_late_lint_pass(box eta_reduction::EtaPass);
174 reg.register_late_lint_pass(box identity_op::IdentityOp);
175 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatements);
176 reg.register_late_lint_pass(box mut_mut::MutMut);
177 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
178 reg.register_late_lint_pass(box len_zero::LenZero);
179 reg.register_late_lint_pass(box misc::CmpOwned);
180 reg.register_late_lint_pass(box attrs::AttrPass);
181 reg.register_late_lint_pass(box collapsible_if::CollapsibleIf);
182 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
183 reg.register_late_lint_pass(box misc::ModuloOne);
184 reg.register_late_lint_pass(box unicode::Unicode);
185 reg.register_late_lint_pass(box strings::StringAdd);
186 reg.register_early_lint_pass(box returns::ReturnPass);
187 reg.register_late_lint_pass(box methods::MethodsPass);
188 reg.register_late_lint_pass(box shadow::ShadowPass);
189 reg.register_late_lint_pass(box types::LetPass);
190 reg.register_late_lint_pass(box types::UnitCmp);
191 reg.register_late_lint_pass(box loops::LoopsPass);
192 reg.register_late_lint_pass(box lifetimes::LifetimePass);
193 reg.register_late_lint_pass(box entry::HashMapLint);
194 reg.register_late_lint_pass(box ranges::StepByZero);
195 reg.register_late_lint_pass(box types::CastPass);
196 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
197 reg.register_late_lint_pass(box matches::MatchPass);
198 reg.register_late_lint_pass(box misc::PatternPass);
199 reg.register_late_lint_pass(box minmax::MinMaxPass);
200 reg.register_late_lint_pass(box open_options::NonSensicalOpenOptions);
201 reg.register_late_lint_pass(box zero_div_zero::ZeroDivZeroPass);
202 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
203 reg.register_late_lint_pass(box needless_update::NeedlessUpdatePass);
204 reg.register_late_lint_pass(box no_effect::NoEffectPass);
205 reg.register_late_lint_pass(box map_clone::MapClonePass);
206 reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignmentPass);
207 reg.register_late_lint_pass(box transmute::Transmute);
208 reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold));
209 reg.register_late_lint_pass(box escape::EscapePass);
210 reg.register_early_lint_pass(box misc_early::MiscEarly);
211 reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
212 reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
213 reg.register_late_lint_pass(box panic::PanicPass);
214 reg.register_late_lint_pass(box strings::StringLitAsBytes);
215 reg.register_late_lint_pass(box derive::Derive);
216 reg.register_late_lint_pass(box types::CharLitAsU8);
217 reg.register_late_lint_pass(box print::PrintLint);
218 reg.register_late_lint_pass(box vec::UselessVec);
219 reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
220 max_single_char_names: conf.max_single_char_names,
222 reg.register_late_lint_pass(box drop_ref::DropRefPass);
223 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
224 reg.register_late_lint_pass(box types::InvalidUpcastComparisons);
225 reg.register_late_lint_pass(box regex::RegexPass::default());
226 reg.register_late_lint_pass(box copies::CopyAndPaste);
227 reg.register_late_lint_pass(box format::FormatMacLint);
228 reg.register_early_lint_pass(box formatting::Formatting);
229 reg.register_late_lint_pass(box swap::Swap);
230 reg.register_early_lint_pass(box if_not_else::IfNotElse);
231 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
232 reg.register_late_lint_pass(box unused_label::UnusedLabel);
233 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
234 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names));
235 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
236 reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents));
238 reg.register_lint_group("clippy_pedantic", vec![
239 array_indexing::INDEXING_SLICING,
240 booleans::NONMINIMAL_BOOL,
241 enum_glob_use::ENUM_GLOB_USE,
242 matches::SINGLE_MATCH_ELSE,
243 methods::OPTION_UNWRAP_USED,
244 methods::RESULT_UNWRAP_USED,
245 methods::WRONG_PUB_SELF_CONVENTION,
247 mutex_atomic::MUTEX_INTEGER,
250 shadow::SHADOW_REUSE,
252 shadow::SHADOW_UNRELATED,
254 strings::STRING_ADD_ASSIGN,
255 types::CAST_POSSIBLE_TRUNCATION,
256 types::CAST_POSSIBLE_WRAP,
257 types::CAST_PRECISION_LOSS,
258 types::CAST_SIGN_LOSS,
259 unicode::NON_ASCII_LITERAL,
260 unicode::UNICODE_NOT_NFC,
263 reg.register_lint_group("clippy", vec![
264 approx_const::APPROX_CONSTANT,
265 array_indexing::OUT_OF_BOUNDS_INDEXING,
266 attrs::DEPRECATED_SEMVER,
267 attrs::INLINE_ALWAYS,
268 bit_mask::BAD_BIT_MASK,
269 bit_mask::INEFFECTIVE_BIT_MASK,
270 blacklisted_name::BLACKLISTED_NAME,
271 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
272 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
274 collapsible_if::COLLAPSIBLE_IF,
275 copies::IF_SAME_THEN_ELSE,
276 copies::IFS_SAME_COND,
277 copies::MATCH_SAME_ARMS,
278 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
279 derive::DERIVE_HASH_XOR_EQ,
280 derive::EXPL_IMPL_CLONE_ON_COPY,
284 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
285 enum_variants::ENUM_VARIANT_NAMES,
288 eta_reduction::REDUNDANT_CLOSURE,
289 format::USELESS_FORMAT,
290 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
291 formatting::SUSPICIOUS_ELSE_FORMATTING,
292 functions::TOO_MANY_ARGUMENTS,
293 identity_op::IDENTITY_OP,
294 if_not_else::IF_NOT_ELSE,
295 items_after_statements::ITEMS_AFTER_STATEMENTS,
296 len_zero::LEN_WITHOUT_IS_EMPTY,
298 lifetimes::NEEDLESS_LIFETIMES,
299 lifetimes::UNUSED_LIFETIMES,
301 loops::EXPLICIT_COUNTER_LOOP,
302 loops::EXPLICIT_ITER_LOOP,
304 loops::FOR_LOOP_OVER_OPTION,
305 loops::FOR_LOOP_OVER_RESULT,
306 loops::ITER_NEXT_LOOP,
307 loops::NEEDLESS_RANGE_LOOP,
308 loops::REVERSE_RANGE_LOOP,
309 loops::UNUSED_COLLECT,
310 loops::WHILE_LET_LOOP,
311 loops::WHILE_LET_ON_ITERATOR,
312 map_clone::MAP_CLONE,
314 matches::MATCH_OVERLAPPING_ARM,
315 matches::MATCH_REF_PATS,
316 matches::SINGLE_MATCH,
317 methods::CHARS_NEXT_CMP,
318 methods::CLONE_DOUBLE_REF,
319 methods::CLONE_ON_COPY,
320 methods::EXTEND_FROM_SLICE,
321 methods::FILTER_NEXT,
322 methods::NEW_RET_NO_SELF,
324 methods::OPTION_MAP_UNWRAP_OR,
325 methods::OPTION_MAP_UNWRAP_OR_ELSE,
326 methods::OR_FUN_CALL,
327 methods::SEARCH_IS_SOME,
328 methods::SHOULD_IMPLEMENT_TRAIT,
329 methods::SINGLE_CHAR_PATTERN,
330 methods::WRONG_SELF_CONVENTION,
336 misc::REDUNDANT_PATTERN,
337 misc::TOPLEVEL_REF_ARG,
338 misc::USED_UNDERSCORE_BINDING,
339 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
340 misc_early::REDUNDANT_CLOSURE_CALL,
341 misc_early::UNNEEDED_FIELD_PATTERN,
342 mut_reference::UNNECESSARY_MUT_PASSED,
343 mutex_atomic::MUTEX_ATOMIC,
344 needless_bool::BOOL_COMPARISON,
345 needless_bool::NEEDLESS_BOOL,
346 needless_update::NEEDLESS_UPDATE,
347 new_without_default::NEW_WITHOUT_DEFAULT,
348 no_effect::NO_EFFECT,
349 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
350 non_expressive_names::SIMILAR_NAMES,
351 open_options::NONSENSICAL_OPEN_OPTIONS,
352 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
354 precedence::PRECEDENCE,
356 ranges::RANGE_STEP_BY_ZERO,
357 ranges::RANGE_ZIP_WITH_LEN,
358 regex::INVALID_REGEX,
360 regex::TRIVIAL_REGEX,
361 returns::LET_AND_RETURN,
362 returns::NEEDLESS_RETURN,
363 strings::STRING_LIT_AS_BYTES,
364 swap::ALMOST_SWAPPED,
366 temporary_assignment::TEMPORARY_ASSIGNMENT,
367 transmute::CROSSPOINTER_TRANSMUTE,
368 transmute::TRANSMUTE_PTR_TO_REF,
369 transmute::USELESS_TRANSMUTE,
370 types::ABSURD_EXTREME_COMPARISONS,
372 types::CHAR_LIT_AS_U8,
373 types::INVALID_UPCAST_COMPARISONS,
374 types::LET_UNIT_VALUE,
376 types::TYPE_COMPLEXITY,
378 unicode::ZERO_WIDTH_SPACE,
379 unused_label::UNUSED_LABEL,
381 zero_div_zero::ZERO_DIVIDED_BY_ZERO,