rustc_lint::builtin

Static PATTERNS_IN_FNS_WITHOUT_BODY

Source
pub static PATTERNS_IN_FNS_WITHOUT_BODY: &'static Lint
Expand description

The patterns_in_fns_without_body lint detects mut identifier patterns as a parameter in functions without a body.

§Example

trait Trait {
    fn foo(mut arg: u8);
}

{{produces}}

§Explanation

To fix this, remove mut from the parameter in the trait definition; it can be used in the implementation. That is, the following is OK:

trait Trait {
    fn foo(arg: u8); // Removed `mut` here
}

impl Trait for i32 {
    fn foo(mut arg: u8) { // `mut` here is OK

    }
}

Trait definitions can define functions without a body to specify a function that implementors must define. The parameter names in the body-less functions are only allowed to be _ or an identifier for documentation purposes (only the type is relevant). Previous versions of the compiler erroneously allowed identifier patterns with the mut keyword, but this was not intended to be allowed. This is a future-incompatible lint to transition this to a hard error in the future. See issue #35203 for more details.