Skip to main content

## METHOD_CALL_ON_DIVERGING_INFER_VAR

# Static METHOD_CALL_ON_DIVERGING_INFER_VAR

Source

    pub static METHOD_CALL_ON_DIVERGING_INFER_VAR: &Lint

Expand description

The `method_call_on_diverging_infer_var` lint detects situations in which a method is called on a value resulting from a never-to-any coercion, without necessary information to infer a type for it.

#### §Example

     fn main() {
         let x = panic!();
         x.clone();
     }

{{produces}}

#### §Explanation

Rust does not generally allow calling methods on values which do not have a known type, such a result of a never-to-any coercion with no type specified.

To aid with transition of code calling methods on `Infallible` after changing `Infallible` to be an alias for `!`, rustc temporarily allows such calls. This will (once again) become an error in the future.

Thanks to never-to-any coercion you can replace method calls on `!` with the use of the `!` variable, or an `as` cast to an explicit type:

    - x.clone()
    + x

    - result.map(|x| x.convert_error())?;
    + result.map(|x| x as ErrorType)?;