rustc_lint::builtin

Static TRIVIAL_CASTS

pub static TRIVIAL_CASTS: &'static Lint
Expand description

The trivial_casts lint detects trivial casts which could be replaced with coercion, which may require a temporary variable.

§Example

#![deny(trivial_casts)]
let x: &u32 = &42;
let y = x as *const u32;

{{produces}}

§Explanation

A trivial cast is a cast e as T where e has type U and U is a subtype of T. This type of cast is usually unnecessary, as it can be usually be inferred.

This lint is “allow” by default because there are situations, such as with FFI interfaces or complex type aliases, where it triggers incorrectly, or in situations where it will be more difficult to clearly express the intent. It may be possible that this will become a warning in the future, possibly with an explicit syntax for coercions providing a convenient way to work around the current issues. See RFC 401 (coercions), RFC 803 (type ascription) and RFC 3307 (remove type ascription) for historical context.