Static REFINING_IMPL_TRAIT_REACHABLE
pub static REFINING_IMPL_TRAIT_REACHABLE: &'static Lint
Expand description
The refining_impl_trait_reachable
lint detects impl Trait
return
types in method signatures that are refined by a publically reachable
trait implementation, meaning the implementation adds information about
the return type that is not present in the trait.
§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
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 lead to implementation details being revealed unintentionally. In particular, it may 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.
refining_impl_trait
is a lint group composed of two lints:
refining_impl_trait_reachable
, for refinements that are publically reachable outside a crate, andrefining_impl_trait_internal
, for refinements that are only visible within a crate.
We are seeking feedback on each of these lints; see issue #121718 for more information.