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