- Allowed-by-default lints
- anonymous-parameters
- bare-trait-object
- box-pointers
- elided-lifetime-in-path
- missing-copy-implementations
- missing-debug-implementations
- missing-docs
- single-use-lifetimes
- trivial-casts
- trivial-numeric-casts
- unreachable-pub
- unsafe-code
- unstable-features
- unused-extern-crates
- unused-import-braces
- unused-qualifications
- unused-results
- variant-size-differences
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
trait Foo {
```
5. ```
fn foo(usize);
```
6. ```
}
```
7. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
trait Foo {
```
5. ```
fn foo(_: usize);
```
6. ```
}
```
7. ```
}
```
bare-trait-object
This lint suggests using dyn Trait for trait objects. Some example codethat triggers this lint:
2. ```
#![allow(unused_variables)]
```
3. ```
#![feature(dyn_trait)]
```
5. ```
fn main() {
```
6. ```
trait Trait { }
```
8. ```
fn takes_trait_object(_: Box<Trait>) {
```
9. ```
}
```
10. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
#![feature(dyn_trait)]
```
4. ```
#![deny(bare_trait_objects)]
```
6. ```
fn main() {
```
7. ```
trait Trait { }
```
9. ```
fn takes_trait_object(_: Box<dyn Trait>) {
```
10. ```
}
```
11. ```
}
```
box-pointers
This lints use of the Box type. Some example code that triggers this lint:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
struct Foo {
```
5. ```
x: Box<isize>,
```
6. ```
}
```
7. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
struct Foo<'a> {
```
5. ```
x: &'a u32
```
6. ```
}
```
8. ```
fn foo(x: &Foo) {
```
9. ```
}
```
10. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
pub struct Foo {
```
5. ```
pub field: i32
```
6. ```
}
```
7. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
pub struct Foo;
```
5. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
pub fn foo() {}
```
5. ```
}
```
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. |
12. error: missing documentation for a function
13. --> src/main.rs:3:1
14. |
15. 3 | pub fn foo() {}
16. | ^^^^^^^^^^^^
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
struct Foo<'x> {
```
5. ```
x: &'x u32
```
6. ```
}
```
7. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
let x: &u32 = &42;
```
5. ```
let _ = x as *const u32;
```
6. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
let x = 42i32 as i32;
```
5. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
mod foo {
```
5. ```
pub mod bar {
```
7. ```
}
```
8. ```
}
```
9. ```
}
```
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 {
```
4. ```
}
```
5. ```
}
```
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};
```
3. ```
pub mod test {
```
4. ```
pub struct A;
```
5. ```
}
```
6. ```
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. ```
}
```
5. ```
fn main() {
```
6. ```
use foo::bar;
```
7. ```
foo::bar();
```
8. ```
}
```
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!() }
```
3. ```
fn main() {
```
4. ```
foo::<usize>();
```
5. ```
}
```
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:
2. ```
#![allow(unused_variables)]
```
3. ```
fn main() {
```
4. ```
enum En {
```
5. ```
V0(u8),
```
6. ```
VBig([u8; 1024]),
```
7. ```
}
```
8. ```
}
```
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. |
