]>
Commit | Line | Data |
---|---|---|
83c7162d XL |
1 | # Deny-by-default lints |
2 | ||
3 | These lints are all set to the 'deny' level by default. | |
4 | ||
5 | ## exceeding-bitshifts | |
6 | ||
7 | This lint detects that a shift exceeds the type's number of bits. Some | |
8 | example code that triggers this lint: | |
9 | ||
10 | ```rust,ignore | |
11 | 1_i32 << 32; | |
12 | ``` | |
13 | ||
14 | This will produce: | |
15 | ||
16 | ```text | |
17 | error: bitshift exceeds the type's number of bits | |
18 | --> src/main.rs:2:5 | |
19 | | | |
20 | 2 | 1_i32 << 32; | |
21 | | ^^^^^^^^^^^ | |
22 | | | |
23 | ``` | |
24 | ||
25 | ## invalid-type-param-default | |
26 | ||
27 | This lint detects type parameter default erroneously allowed in invalid location. Some | |
28 | example code that triggers this lint: | |
29 | ||
30 | ```rust,ignore | |
31 | fn foo<T=i32>(t: T) {} | |
32 | ``` | |
33 | ||
34 | This will produce: | |
35 | ||
36 | ```text | |
37 | error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions. | |
38 | --> src/main.rs:4:8 | |
39 | | | |
40 | 4 | fn foo<T=i32>(t: T) {} | |
41 | | ^ | |
42 | | | |
416331ca | 43 | = note: `#[deny(invalid_type_param_default)]` on by default |
83c7162d XL |
44 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! |
45 | = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887> | |
46 | ``` | |
47 | ||
83c7162d XL |
48 | ## mutable-transmutes |
49 | ||
b7449926 | 50 | This lint catches transmuting from `&T` to `&mut T` because it is undefined |
83c7162d XL |
51 | behavior. Some example code that triggers this lint: |
52 | ||
53 | ```rust,ignore | |
54 | unsafe { | |
55 | let y = std::mem::transmute::<&i32, &mut i32>(&5); | |
56 | } | |
57 | ``` | |
58 | ||
59 | This will produce: | |
60 | ||
61 | ```text | |
62 | error: mutating transmuted &mut T from &T may cause undefined behavior, consider instead using an UnsafeCell | |
63 | --> src/main.rs:3:17 | |
64 | | | |
65 | 3 | let y = std::mem::transmute::<&i32, &mut i32>(&5); | |
66 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
67 | | | |
68 | ``` | |
69 | ||
70 | ||
71 | ## no-mangle-const-items | |
72 | ||
73 | This lint detects any `const` items with the `#[no_mangle]` attribute. | |
74 | Constants do not have their symbols exported, and therefore, this probably | |
75 | means you meant to use a `static`, not a `const`. Some example code that | |
76 | triggers this lint: | |
77 | ||
78 | ```rust,ignore | |
79 | #[no_mangle] | |
80 | const FOO: i32 = 5; | |
81 | ``` | |
82 | ||
83 | This will produce: | |
84 | ||
85 | ```text | |
416331ca | 86 | error: const items should never be `#[no_mangle]` |
83c7162d XL |
87 | --> src/main.rs:3:1 |
88 | | | |
89 | 3 | const FOO: i32 = 5; | |
90 | | -----^^^^^^^^^^^^^^ | |
91 | | | | |
92 | | help: try a static value: `pub static` | |
93 | | | |
94 | ``` | |
95 | ||
9fa01778 XL |
96 | ## overflowing-literals |
97 | ||
98 | This lint detects literal out of range for its type. Some | |
99 | example code that triggers this lint: | |
100 | ||
101 | ```rust,compile_fail | |
102 | let x: u8 = 1000; | |
103 | ``` | |
104 | ||
105 | This will produce: | |
106 | ||
107 | ```text | |
108 | error: literal out of range for u8 | |
109 | --> src/main.rs:2:17 | |
110 | | | |
111 | 2 | let x: u8 = 1000; | |
112 | | ^^^^ | |
113 | | | |
114 | ``` | |
115 | ||
60c5eb7d | 116 | ## patterns-in-fns-without-body |
83c7162d | 117 | |
60c5eb7d XL |
118 | This lint detects patterns in functions without body were that were |
119 | previously erroneously allowed. Some example code that triggers this lint: | |
83c7162d | 120 | |
60c5eb7d XL |
121 | ```rust,compile_fail |
122 | trait Trait { | |
123 | fn foo(mut arg: u8); | |
124 | } | |
83c7162d XL |
125 | ``` |
126 | ||
127 | This will produce: | |
128 | ||
129 | ```text | |
60c5eb7d XL |
130 | warning: patterns aren't allowed in methods without bodies |
131 | --> src/main.rs:2:12 | |
83c7162d | 132 | | |
60c5eb7d XL |
133 | 2 | fn foo(mut arg: u8); |
134 | | ^^^^^^^ | |
83c7162d | 135 | | |
60c5eb7d | 136 | = note: `#[warn(patterns_in_fns_without_body)]` on by default |
83c7162d | 137 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! |
60c5eb7d | 138 | = note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203> |
83c7162d XL |
139 | ``` |
140 | ||
60c5eb7d XL |
141 | To fix this, remove the pattern; it can be used in the implementation without |
142 | being used in the definition. That is: | |
83c7162d | 143 | |
60c5eb7d XL |
144 | ```rust |
145 | trait Trait { | |
146 | fn foo(arg: u8); | |
147 | } | |
83c7162d | 148 | |
60c5eb7d XL |
149 | impl Trait for i32 { |
150 | fn foo(mut arg: u8) { | |
151 | ||
152 | } | |
153 | } | |
154 | ``` | |
83c7162d | 155 | |
60c5eb7d | 156 | ## pub-use-of-private-extern-crate |
83c7162d | 157 | |
60c5eb7d | 158 | This lint detects a specific situation of re-exporting a private `extern crate`; |
83c7162d XL |
159 | |
160 | ## unknown-crate-types | |
161 | ||
162 | This lint detects an unknown crate type found in a `#[crate_type]` directive. Some | |
163 | example code that triggers this lint: | |
164 | ||
165 | ```rust,ignore | |
166 | #![crate_type="lol"] | |
167 | ``` | |
168 | ||
169 | This will produce: | |
170 | ||
171 | ```text | |
172 | error: invalid `crate_type` value | |
173 | --> src/lib.rs:1:1 | |
174 | | | |
175 | 1 | #![crate_type="lol"] | |
176 | | ^^^^^^^^^^^^^^^^^^^^ | |
177 | | | |
178 | ``` | |
e74abb32 XL |
179 | |
180 | ## const-err | |
181 | ||
182 | This lint detects expressions that will always panic at runtime and would be an | |
183 | error in a `const` context. | |
184 | ||
185 | ```rust,ignore | |
186 | let _ = [0; 4][4]; | |
187 | ``` | |
188 | ||
189 | This will produce: | |
190 | ||
191 | ```text | |
192 | error: index out of bounds: the len is 4 but the index is 4 | |
193 | --> src/lib.rs:1:9 | |
194 | | | |
195 | 1 | let _ = [0; 4][4]; | |
196 | | ^^^^^^^^^ | |
197 | | | |
198 | ``` | |
199 | ||
200 | ## order-dependent-trait-objects | |
201 | ||
202 | This lint detects a trait coherency violation that would allow creating two | |
203 | trait impls for the same dynamic trait object involving marker traits. |