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 #![allow(indexing_slicing, shadow_reuse, unknown_lints)]
9 // this only exists to allow the "dogfood" integration test to work
11 #[allow(print_stdout)]
13 println!("What are you doing? Don't run clippy as an executable");
21 extern crate rustc_front;
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 extern crate rustc_plugin;
39 extern crate rustc_const_eval;
40 use rustc_plugin::Registry;
46 // begin lints modules, do not remove this comment, it’s used in `update_lints`
48 pub mod array_indexing;
51 pub mod blacklisted_name;
52 pub mod block_in_if_condition;
53 pub mod collapsible_if;
55 pub mod cyclomatic_complexity;
60 pub mod enum_glob_use;
61 pub mod enum_variants;
64 pub mod eta_reduction;
70 pub mod items_after_statements;
81 pub mod mut_reference;
83 pub mod needless_bool;
84 pub mod needless_update;
85 pub mod new_without_default;
87 pub mod non_expressive_names;
89 pub mod overflow_check_conditional;
100 pub mod temporary_assignment;
104 pub mod unused_label;
106 pub mod zero_div_zero;
107 // end lints modules, do not remove this comment, it’s used in `update_lints`
110 pub use syntax::ast::{Name, NodeId};
114 #[cfg_attr(rustfmt, rustfmt_skip)]
115 pub fn plugin_registrar(reg: &mut Registry) {
116 let conf = match utils::conf::conf_file(reg.args()) {
118 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
119 // do not require the file to exist
120 let (ref file_name, must_exist) = if let Some(ref file_name) = file_name {
123 ("clippy.toml", false)
126 let (conf, errors) = utils::conf::read_conf(&file_name, must_exist);
128 // all conf errors are non-fatal, we just use the default conf in case of error
129 for error in errors {
130 reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit();
135 Err((err, span)) => {
136 reg.sess.struct_span_err(span, err)
137 .span_note(span, "Clippy will use defaulf configuration")
139 utils::conf::Conf::default()
143 let mut store = reg.sess.lint_store.borrow_mut();
144 store.register_removed("unstable_as_slice", "`Vec::as_slice` has been stabilized in 1.7");
145 store.register_removed("unstable_as_mut_slice", "`Vec::as_mut_slice` has been stabilized in 1.7");
146 store.register_removed("str_to_string", "using `str::to_string` is common even today and specialization will likely happen soon");
147 store.register_removed("string_to_string", "using `string::to_string` is common even today and specialization will likely happen soon");
148 // end deprecated lints, do not remove this comment, it’s used in `update_lints`
150 reg.register_late_lint_pass(box types::TypePass);
151 reg.register_late_lint_pass(box misc::TopLevelRefPass);
152 reg.register_late_lint_pass(box misc::CmpNan);
153 reg.register_late_lint_pass(box eq_op::EqOp);
154 reg.register_early_lint_pass(box enum_variants::EnumVariantNames);
155 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
156 reg.register_late_lint_pass(box enum_clike::EnumClikeUnportableVariant);
157 reg.register_late_lint_pass(box bit_mask::BitMask);
158 reg.register_late_lint_pass(box ptr_arg::PtrArg);
159 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
160 reg.register_late_lint_pass(box needless_bool::BoolComparison);
161 reg.register_late_lint_pass(box approx_const::ApproxConstant);
162 reg.register_late_lint_pass(box misc::FloatCmp);
163 reg.register_early_lint_pass(box precedence::Precedence);
164 reg.register_late_lint_pass(box eta_reduction::EtaPass);
165 reg.register_late_lint_pass(box identity_op::IdentityOp);
166 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatemets);
167 reg.register_late_lint_pass(box mut_mut::MutMut);
168 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
169 reg.register_late_lint_pass(box len_zero::LenZero);
170 reg.register_late_lint_pass(box misc::CmpOwned);
171 reg.register_late_lint_pass(box attrs::AttrPass);
172 reg.register_late_lint_pass(box collapsible_if::CollapsibleIf);
173 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
174 reg.register_late_lint_pass(box misc::ModuloOne);
175 reg.register_late_lint_pass(box unicode::Unicode);
176 reg.register_late_lint_pass(box strings::StringAdd);
177 reg.register_early_lint_pass(box returns::ReturnPass);
178 reg.register_late_lint_pass(box methods::MethodsPass);
179 reg.register_late_lint_pass(box shadow::ShadowPass);
180 reg.register_late_lint_pass(box types::LetPass);
181 reg.register_late_lint_pass(box types::UnitCmp);
182 reg.register_late_lint_pass(box loops::LoopsPass);
183 reg.register_late_lint_pass(box lifetimes::LifetimePass);
184 reg.register_late_lint_pass(box entry::HashMapLint);
185 reg.register_late_lint_pass(box ranges::StepByZero);
186 reg.register_late_lint_pass(box types::CastPass);
187 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
188 reg.register_late_lint_pass(box matches::MatchPass);
189 reg.register_late_lint_pass(box misc::PatternPass);
190 reg.register_late_lint_pass(box minmax::MinMaxPass);
191 reg.register_late_lint_pass(box open_options::NonSensicalOpenOptions);
192 reg.register_late_lint_pass(box zero_div_zero::ZeroDivZeroPass);
193 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
194 reg.register_late_lint_pass(box needless_update::NeedlessUpdatePass);
195 reg.register_late_lint_pass(box no_effect::NoEffectPass);
196 reg.register_late_lint_pass(box map_clone::MapClonePass);
197 reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignmentPass);
198 reg.register_late_lint_pass(box transmute::CrosspointerTransmute);
199 reg.register_late_lint_pass(box transmute::UselessTransmute);
200 reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold));
201 reg.register_late_lint_pass(box escape::EscapePass);
202 reg.register_early_lint_pass(box misc_early::MiscEarly);
203 reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
204 reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
205 reg.register_late_lint_pass(box panic::PanicPass);
206 reg.register_late_lint_pass(box strings::StringLitAsBytes);
207 reg.register_late_lint_pass(box derive::Derive);
208 reg.register_late_lint_pass(box types::CharLitAsU8);
209 reg.register_late_lint_pass(box print::PrintLint);
210 reg.register_late_lint_pass(box vec::UselessVec);
211 reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
212 max_single_char_names: conf.max_single_char_names,
214 reg.register_late_lint_pass(box drop_ref::DropRefPass);
215 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
216 reg.register_late_lint_pass(box regex::RegexPass::default());
217 reg.register_late_lint_pass(box copies::CopyAndPaste);
218 reg.register_late_lint_pass(box format::FormatMacLint);
219 reg.register_early_lint_pass(box formatting::Formatting);
220 reg.register_late_lint_pass(box swap::Swap);
221 reg.register_early_lint_pass(box if_not_else::IfNotElse);
222 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
223 reg.register_late_lint_pass(box unused_label::UnusedLabel);
224 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
225 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names));
226 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
228 reg.register_lint_group("clippy_pedantic", vec![
229 array_indexing::INDEXING_SLICING,
230 enum_glob_use::ENUM_GLOB_USE,
231 matches::SINGLE_MATCH_ELSE,
232 methods::OPTION_UNWRAP_USED,
233 methods::RESULT_UNWRAP_USED,
234 methods::WRONG_PUB_SELF_CONVENTION,
236 mutex_atomic::MUTEX_INTEGER,
239 shadow::SHADOW_REUSE,
241 shadow::SHADOW_UNRELATED,
243 strings::STRING_ADD_ASSIGN,
244 types::CAST_POSSIBLE_TRUNCATION,
245 types::CAST_POSSIBLE_WRAP,
246 types::CAST_PRECISION_LOSS,
247 types::CAST_SIGN_LOSS,
248 unicode::NON_ASCII_LITERAL,
249 unicode::UNICODE_NOT_NFC,
252 reg.register_lint_group("clippy", vec![
253 approx_const::APPROX_CONSTANT,
254 array_indexing::OUT_OF_BOUNDS_INDEXING,
255 attrs::DEPRECATED_SEMVER,
256 attrs::INLINE_ALWAYS,
257 bit_mask::BAD_BIT_MASK,
258 bit_mask::INEFFECTIVE_BIT_MASK,
259 blacklisted_name::BLACKLISTED_NAME,
260 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
261 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
262 collapsible_if::COLLAPSIBLE_IF,
263 copies::IF_SAME_THEN_ELSE,
264 copies::IFS_SAME_COND,
265 copies::MATCH_SAME_ARMS,
266 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
267 derive::DERIVE_HASH_XOR_EQ,
268 derive::EXPL_IMPL_CLONE_ON_COPY,
271 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
272 enum_variants::ENUM_VARIANT_NAMES,
275 eta_reduction::REDUNDANT_CLOSURE,
276 format::USELESS_FORMAT,
277 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
278 formatting::SUSPICIOUS_ELSE_FORMATTING,
279 functions::TOO_MANY_ARGUMENTS,
280 identity_op::IDENTITY_OP,
281 if_not_else::IF_NOT_ELSE,
282 items_after_statements::ITEMS_AFTER_STATEMENTS,
283 len_zero::LEN_WITHOUT_IS_EMPTY,
285 lifetimes::NEEDLESS_LIFETIMES,
286 lifetimes::UNUSED_LIFETIMES,
288 loops::EXPLICIT_COUNTER_LOOP,
289 loops::EXPLICIT_ITER_LOOP,
291 loops::FOR_LOOP_OVER_OPTION,
292 loops::FOR_LOOP_OVER_RESULT,
293 loops::ITER_NEXT_LOOP,
294 loops::NEEDLESS_RANGE_LOOP,
295 loops::REVERSE_RANGE_LOOP,
296 loops::UNUSED_COLLECT,
297 loops::WHILE_LET_LOOP,
298 loops::WHILE_LET_ON_ITERATOR,
299 map_clone::MAP_CLONE,
301 matches::MATCH_OVERLAPPING_ARM,
302 matches::MATCH_REF_PATS,
303 matches::SINGLE_MATCH,
304 methods::CHARS_NEXT_CMP,
305 methods::CLONE_DOUBLE_REF,
306 methods::CLONE_ON_COPY,
307 methods::EXTEND_FROM_SLICE,
308 methods::FILTER_NEXT,
309 methods::NEW_RET_NO_SELF,
311 methods::OPTION_MAP_UNWRAP_OR,
312 methods::OPTION_MAP_UNWRAP_OR_ELSE,
313 methods::OR_FUN_CALL,
314 methods::SEARCH_IS_SOME,
315 methods::SHOULD_IMPLEMENT_TRAIT,
316 methods::SINGLE_CHAR_PATTERN,
317 methods::WRONG_SELF_CONVENTION,
323 misc::REDUNDANT_PATTERN,
324 misc::TOPLEVEL_REF_ARG,
325 misc::USED_UNDERSCORE_BINDING,
326 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
327 misc_early::REDUNDANT_CLOSURE_CALL,
328 misc_early::UNNEEDED_FIELD_PATTERN,
329 mut_reference::UNNECESSARY_MUT_PASSED,
330 mutex_atomic::MUTEX_ATOMIC,
331 needless_bool::BOOL_COMPARISON,
332 needless_bool::NEEDLESS_BOOL,
333 needless_update::NEEDLESS_UPDATE,
334 new_without_default::NEW_WITHOUT_DEFAULT,
335 no_effect::NO_EFFECT,
336 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
337 non_expressive_names::SIMILAR_NAMES,
338 open_options::NONSENSICAL_OPEN_OPTIONS,
339 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
341 precedence::PRECEDENCE,
343 ranges::RANGE_STEP_BY_ZERO,
344 ranges::RANGE_ZIP_WITH_LEN,
345 regex::INVALID_REGEX,
347 regex::TRIVIAL_REGEX,
348 returns::LET_AND_RETURN,
349 returns::NEEDLESS_RETURN,
350 strings::STRING_LIT_AS_BYTES,
351 swap::ALMOST_SWAPPED,
353 temporary_assignment::TEMPORARY_ASSIGNMENT,
354 transmute::CROSSPOINTER_TRANSMUTE,
355 transmute::USELESS_TRANSMUTE,
356 types::ABSURD_EXTREME_COMPARISONS,
358 types::CHAR_LIT_AS_U8,
359 types::LET_UNIT_VALUE,
361 types::TYPE_COMPLEXITY,
363 unicode::ZERO_WIDTH_SPACE,
364 unused_label::UNUSED_LABEL,
366 zero_div_zero::ZERO_DIVIDED_BY_ZERO,