Allowed-by-default lints

These lints are all set to the 'allow' level by default. As such, they won't show upunless you set them to a higher lint level with a flag or attribute.

anonymous-parameters

This lint detects anonymous parameters. Some example code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. trait Foo {
  4.     fn foo(usize);
  5. }
  6. }

When set to 'deny', this will produce:

  1. error: use of deprecated anonymous parameter
  2. --> src/lib.rs:5:11
  3. |
  4. 5 | fn foo(usize);
  5. | ^
  6. |
  7. = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  8. = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>

This syntax is mostly a historical accident, and can be worked around quiteeasily:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. trait Foo {
  4.     fn foo(_: usize);
  5. }
  6. }

bare-trait-object

This lint suggests using dyn Trait for trait objects. Some example codethat triggers this lint:

  1. #![allow(unused_variables)]
  2. #![feature(dyn_trait)]
  3. fn main() {
  4. trait Trait { }
  5. fn takes_trait_object(_: Box<Trait>) {
  6. }
  7. }

When set to 'deny', this will produce:

  1. error: trait objects without an explicit `dyn` are deprecated
  2. --> src/lib.rs:7:30
  3. |
  4. 7 | fn takes_trait_object(_: Box<Trait>) {
  5. | ^^^^^ help: use `dyn`: `dyn Trait`
  6. |

To fix it, do as the help message suggests:

  1. #![allow(unused_variables)]
  2. #![feature(dyn_trait)]
  3. #![deny(bare_trait_objects)]
  4. fn main() {
  5. trait Trait { }
  6. fn takes_trait_object(_: Box<dyn Trait>) {
  7. }
  8. }

box-pointers

This lints use of the Box type. Some example code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. struct Foo {
  4.     x: Box<isize>,
  5. }
  6. }

When set to 'deny', this will produce:

  1. error: type uses owned (Box type) pointers: std::boxed::Box<isize>
  2. --> src/lib.rs:6:5
  3. |
  4. 6 | x: Box<isize> //~ ERROR type uses owned
  5. | ^^^^^^^^^^^^^
  6. |

This lint is mostly historical, and not particularly useful. Box<T> used tobe built into the language, and the only way to do heap allocation. Today'sRust can call into other allocators, etc.

elided-lifetime-in-path

This lint detects the use of hidden lifetime parameters. Some example codethat triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. struct Foo<'a> {
  4.     x: &'a u32
  5. }
  6. fn foo(x: &Foo) {
  7. }
  8. }

When set to 'deny', this will produce:

  1. error: hidden lifetime parameters are deprecated, try `Foo<'_>`
  2. --> src/lib.rs:5:12
  3. |
  4. 5 | fn foo(x: &Foo) {
  5. | ^^^
  6. |

Lifetime elision elides this lifetime, but that is being deprecated.

missing-copy-implementations

This lint detects potentially-forgotten implementations of Copy. Someexample code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. pub struct Foo {
  4.     pub field: i32
  5. }
  6. }

When set to 'deny', this will produce:

  1. error: type could implement `Copy`; consider adding `impl Copy`
  2. --> src/main.rs:3:1
  3. |
  4. 3 | / pub struct Foo { //~ ERROR type could implement `Copy`; consider adding `impl Copy`
  5. 4 | | pub field: i32
  6. 5 | | }
  7. | |_^
  8. |

You can fix the lint by deriving Copy.

This lint is set to 'allow' because this code isn't bad; it's common to writenewtypes like this specifically so that a Copy type is no longer Copy.

missing-debug-implementations

This lint detects missing implementations of fmt::Debug. Some example codethat triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. pub struct Foo;
  4. }

When set to 'deny', this will produce:

  1. error: type does not implement `fmt::Debug`; consider adding `#[derive(Debug)]` or a manual implementation
  2. --> src/main.rs:3:1
  3. |
  4. 3 | pub struct Foo;
  5. | ^^^^^^^^^^^^^^^
  6. |

You can fix the lint by deriving Debug.

missing-docs

This lint detects missing documentation for public items. Some example codethat triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. pub fn foo() {}
  4. }

When set to 'deny', this will produce:

  1. error: missing documentation for crate
  2. --> src/main.rs:1:1
  3. |
  4. 1 | / #![deny(missing_docs)]
  5. 2 | |
  6. 3 | | pub fn foo() {}
  7. 4 | |
  8. 5 | | fn main() {}
  9. | |____________^
  10. |
  11. error: missing documentation for a function
  12. --> src/main.rs:3:1
  13. |
  14. 3 | pub fn foo() {}
  15. | ^^^^^^^^^^^^

To fix the lint, add documentation to all items.

single-use-lifetimes

