]> git.lizzy.rs Git - rust.git/blob - src/lib.rs
Merge pull request #662 from mcarton/#601
[rust.git] / src / lib.rs
1 #![feature(plugin_registrar, box_syntax)]
2 #![feature(rustc_private, collections)]
3 #![feature(iter_arith)]
4 #![feature(custom_attribute)]
5 #![allow(unknown_lints)]
6
7 // this only exists to allow the "dogfood" integration test to work
8 #[allow(dead_code)]
9 #[allow(print_stdout)]
10 fn main() {
11     println!("What are you doing? Don't run clippy as an executable");
12 }
13
14 #[macro_use]
15 extern crate syntax;
16 #[macro_use]
17 extern crate rustc;
18 #[macro_use]
19 extern crate rustc_front;
20
21 // Only for the compile time checking of paths
22 extern crate core;
23 extern crate collections;
24
25 // for unicode nfc normalization
26 extern crate unicode_normalization;
27
28 // for semver check in attrs.rs
29 extern crate semver;
30
31 // for regex checking
32 extern crate regex_syntax;
33
34 extern crate rustc_plugin;
35
36 use rustc_plugin::Registry;
37
38 #[macro_use]
39 pub mod utils;
40 pub mod copies;
41 pub mod consts;
42 pub mod types;
43 pub mod misc;
44 pub mod enum_glob_use;
45 pub mod eq_op;
46 pub mod bit_mask;
47 pub mod ptr_arg;
48 pub mod needless_bool;
49 pub mod approx_const;
50 pub mod eta_reduction;
51 pub mod enum_variants;
52 pub mod identity_op;
53 pub mod items_after_statements;
54 pub mod minmax;
55 pub mod mut_mut;
56 pub mod mut_reference;
57 pub mod len_zero;
58 pub mod attrs;
59 pub mod collapsible_if;
60 pub mod block_in_if_condition;
61 pub mod unicode;
62 pub mod shadow;
63 pub mod strings;
64 pub mod methods;
65 pub mod returns;
66 pub mod lifetimes;
67 pub mod loops;
68 pub mod ranges;
69 pub mod map_clone;
70 pub mod matches;
71 pub mod precedence;
72 pub mod mutex_atomic;
73 pub mod zero_div_zero;
74 pub mod open_options;
75 pub mod needless_features;
76 pub mod needless_update;
77 pub mod no_effect;
78 pub mod temporary_assignment;
79 pub mod transmute;
80 pub mod cyclomatic_complexity;
81 pub mod escape;
82 pub mod entry;
83 pub mod misc_early;
84 pub mod array_indexing;
85 pub mod panic;
86 pub mod derive;
87 pub mod print;
88 pub mod vec;
89 pub mod drop_ref;
90 pub mod regex;
91
92 mod reexport {
93     pub use syntax::ast::{Name, NodeId};
94 }
95
96 #[plugin_registrar]
97 #[cfg_attr(rustfmt, rustfmt_skip)]
98 pub fn plugin_registrar(reg: &mut Registry) {
99     reg.register_late_lint_pass(box types::TypePass);
100     reg.register_late_lint_pass(box misc::TopLevelRefPass);
101     reg.register_late_lint_pass(box misc::CmpNan);
102     reg.register_late_lint_pass(box eq_op::EqOp);
103     reg.register_early_lint_pass(box enum_variants::EnumVariantNames);
104     reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
105     reg.register_late_lint_pass(box bit_mask::BitMask);
106     reg.register_late_lint_pass(box ptr_arg::PtrArg);
107     reg.register_late_lint_pass(box needless_bool::NeedlessBool);
108     reg.register_late_lint_pass(box needless_bool::BoolComparison);
109     reg.register_late_lint_pass(box approx_const::ApproxConstant);
110     reg.register_late_lint_pass(box misc::FloatCmp);
111     reg.register_early_lint_pass(box precedence::Precedence);
112     reg.register_late_lint_pass(box eta_reduction::EtaPass);
113     reg.register_late_lint_pass(box identity_op::IdentityOp);
114     reg.register_early_lint_pass(box items_after_statements::ItemsAfterStatemets);
115     reg.register_late_lint_pass(box mut_mut::MutMut);
116     reg.register_late_lint_pass(box mut_reference::UnnecessaryMutPassed);
117     reg.register_late_lint_pass(box len_zero::LenZero);
118     reg.register_late_lint_pass(box misc::CmpOwned);
119     reg.register_late_lint_pass(box attrs::AttrPass);
120     reg.register_late_lint_pass(box collapsible_if::CollapsibleIf);
121     reg.register_late_lint_pass(box block_in_if_condition::BlockInIfCondition);
122     reg.register_late_lint_pass(box misc::ModuloOne);
123     reg.register_late_lint_pass(box unicode::Unicode);
124     reg.register_late_lint_pass(box strings::StringAdd);
125     reg.register_early_lint_pass(box returns::ReturnPass);
126     reg.register_late_lint_pass(box methods::MethodsPass);
127     reg.register_late_lint_pass(box shadow::ShadowPass);
128     reg.register_late_lint_pass(box types::LetPass);
129     reg.register_late_lint_pass(box types::UnitCmp);
130     reg.register_late_lint_pass(box loops::LoopsPass);
131     reg.register_late_lint_pass(box lifetimes::LifetimePass);
132     reg.register_late_lint_pass(box entry::HashMapLint);
133     reg.register_late_lint_pass(box ranges::StepByZero);
134     reg.register_late_lint_pass(box types::CastPass);
135     reg.register_late_lint_pass(box types::TypeComplexityPass);
136     reg.register_late_lint_pass(box matches::MatchPass);
137     reg.register_late_lint_pass(box misc::PatternPass);
138     reg.register_late_lint_pass(box minmax::MinMaxPass);
139     reg.register_late_lint_pass(box open_options::NonSensicalOpenOptions);
140     reg.register_late_lint_pass(box zero_div_zero::ZeroDivZeroPass);
141     reg.register_late_lint_pass(box mutex_atomic::MutexAtomic);
142     reg.register_late_lint_pass(box needless_features::NeedlessFeaturesPass);
143     reg.register_late_lint_pass(box needless_update::NeedlessUpdatePass);
144     reg.register_late_lint_pass(box no_effect::NoEffectPass);
145     reg.register_late_lint_pass(box map_clone::MapClonePass);
146     reg.register_late_lint_pass(box temporary_assignment::TemporaryAssignmentPass);
147     reg.register_late_lint_pass(box transmute::UselessTransmute);
148     reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(25));
149     reg.register_late_lint_pass(box escape::EscapePass);
150     reg.register_early_lint_pass(box misc_early::MiscEarly);
151     reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
152     reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
153     reg.register_late_lint_pass(box panic::PanicPass);
154     reg.register_late_lint_pass(box strings::StringLitAsBytes);
155     reg.register_late_lint_pass(box derive::Derive);
156     reg.register_late_lint_pass(box types::CharLitAsU8);
157     reg.register_late_lint_pass(box print::PrintLint);
158     reg.register_late_lint_pass(box vec::UselessVec);
159     reg.register_late_lint_pass(box drop_ref::DropRefPass);
160     reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
161     reg.register_late_lint_pass(box regex::RegexPass);
162     reg.register_late_lint_pass(box copies::CopyAndPaste);
163
164     reg.register_lint_group("clippy_pedantic", vec![
165         enum_glob_use::ENUM_GLOB_USE,
166         matches::SINGLE_MATCH_ELSE,
167         methods::OPTION_UNWRAP_USED,
168         methods::RESULT_UNWRAP_USED,
169         methods::WRONG_PUB_SELF_CONVENTION,
170         mut_mut::MUT_MUT,
171         mutex_atomic::MUTEX_INTEGER,
172         print::PRINT_STDOUT,
173         print::USE_DEBUG,
174         shadow::SHADOW_REUSE,
175         shadow::SHADOW_SAME,
176         shadow::SHADOW_UNRELATED,
177         strings::STRING_ADD,
178         strings::STRING_ADD_ASSIGN,
179         types::CAST_POSSIBLE_TRUNCATION,
180         types::CAST_POSSIBLE_WRAP,
181         types::CAST_PRECISION_LOSS,
182         types::CAST_SIGN_LOSS,
183         unicode::NON_ASCII_LITERAL,
184         unicode::UNICODE_NOT_NFC,
185     ]);
186
187     reg.register_lint_group("clippy", vec![
188         approx_const::APPROX_CONSTANT,
189         array_indexing::OUT_OF_BOUNDS_INDEXING,
190         attrs::DEPRECATED_SEMVER,
191         attrs::INLINE_ALWAYS,
192         bit_mask::BAD_BIT_MASK,
193         bit_mask::INEFFECTIVE_BIT_MASK,
194         block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
195         block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
196         collapsible_if::COLLAPSIBLE_IF,
197         copies::IF_SAME_THEN_ELSE,
198         copies::IFS_SAME_COND,
199         copies::MATCH_SAME_ARMS,
200         cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
201         derive::DERIVE_HASH_NOT_EQ,
202         derive::EXPL_IMPL_CLONE_ON_COPY,
203         drop_ref::DROP_REF,
204         entry::MAP_ENTRY,
205         enum_variants::ENUM_VARIANT_NAMES,
206         eq_op::EQ_OP,
207         escape::BOXED_LOCAL,
208         eta_reduction::REDUNDANT_CLOSURE,
209         identity_op::IDENTITY_OP,
210         items_after_statements::ITEMS_AFTER_STATEMENTS,
211         len_zero::LEN_WITHOUT_IS_EMPTY,
212         len_zero::LEN_ZERO,
213         lifetimes::NEEDLESS_LIFETIMES,
214         lifetimes::UNUSED_LIFETIMES,
215         loops::EMPTY_LOOP,
216         loops::EXPLICIT_COUNTER_LOOP,
217         loops::EXPLICIT_ITER_LOOP,
218         loops::FOR_KV_MAP,
219         loops::FOR_LOOP_OVER_OPTION,
220         loops::FOR_LOOP_OVER_RESULT,
221         loops::ITER_NEXT_LOOP,
222         loops::NEEDLESS_RANGE_LOOP,
223         loops::REVERSE_RANGE_LOOP,
224         loops::UNUSED_COLLECT,
225         loops::WHILE_LET_LOOP,
226         loops::WHILE_LET_ON_ITERATOR,
227         map_clone::MAP_CLONE,
228         matches::MATCH_BOOL,
229         matches::MATCH_OVERLAPPING_ARM,
230         matches::MATCH_REF_PATS,
231         matches::SINGLE_MATCH,
232         methods::CHARS_NEXT_CMP,
233         methods::CLONE_DOUBLE_REF,
234         methods::CLONE_ON_COPY,
235         methods::EXTEND_FROM_SLICE,
236         methods::FILTER_NEXT,
237         methods::NEW_RET_NO_SELF,
238         methods::OK_EXPECT,
239         methods::OPTION_MAP_UNWRAP_OR,
240         methods::OPTION_MAP_UNWRAP_OR_ELSE,
241         methods::OR_FUN_CALL,
242         methods::SEARCH_IS_SOME,
243         methods::SHOULD_IMPLEMENT_TRAIT,
244         methods::STR_TO_STRING,
245         methods::STRING_TO_STRING,
246         methods::WRONG_SELF_CONVENTION,
247         minmax::MIN_MAX,
248         misc::CMP_NAN,
249         misc::CMP_OWNED,
250         misc::FLOAT_CMP,
251         misc::MODULO_ONE,
252         misc::REDUNDANT_PATTERN,
253         misc::TOPLEVEL_REF_ARG,
254         misc::USED_UNDERSCORE_BINDING,
255         misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
256         misc_early::UNNEEDED_FIELD_PATTERN,
257         mut_reference::UNNECESSARY_MUT_PASSED,
258         mutex_atomic::MUTEX_ATOMIC,
259         needless_bool::BOOL_COMPARISON,
260         needless_bool::NEEDLESS_BOOL,
261         needless_features::UNSTABLE_AS_MUT_SLICE,
262         needless_features::UNSTABLE_AS_SLICE,
263         needless_update::NEEDLESS_UPDATE,
264         no_effect::NO_EFFECT,
265         open_options::NONSENSICAL_OPEN_OPTIONS,
266         panic::PANIC_PARAMS,
267         precedence::PRECEDENCE,
268         ptr_arg::PTR_ARG,
269         ranges::RANGE_STEP_BY_ZERO,
270         ranges::RANGE_ZIP_WITH_LEN,
271         regex::INVALID_REGEX,
272         regex::REGEX_MACRO,
273         regex::TRIVIAL_REGEX,
274         returns::LET_AND_RETURN,
275         returns::NEEDLESS_RETURN,
276         strings::STRING_LIT_AS_BYTES,
277         temporary_assignment::TEMPORARY_ASSIGNMENT,
278         transmute::USELESS_TRANSMUTE,
279         types::ABSURD_EXTREME_COMPARISONS,
280         types::BOX_VEC,
281         types::CHAR_LIT_AS_U8,
282         types::LET_UNIT_VALUE,
283         types::LINKEDLIST,
284         types::TYPE_COMPLEXITY,
285         types::UNIT_CMP,
286         unicode::ZERO_WIDTH_SPACE,
287         vec::USELESS_VEC,
288         zero_div_zero::ZERO_DIVIDED_BY_ZERO,
289     ]);
290 }