Deny-by-default lints

These lints are all set to the 'deny' level by default.

exceeding-bitshifts

This lint detects that a shift exceeds the type's number of bits. Someexample code that triggers this lint:

  1. 1_i32 << 32;

This will produce:

  1. error: bitshift exceeds the type's number of bits
  2. --> src/main.rs:2:5
  3. |
  4. 2 | 1_i32 << 32;
  5. | ^^^^^^^^^^^
  6. |

invalid-type-param-default

This lint detects type parameter default erroneously allowed in invalid location. Someexample code that triggers this lint:

  1. fn foo<T=i32>(t: T) {}

This will produce:

  1. error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions.
  2. --> src/main.rs:4:8
  3. |
  4. 4 | fn foo<T=i32>(t: T) {}
  5. | ^
  6. |
  7. = note: `#[deny(invalid_type_param_default)]` on by default
  8. = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  9. = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>

missing-fragment-specifier

The missing_fragment_specifier warning is issued when an unused pattern in amacro_rules! macro definition has a meta-variable (e.g. $e) that is notfollowed by a fragment specifier (e.g. :expr).

This warning can always be fixed by removing the unused pattern in themacro_rules! macro definition.

mutable-transmutes

This lint catches transmuting from &T to &mut T because it is undefinedbehavior. Some example code that triggers this lint:

  1. unsafe {
  2. let y = std::mem::transmute::<&i32, &mut i32>(&5);
  3. }

This will produce:

  1. error: mutating transmuted &mut T from &T may cause undefined behavior, consider instead using an UnsafeCell
  2. --> src/main.rs:3:17
  3. |
  4. 3 | let y = std::mem::transmute::<&i32, &mut i32>(&5);
  5. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6. |

no-mangle-const-items

This lint detects any const items with the #[no_mangle] attribute.Constants do not have their symbols exported, and therefore, this probablymeans you meant to use a static, not a const. Some example code thattriggers this lint:

  1. #[no_mangle]
  2. const FOO: i32 = 5;

This will produce:

  1. error: const items should never be `#[no_mangle]`
  2. --> src/main.rs:3:1
  3. |
  4. 3 | const FOO: i32 = 5;
  5. | -----^^^^^^^^^^^^^^
  6. | |
  7. | help: try a static value: `pub static`
  8. |

overflowing-literals

This lint detects literal out of range for its type. Someexample code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. let x: u8 = 1000;
  4. }

This will produce:

  1. error: literal out of range for u8
  2. --> src/main.rs:2:17
  3. |
  4. 2 | let x: u8 = 1000;
  5. | ^^^^
  6. |

patterns-in-fns-without-body

This lint detects patterns in functions without body were that werepreviously erroneously allowed. Some example code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. trait Trait {
  4.     fn foo(mut arg: u8);
  5. }
  6. }

This will produce:

  1. warning: patterns aren't allowed in methods without bodies
  2. --> src/main.rs:2:12
  3. |
  4. 2 | fn foo(mut arg: u8);
  5. | ^^^^^^^
  6. |
  7. = note: `#[warn(patterns_in_fns_without_body)]` on by default
  8. = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  9. = note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>

To fix this, remove the pattern; it can be used in the implementation withoutbeing used in the definition. That is:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. trait Trait {
  4.     fn foo(arg: u8);
  5. }
  6. impl Trait for i32 {
  7.     fn foo(mut arg: u8) {
  8.     }
  9. }
  10. }

pub-use-of-private-extern-crate

This lint detects a specific situation of re-exporting a private extern crate;

unknown-crate-types

This lint detects an unknown crate type found in a #[crate_type] directive. Someexample code that triggers this lint:

  1. #![crate_type="lol"]

This will produce:

  1. error: invalid `crate_type` value
  2. --> src/lib.rs:1:1
  3. |
  4. 1 | #![crate_type="lol"]
  5. | ^^^^^^^^^^^^^^^^^^^^
  6. |

const-err

This lint detects expressions that will always panic at runtime and would be anerror in a const context.

  1. let _ = [0; 4][4];

This will produce:

  1. error: index out of bounds: the len is 4 but the index is 4
  2. --> src/lib.rs:1:9
  3. |
  4. 1 | let _ = [0; 4][4];
  5. | ^^^^^^^^^
  6. |

order-dependent-trait-objects

This lint detects a trait coherency violation that would allow creating twotrait impls for the same dynamic trait object involving marker traits.