]> git.lizzy.rs Git - rust.git/blob - src/lib.rs
Merge pull request #727 from oli-obk/similar_names
[rust.git] / src / lib.rs
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)]
8
9 // this only exists to allow the "dogfood" integration test to work
10 #[allow(dead_code)]
11 #[allow(print_stdout)]
12 fn main() {
13     println!("What are you doing? Don't run clippy as an executable");
14 }
15
16 #[macro_use]
17 extern crate syntax;
18 #[macro_use]
19 extern crate rustc;
20 #[macro_use]
21 extern crate rustc_front;
22
23 extern crate toml;
24
25 // Only for the compile time checking of paths
26 extern crate core;
27 extern crate collections;
28
29 // for unicode nfc normalization
30 extern crate unicode_normalization;
31
32 // for semver check in attrs.rs
33 extern crate semver;
34
35 // for regex checking
36 extern crate regex_syntax;
37
38 extern crate rustc_plugin;
39 extern crate rustc_const_eval;
40 use rustc_plugin::Registry;
41
42 pub mod consts;
43 #[macro_use]
44 pub mod utils;
45
46 // begin lints modules, do not remove this comment, it’s used in `update_lints`
47 pub mod approx_const;
48 pub mod array_indexing;
49 pub mod attrs;
50 pub mod bit_mask;
51 pub mod blacklisted_name;
52 pub mod block_in_if_condition;
53 pub mod collapsible_if;
54 pub mod copies;
55 pub mod cyclomatic_complexity;
56 pub mod derive;
57 pub mod drop_ref;
58 pub mod entry;
59 pub mod enum_clike;
60 pub mod enum_glob_use;
61 pub mod enum_variants;
62 pub mod eq_op;
63 pub mod escape;
64 pub mod eta_reduction;
65 pub mod format;
66 pub mod formatting;
67 pub mod functions;
68 pub mod identity_op;
69 pub mod if_not_else;
70 pub mod items_after_statements;
71 pub mod len_zero;
72 pub mod lifetimes;
73 pub mod loops;
74 pub mod map_clone;
75 pub mod matches;
76 pub mod methods;
77 pub mod minmax;
78 pub mod misc;
79 pub mod misc_early;
80 pub mod mut_mut;
81 pub mod mut_reference;
82 pub mod mutex_atomic;
83 pub mod needless_bool;
84 pub mod needless_features;
85 pub mod needless_update;
86 pub mod new_without_default;
87 pub mod no_effect;
88 pub mod non_expressive_names;
89 pub mod open_options;
90 pub mod overflow_check_conditional;
91 pub mod panic;
92 pub mod precedence;
93 pub mod print;
94 pub mod ptr_arg;
95 pub mod ranges;
96 pub mod regex;
97 pub mod returns;
98 pub mod shadow;
99 pub mod strings;
100 pub mod swap;
101 pub mod temporary_assignment;
102 pub mod transmute;
103 pub mod types;
104 pub mod unicode;
105 pub mod unused_label;
106 pub mod vec;
107 pub mod zero_div_zero;
108 // end lints modules, do not remove this comment, it’s used in `update_lints`
109
110 mod reexport {
111     pub use syntax::ast::{Name, NodeId};
112 }
113
114 #[plugin_registrar]
115 #[cfg_attr(rustfmt, rustfmt_skip)]
116 pub fn plugin_registrar(reg: &mut Registry) {
117     let conf = match utils::conf::conf_file(reg.args()) {
118         Ok(file_name) => {
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 {
122                 (&**file_name, true)
123             } else {
124                 ("clippy.toml", false)
125             };
126
127             let (conf, errors) = utils::conf::read_conf(&file_name, must_exist);
128
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();
132             }
133
134             conf
135         }
136         Err((err, span)) => {
137             reg.sess.struct_span_err(span, err)
138                     .span_note(span, "Clippy will use defaulf configuration")
139                     .emit();
140             utils::conf::Conf::default()
141         }
142     };
143
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,
207     });
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));
221
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,
229         mut_mut::MUT_MUT,
230         mutex_atomic::MUTEX_INTEGER,
231         print::PRINT_STDOUT,
232         print::USE_DEBUG,
233         shadow::SHADOW_REUSE,
234         shadow::SHADOW_SAME,
235         shadow::SHADOW_UNRELATED,
236         strings::STRING_ADD,
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,
244     ]);
245
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,
263         drop_ref::DROP_REF,
264         entry::MAP_ENTRY,
265         enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
266         enum_variants::ENUM_VARIANT_NAMES,
267         eq_op::EQ_OP,
268         escape::BOXED_LOCAL,
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,
278         len_zero::LEN_ZERO,
279         lifetimes::NEEDLESS_LIFETIMES,
280         lifetimes::UNUSED_LIFETIMES,
281         loops::EMPTY_LOOP,
282         loops::EXPLICIT_COUNTER_LOOP,
283         loops::EXPLICIT_ITER_LOOP,
284         loops::FOR_KV_MAP,
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,
294         matches::MATCH_BOOL,
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,
304         methods::OK_EXPECT,
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,
314         minmax::MIN_MAX,
315         misc::CMP_NAN,
316         misc::CMP_OWNED,
317         misc::FLOAT_CMP,
318         misc::MODULO_ONE,
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,
338         panic::PANIC_PARAMS,
339         precedence::PRECEDENCE,
340         ptr_arg::PTR_ARG,
341         ranges::RANGE_STEP_BY_ZERO,
342         ranges::RANGE_ZIP_WITH_LEN,
343         regex::INVALID_REGEX,
344         regex::REGEX_MACRO,
345         regex::TRIVIAL_REGEX,
346         returns::LET_AND_RETURN,
347         returns::NEEDLESS_RETURN,
348         strings::STRING_LIT_AS_BYTES,
349         swap::ALMOST_SWAPPED,
350         swap::MANUAL_SWAP,
351         temporary_assignment::TEMPORARY_ASSIGNMENT,
352         transmute::USELESS_TRANSMUTE,
353         types::ABSURD_EXTREME_COMPARISONS,
354         types::BOX_VEC,
355         types::CHAR_LIT_AS_U8,
356         types::LET_UNIT_VALUE,
357         types::LINKEDLIST,
358         types::TYPE_COMPLEXITY,
359         types::UNIT_CMP,
360         unicode::ZERO_WIDTH_SPACE,
361         unused_label::UNUSED_LABEL,
362         vec::USELESS_VEC,
363         zero_div_zero::ZERO_DIVIDED_BY_ZERO,
364     ]);
365 }