pub static REFINING_IMPL_TRAIT: &'static Lint
Expand description

The refining_impl_trait lint detects usages of return-position impl traits in trait signatures which are refined by implementations.

§Example

#![deny(refining_impl_trait)]

use std::fmt::Display;

pub trait AsDisplay {
    fn as_display(&self) -> impl Display;
}

impl<'s> AsDisplay for &'s str {
    fn as_display(&self) -> Self {
        *self
    }
}

fn main() {
    // users can observe that the return type of
    // `<&str as AsDisplay>::as_display()` is `&str`.
    let x: &str = "".as_display();
}

{{produces}}

§Explanation

Return-position impl trait in traits (RPITITs) desugar to associated types, and callers of methods for types where the implementation is known are able to observe the types written in the impl signature. This may be intended behavior, but may also pose a semver hazard for authors of libraries who do not wish to make stronger guarantees about the types than what is written in the trait signature.