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