1 #![feature(type_macros)]
2 #![feature(plugin_registrar, box_syntax)]
3 #![feature(rustc_private, collections)]
4 #![feature(iter_arith)]
5 #![feature(custom_attribute)]
6 #![allow(indexing_slicing, shadow_reuse, unknown_lints)]
8 // this only exists to allow the "dogfood" integration test to work
10 #[allow(print_stdout)]
12 println!("What are you doing? Don't run clippy as an executable");
20 extern crate rustc_front;
24 // Only for the compile time checking of paths
26 extern crate collections;
28 // for unicode nfc normalization
29 extern crate unicode_normalization;
31 // for semver check in attrs.rs
35 extern crate regex_syntax;
37 extern crate rustc_plugin;
38 extern crate rustc_const_eval;
39 use rustc_plugin::Registry;
45 // begin lints modules, do not remove this comment, it’s used in `update_lints`
47 pub mod array_indexing;
50 pub mod blacklisted_name;
51 pub mod block_in_if_condition;
52 pub mod collapsible_if;
54 pub mod cyclomatic_complexity;
59 pub mod enum_glob_use;
60 pub mod enum_variants;
63 pub mod eta_reduction;
69 pub mod items_after_statements;
80 pub mod mut_reference;
82 pub mod needless_bool;
83 pub mod needless_features;
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 reg.register_late_lint_pass(box types::TypePass);
144 reg.register_late_lint_pass(box misc::TopLevelRefPass);
145 reg.register_late_lint_pass(box misc::CmpNan);
146 reg.register_late_lint_pass(box eq_op::EqOp);
147 reg.register_early_lint_pass(box enum_variants::EnumVariantNames);
148 reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
149 reg.register_late_lint_pass(box enum_clike::EnumClikeUnportableVariant);
150 reg.register_late_lint_pass(box bit_mask::BitMask);
151 reg.register_late_lint_pass(box ptr_arg::PtrArg);
152 reg.register_late_lint_pass(box needless_bool::NeedlessBool);
153 reg.register_late_lint_pass(box needless_bool::BoolComparison);
154 reg.register_late_lint_pass(box approx_const::ApproxConstant);
155 reg.register_late_lint_pass(box misc::FloatCmp);
156 reg.register_early_lint_pass(box precedence::Precedence);
157 reg.register_late_lint_pass(box eta_reduction::EtaPass);
158 reg.register_late_lint_pass(box identity_op::IdentityOp);
159 reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatemets);
160 reg.register_late_lint_pass(box mut_mut::MutMut);
161 reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
162 reg.register_late_lint_pass(box len_zero::LenZero);
163 reg.register_late_lint_pass(box misc::CmpOwned);
164 reg.register_late_lint_pass(box attrs::AttrPass);
165 reg.register_late_lint_pass(box collapsible_if::CollapsibleIf);
166 reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
167 reg.register_late_lint_pass(box misc::ModuloOne);
168 reg.register_late_lint_pass(box unicode::Unicode);
169 reg.register_late_lint_pass(box strings::StringAdd);
170 reg.register_early_lint_pass(box returns::ReturnPass);
171 reg.register_late_lint_pass(box methods::MethodsPass);
172 reg.register_late_lint_pass(box shadow::ShadowPass);
173 reg.register_late_lint_pass(box types::LetPass);
174 reg.register_late_lint_pass(box types::UnitCmp);
175 reg.register_late_lint_pass(box loops::LoopsPass);
176 reg.register_late_lint_pass(box lifetimes::LifetimePass);
177 reg.register_late_lint_pass(box entry::HashMapLint);
178 reg.register_late_lint_pass(box ranges::StepByZero);
179 reg.register_late_lint_pass(box types::CastPass);
180 reg.register_late_lint_pass(box types::TypeComplexityPass::new(conf.type_complexity_threshold));
181 reg.register_late_lint_pass(box matches::MatchPass);
182 reg.register_late_lint_pass(box misc::PatternPass);
183 reg.register_late_lint_pass(box minmax::MinMaxPass);
184 reg.register_late_lint_pass(box open_options::NonSensicalOpenOptions);
185 reg.register_late_lint_pass(box zero_div_zero::ZeroDivZeroPass);
186 reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
187 reg.register_late_lint_pass(box needless_features::NeedlessFeaturesPass);
188 reg.register_late_lint_pass(box needless_update::NeedlessUpdatePass);
189 reg.register_late_lint_pass(box no_effect::NoEffectPass);
190 reg.register_late_lint_pass(box map_clone::MapClonePass);
191 reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignmentPass);
192 reg.register_late_lint_pass(box transmute::UselessTransmute);
193 reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold));
194 reg.register_late_lint_pass(box escape::EscapePass);
195 reg.register_early_lint_pass(box misc_early::MiscEarly);
196 reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
197 reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
198 reg.register_late_lint_pass(box panic::PanicPass);
199 reg.register_late_lint_pass(box strings::StringLitAsBytes);
200 reg.register_late_lint_pass(box derive::Derive);
201 reg.register_late_lint_pass(box types::CharLitAsU8);
202 reg.register_late_lint_pass(box print::PrintLint);
203 reg.register_late_lint_pass(box vec::UselessVec);
204 reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
205 max_single_char_names: 5,
207 reg.register_late_lint_pass(box drop_ref::DropRefPass);
208 reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
209 reg.register_late_lint_pass(box regex::RegexPass::default());
210 reg.register_late_lint_pass(box copies::CopyAndPaste);
211 reg.register_late_lint_pass(box format::FormatMacLint);
212 reg.register_early_lint_pass(box formatting::Formatting);
213 reg.register_late_lint_pass(box swap::Swap);
214 reg.register_early_lint_pass(box if_not_else::IfNotElse);
215 reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
216 reg.register_late_lint_pass(box unused_label::UnusedLabel);
217 reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
218 reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names));
219 reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
221 reg.register_lint_group("clippy_pedantic", vec![
222 array_indexing::INDEXING_SLICING,
223 enum_glob_use::ENUM_GLOB_USE,
224 matches::SINGLE_MATCH_ELSE,
225 methods::OPTION_UNWRAP_USED,
226 methods::RESULT_UNWRAP_USED,
227 methods::WRONG_PUB_SELF_CONVENTION,
229 mutex_atomic::MUTEX_INTEGER,
232 shadow::SHADOW_REUSE,
234 shadow::SHADOW_UNRELATED,
236 strings::STRING_ADD_ASSIGN,
237 types::CAST_POSSIBLE_TRUNCATION,
238 types::CAST_POSSIBLE_WRAP,
239 types::CAST_PRECISION_LOSS,
240 types::CAST_SIGN_LOSS,
241 unicode::NON_ASCII_LITERAL,
242 unicode::UNICODE_NOT_NFC,
245 reg.register_lint_group("clippy", vec![
246 approx_const::APPROX_CONSTANT,
247 array_indexing::OUT_OF_BOUNDS_INDEXING,
248 attrs::DEPRECATED_SEMVER,
249 attrs::INLINE_ALWAYS,
250 bit_mask::BAD_BIT_MASK,
251 bit_mask::INEFFECTIVE_BIT_MASK,
252 blacklisted_name::BLACKLISTED_NAME,
253 block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
254 block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
255 collapsible_if::COLLAPSIBLE_IF,
256 copies::IF_SAME_THEN_ELSE,
257 copies::IFS_SAME_COND,
258 copies::MATCH_SAME_ARMS,
259 cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
260 derive::DERIVE_HASH_XOR_EQ,
261 derive::EXPL_IMPL_CLONE_ON_COPY,
264 enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
265 enum_variants::ENUM_VARIANT_NAMES,
268 eta_reduction::REDUNDANT_CLOSURE,
269 format::USELESS_FORMAT,
270 formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
271 formatting::SUSPICIOUS_ELSE_FORMATTING,
272 functions::TOO_MANY_ARGUMENTS,
273 identity_op::IDENTITY_OP,
274 if_not_else::IF_NOT_ELSE,
275 items_after_statements::ITEMS_AFTER_STATEMENTS,
276 len_zero::LEN_WITHOUT_IS_EMPTY,
278 lifetimes::NEEDLESS_LIFETIMES,
279 lifetimes::UNUSED_LIFETIMES,
281 loops::EXPLICIT_COUNTER_LOOP,
282 loops::EXPLICIT_ITER_LOOP,
284 loops::FOR_LOOP_OVER_OPTION,
285 loops::FOR_LOOP_OVER_RESULT,
286 loops::ITER_NEXT_LOOP,
287 loops::NEEDLESS_RANGE_LOOP,
288 loops::REVERSE_RANGE_LOOP,
289 loops::UNUSED_COLLECT,
290 loops::WHILE_LET_LOOP,
291 loops::WHILE_LET_ON_ITERATOR,
292 map_clone::MAP_CLONE,
294 matches::MATCH_OVERLAPPING_ARM,
295 matches::MATCH_REF_PATS,
296 matches::SINGLE_MATCH,
297 methods::CHARS_NEXT_CMP,
298 methods::CLONE_DOUBLE_REF,
299 methods::CLONE_ON_COPY,
300 methods::EXTEND_FROM_SLICE,
301 methods::FILTER_NEXT,
302 methods::NEW_RET_NO_SELF,
304 methods::OPTION_MAP_UNWRAP_OR,
305 methods::OPTION_MAP_UNWRAP_OR_ELSE,
306 methods::OR_FUN_CALL,
307 methods::SEARCH_IS_SOME,
308 methods::SHOULD_IMPLEMENT_TRAIT,
309 methods::SINGLE_CHAR_PATTERN,
310 methods::STR_TO_STRING,
311 methods::STRING_TO_STRING,
312 methods::WRONG_SELF_CONVENTION,
318 misc::REDUNDANT_PATTERN,
319 misc::TOPLEVEL_REF_ARG,
320 misc::USED_UNDERSCORE_BINDING,
321 misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
322 misc_early::REDUNDANT_CLOSURE_CALL,
323 misc_early::UNNEEDED_FIELD_PATTERN,
324 mut_reference::UNNECESSARY_MUT_PASSED,
325 mutex_atomic::MUTEX_ATOMIC,
326 needless_bool::BOOL_COMPARISON,
327 needless_bool::NEEDLESS_BOOL,
328 needless_features::UNSTABLE_AS_MUT_SLICE,
329 needless_features::UNSTABLE_AS_SLICE,
330 needless_update::NEEDLESS_UPDATE,
331 new_without_default::NEW_WITHOUT_DEFAULT,
332 no_effect::NO_EFFECT,
333 non_expressive_names::MANY_SINGLE_CHAR_NAMES,
334 non_expressive_names::SIMILAR_NAMES,
335 open_options::NONSENSICAL_OPEN_OPTIONS,
336 overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
338 precedence::PRECEDENCE,
340 ranges::RANGE_STEP_BY_ZERO,
341 ranges::RANGE_ZIP_WITH_LEN,
342 regex::INVALID_REGEX,
344 regex::TRIVIAL_REGEX,
345 returns::LET_AND_RETURN,
346 returns::NEEDLESS_RETURN,
347 strings::STRING_LIT_AS_BYTES,
348 swap::ALMOST_SWAPPED,
350 temporary_assignment::TEMPORARY_ASSIGNMENT,
351 transmute::USELESS_TRANSMUTE,
352 types::ABSURD_EXTREME_COMPARISONS,
354 types::CHAR_LIT_AS_U8,
355 types::LET_UNIT_VALUE,
357 types::TYPE_COMPLEXITY,
359 unicode::ZERO_WIDTH_SPACE,
360 unused_label::UNUSED_LABEL,
362 zero_div_zero::ZERO_DIVIDED_BY_ZERO,