This lint detects lifetimes that are only used once. Some example code thattriggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. struct Foo<'x> {
  4.     x: &'x u32
  5. }
  6. }

When set to 'deny', this will produce:

  1. error: lifetime name `'x` only used once
  2. --> src/main.rs:3:12
  3. |
  4. 3 | struct Foo<'x> {
  5. | ^^
  6. |

trivial-casts

This lint detects trivial casts which could be removed. Some example codethat triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. let x: &u32 = &42;
  4. let _ = x as *const u32;
  5. }

When set to 'deny', this will produce:

  1. error: trivial cast: `&u32` as `*const u32`. Cast can be replaced by coercion, this might require type ascription or a temporary variable
  2. --> src/main.rs:5:13
  3. |
  4. 5 | let _ = x as *const u32;
  5. | ^^^^^^^^^^^^^^^
  6. |
  7. note: lint level defined here
  8. --> src/main.rs:1:9
  9. |
  10. 1 | #![deny(trivial_casts)]
  11. | ^^^^^^^^^^^^^

trivial-numeric-casts

This lint detects trivial casts of numeric types which could be removed. Someexample code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. let x = 42i32 as i32;
  4. }

When set to 'deny', this will produce:

  1. error: trivial numeric cast: `i32` as `i32`. Cast can be replaced by coercion, this might require type ascription or a temporary variable
  2. --> src/main.rs:4:13
  3. |
  4. 4 | let x = 42i32 as i32;
  5. | ^^^^^^^^^^^^
  6. |

unreachable-pub

This lint triggers for pub items not reachable from the crate root. Someexample code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. mod foo {
  4.     pub mod bar {
  5.     }
  6. }
  7. }

When set to 'deny', this will produce:

  1. error: unreachable `pub` item
  2. --> src/main.rs:4:5
  3. |
  4. 4 | pub mod bar {
  5. | ---^^^^^^^^
  6. | |
  7. | help: consider restricting its visibility: `pub(crate)`
  8. |

unsafe-code

This lint catches usage of unsafe code. Some example code that triggers this lint:

  1. fn main() {
  2.     unsafe {
  3.     }
  4. }

When set to 'deny', this will produce:

  1. error: usage of an `unsafe` block
  2. --> src/main.rs:4:5
  3. |
  4. 4 | / unsafe {
  5. 5 | |
  6. 6 | | }
  7. | |_____^
  8. |

unstable-features

This lint is deprecated and no longer used.

unused-extern-crates

This lint guards against extern crate items that are never used. Someexample code that triggers this lint:

  1. extern crate semver;

When set to 'deny', this will produce:

  1. error: unused extern crate
  2. --> src/main.rs:3:1
  3. |
  4. 3 | extern crate semver;
  5. | ^^^^^^^^^^^^^^^^^^^^
  6. |

unused-import-braces

This lint catches unnecessary braces around an imported item. Some examplecode that triggers this lint:

  1. use test::{A};
  2. pub mod test {
  3.     pub struct A;
  4. }
  5. fn main() {}

When set to 'deny', this will produce:

  1. error: braces around A is unnecessary
  2. --> src/main.rs:3:1
  3. |
  4. 3 | use test::{A};
  5. | ^^^^^^^^^^^^^^
  6. |

To fix it, use test::A;

unused-qualifications

This lint detects unnecessarily qualified names. Some example code that triggers this lint:

  1. mod foo {
  2.     pub fn bar() {}
  3. }
  4. fn main() {
  5.     use foo::bar;
  6.     foo::bar();
  7. }

When set to 'deny', this will produce:

  1. error: unnecessary qualification
  2. --> src/main.rs:9:5
  3. |
  4. 9 | foo::bar();
  5. | ^^^^^^^^
  6. |

You can call bar() directly, without the foo::.

unused-results

This lint checks for the unused result of an expression in a statement. Someexample code that triggers this lint:

  1. fn foo<T>() -> T { panic!() }
  2. fn main() {
  3.     foo::<usize>();
  4. }

When set to 'deny', this will produce:

  1. error: unused result
  2. --> src/main.rs:6:5
  3. |
  4. 6 | foo::<usize>();
  5. | ^^^^^^^^^^^^^^^
  6. |

variant-size-differences

This lint detects enums with widely varying variant sizes. Some example code that triggers this lint:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. enum En {
  4.     V0(u8),
  5.     VBig([u8; 1024]),
  6. }
  7. }

When set to 'deny', this will produce:

  1. error: enum variant is more than three times larger (1024 bytes) than the next largest
  2. --> src/main.rs:5:5
  3. |
  4. 5 | VBig([u8; 1024]), //~ ERROR variant is more than three times larger
  5. | ^^^^^^^^^^^^^^^^
  6. |