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_features;
85 pub mod needless_update;
86 pub mod new_without_default;
88 pub mod non_expressive_names;
90 pub mod overflow_check_conditional;
101 pub mod temporary_assignment;
105 pub mod unused_label;
107 pub mod zero_div_zero;
108 // end lints modules, do not remove this comment, it’s used in `update_lints`
111 pub use syntax::ast::{Name, NodeId};
115 #[cfg_attr(rustfmt, rustfmt_skip)]
116 pub fn plugin_registrar(reg: &mut Registry) {
117 let conf = match utils::conf::conf_file(reg.args()) {
119 // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
120 // do not require the file to exist
121 let (ref file_name, must_exist) = if let Some(ref file_name) = file_name {
124 ("clippy.toml", false)
127 let (conf, errors) = utils::conf::read_conf(&file_name, must_exist);
129 // all conf errors are non-fatal, we just use the default conf in case of error
130 for error in errors {
131 reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit();
136 Err((err, span)) => {
137 reg.sess.struct_span_err(span, err)
138 .span_note(span, "Clippy will use defaulf configuration")
140 utils::conf::Conf::default()
144 reg.register_late_lint_pass(box types::TypePass);
145 reg.register_late_lint_pass(box misc::TopLevelRefPass);
146 reg.register_late_lint_pass(box misc::CmpNan);
147 reg.register_late_lint_pass(box eq_op::EqOp);
148 reg.register_early_lint_pass(box enum_variants::EnumVariantNames);
149 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
150 reg.register_late_lint_pass(box enum_clike::EnumClikeUnportableVariant);
151 reg.register_late_lint_pass(box bit_mask::BitMask);
152 reg.register_late_lint_pass(box ptr_arg::PtrArg);
153 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
154 reg.register_late_lint_pass(box needless_bool::BoolComparison);
155 reg.register_late_lint_pass(box approx_const::ApproxConstant);
156 reg.register_late_lint_pass(box misc::FloatCmp);
157 reg.register_early_lint_pass(box precedence::Precedence);
158 reg.register_late_lint_pass(box eta_reduction::EtaPass);
159 reg.register_late_lint_pass(box identity_op::IdentityOp);
160 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatemets);
161 reg.register_late_lint_pass(box mut_mut::MutMut);
162 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
163 reg.register_late_lint_pass(box len_zero::LenZero);
164 reg.register_late_lint_pass(box misc::CmpOwned);
165 reg.register_late_lint_pass(box attrs::AttrPass);
166 reg.register_late_lint_pass(box collapsible_if::CollapsibleIf);
167 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
168 reg.register_late_lint_pass(box misc::ModuloOne);
169 reg.register_late_lint_pass(box unicode::Unicode);
170 reg.register_late_lint_pass(box strings::StringAdd);
171 reg.register_early_lint_pass(box returns::ReturnPass);
172 reg.register_late_lint_pass(box methods::MethodsPass);
173 reg.register_late_lint_pass(box shadow::ShadowPass);
174 reg.register_late_lint_pass(box types::LetPass);
175 reg.register_late_lint_pass(box types::UnitCmp);
176 reg.register_late_lint_pass(box loops::LoopsPass);
177 reg.register_late_lint_pass(box lifetimes::LifetimePass);
178 reg.register_late_lint_pass(box entry::HashMapLint);
179 reg.register_late_lint_pass(box ranges::StepByZero);
180 reg.register_late_lint_pass(box types::CastPass);
181 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
182 reg.register_late_lint_pass(box matches::MatchPass);
183 reg.register_late_lint_pass(box misc::PatternPass);
184 reg.register_late_lint_pass(box minmax::MinMaxPass);
185 reg.register_late_lint_pass(box open_options::NonSensicalOpenOptions);
186 reg.register_late_lint_pass(box zero_div_zero::ZeroDivZeroPass);
187 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
188 reg.register_late_lint_pass(box needless_features::NeedlessFeaturesPass);
189 reg.register_late_lint_pass(box needless_update::NeedlessUpdatePass);
190 reg.register_late_lint_pass(box no_effect::NoEffectPass);
191 reg.register_late_lint_pass(box map_clone::MapClonePass);
192 reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignmentPass);
193 reg.register_late_lint_pass(box transmute::UselessTransmute);
194 reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold));
195 reg.register_late_lint_pass(box escape::EscapePass);
196 reg.register_early_lint_pass(box misc_early::MiscEarly);
197 reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
198 reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
199 reg.register_late_lint_pass(box panic::PanicPass);
200 reg.register_late_lint_pass(box strings::StringLitAsBytes);
201 reg.register_late_lint_pass(box derive::Derive);
202 reg.register_late_lint_pass(box types::CharLitAsU8);
203 reg.register_late_lint_pass(box print::PrintLint);
204 reg.register_late_lint_pass(box vec::UselessVec);
205 reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
206 max_single_char_names: conf.max_single_char_names,
208 reg.register_late_lint_pass(box drop_ref::DropRefPass);
209 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
210 reg.register_late_lint_pass(box regex::RegexPass::default());
211 reg.register_late_lint_pass(box copies::CopyAndPaste);
212 reg.register_late_lint_pass(box format::FormatMacLint);
213 reg.register_early_lint_pass(box formatting::Formatting);
214 reg.register_late_lint_pass(box swap::Swap);
215 reg.register_early_lint_pass(box if_not_else::IfNotElse);
216 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
217 reg.register_late_lint_pass(box unused_label::UnusedLabel);
218 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
219 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names));
220 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
222 reg.register_lint_group("clippy_pedantic", vec![
223 array_indexing::INDEXING_SLICING,
224 enum_glob_use::ENUM_GLOB_USE,
225 matches::SINGLE_MATCH_ELSE,
226 methods::OPTION_UNWRAP_USED,
227 methods::RESULT_UNWRAP_USED,
228 methods::WRONG_PUB_SELF_CONVENTION,
230 mutex_atomic::MUTEX_INTEGER,
233 shadow::SHADOW_REUSE,
235 shadow::SHADOW_UNRELATED,
237 strings::STRING_ADD_ASSIGN,
238 types::CAST_POSSIBLE_TRUNCATION,
239 types::CAST_POSSIBLE_WRAP,
240 types::CAST_PRECISION_LOSS,
241 types::CAST_SIGN_LOSS,
242 unicode::NON_ASCII_LITERAL,
243 unicode::UNICODE_NOT_NFC,
246 reg.register_lint_group("clippy", vec![
247 approx_const::APPROX_CONSTANT,
248 array_indexing::OUT_OF_BOUNDS_INDEXING,
249 attrs::DEPRECATED_SEMVER,
250 attrs::INLINE_ALWAYS,
251 bit_mask::BAD_BIT_MASK,
252 bit_mask::INEFFECTIVE_BIT_MASK,
253 blacklisted_name::BLACKLISTED_NAME,
254 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
255 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
256 collapsible_if::COLLAPSIBLE_IF,
257 copies::IF_SAME_THEN_ELSE,
258 copies::IFS_SAME_COND,
259 copies::MATCH_SAME_ARMS,
260 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
261 derive::DERIVE_HASH_XOR_EQ,
262 derive::EXPL_IMPL_CLONE_ON_COPY,
265 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
266 enum_variants::ENUM_VARIANT_NAMES,
269 eta_reduction::REDUNDANT_CLOSURE,
270 format::USELESS_FORMAT,
271 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
272 formatting::SUSPICIOUS_ELSE_FORMATTING,
273 functions::TOO_MANY_ARGUMENTS,
274 identity_op::IDENTITY_OP,
275 if_not_else::IF_NOT_ELSE,
276 items_after_statements::ITEMS_AFTER_STATEMENTS,
277 len_zero::LEN_WITHOUT_IS_EMPTY,
279 lifetimes::NEEDLESS_LIFETIMES,
280 lifetimes::UNUSED_LIFETIMES,
282 loops::EXPLICIT_COUNTER_LOOP,
283 loops::EXPLICIT_ITER_LOOP,
285 loops::FOR_LOOP_OVER_OPTION,
286 loops::FOR_LOOP_OVER_RESULT,
287 loops::ITER_NEXT_LOOP,
288 loops::NEEDLESS_RANGE_LOOP,
289 loops::REVERSE_RANGE_LOOP,
290 loops::UNUSED_COLLECT,
291 loops::WHILE_LET_LOOP,
292 loops::WHILE_LET_ON_ITERATOR,
293 map_clone::MAP_CLONE,
295 matches::MATCH_OVERLAPPING_ARM,
296 matches::MATCH_REF_PATS,
297 matches::SINGLE_MATCH,
298 methods::CHARS_NEXT_CMP,
299 methods::CLONE_DOUBLE_REF,
300 methods::CLONE_ON_COPY,
301 methods::EXTEND_FROM_SLICE,
302 methods::FILTER_NEXT,
303 methods::NEW_RET_NO_SELF,
305 methods::OPTION_MAP_UNWRAP_OR,
306 methods::OPTION_MAP_UNWRAP_OR_ELSE,
307 methods::OR_FUN_CALL,
308 methods::SEARCH_IS_SOME,
309 methods::SHOULD_IMPLEMENT_TRAIT,
310 methods::SINGLE_CHAR_PATTERN,
311 methods::STR_TO_STRING,
312 methods::STRING_TO_STRING,
313 methods::WRONG_SELF_CONVENTION,
319 misc::REDUNDANT_PATTERN,
320 misc::TOPLEVEL_REF_ARG,
321 misc::USED_UNDERSCORE_BINDING,
322 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
323 misc_early::REDUNDANT_CLOSURE_CALL,
324 misc_early::UNNEEDED_FIELD_PATTERN,
325 mut_reference::UNNECESSARY_MUT_PASSED,
326 mutex_atomic::MUTEX_ATOMIC,
327 needless_bool::BOOL_COMPARISON,
328 needless_bool::NEEDLESS_BOOL,
329 needless_features::UNSTABLE_AS_MUT_SLICE,
330 needless_features::UNSTABLE_AS_SLICE,
331 needless_update::NEEDLESS_UPDATE,
332 new_without_default::NEW_WITHOUT_DEFAULT,
333 no_effect::NO_EFFECT,
334 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
335 non_expressive_names::SIMILAR_NAMES,
336 open_options::NONSENSICAL_OPEN_OPTIONS,
337 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
339 precedence::PRECEDENCE,
341 ranges::RANGE_STEP_BY_ZERO,
342 ranges::RANGE_ZIP_WITH_LEN,
343 regex::INVALID_REGEX,
345 regex::TRIVIAL_REGEX,
346 returns::LET_AND_RETURN,
347 returns::NEEDLESS_RETURN,
348 strings::STRING_LIT_AS_BYTES,
349 swap::ALMOST_SWAPPED,
351 temporary_assignment::TEMPORARY_ASSIGNMENT,
352 transmute::USELESS_TRANSMUTE,
353 types::ABSURD_EXTREME_COMPARISONS,
355 types::CHAR_LIT_AS_U8,
356 types::LET_UNIT_VALUE,
358 types::TYPE_COMPLEXITY,
360 unicode::ZERO_WIDTH_SPACE,
361 unused_label::UNUSED_LABEL,
363 zero_div_zero::ZERO_DIVIDED_BY_ZERO,