@@ -79,7 +79,8 @@ declare_lint_pass! {
7979 PROC_MACRO_BACK_COMPAT ,
8080 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
8181 PUB_USE_OF_PRIVATE_EXTERN_CRATE ,
82- REFINING_IMPL_TRAIT ,
82+ REFINING_IMPL_TRAIT_INTERNAL ,
83+ REFINING_IMPL_TRAIT_REACHABLE ,
8384 RENAMED_AND_REMOVED_LINTS ,
8485 REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ,
8586 RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES ,
@@ -4402,8 +4403,10 @@ declare_lint! {
44024403}
44034404
44044405declare_lint ! {
4405- /// The `refining_impl_trait` lint detects usages of return-position impl
4406- /// traits in trait signatures which are refined by implementations.
4406+ /// The `refining_impl_trait_reachable` lint detects `impl Trait` return
4407+ /// types in method signatures that are refined by a publically reachable
4408+ /// trait implementation, meaning the implementation adds information about
4409+ /// the return type that is not present in the trait.
44074410 ///
44084411 /// ### Example
44094412 ///
@@ -4425,21 +4428,88 @@ declare_lint! {
44254428 /// fn main() {
44264429 /// // users can observe that the return type of
44274430 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4428- /// let x : &str = "".as_display();
4431+ /// let _x : &str = "".as_display();
44294432 /// }
44304433 /// ```
44314434 ///
44324435 /// {{produces}}
44334436 ///
44344437 /// ### Explanation
44354438 ///
4436- /// Return-position impl trait in traits (RPITITs) desugar to associated types,
4437- /// and callers of methods for types where the implementation is known are
4439+ /// Callers of methods for types where the implementation is known are
44384440 /// able to observe the types written in the impl signature. This may be
4439- /// intended behavior, but may also pose a semver hazard for authors of libraries
4440- /// who do not wish to make stronger guarantees about the types than what is
4441- /// written in the trait signature.
4442- pub REFINING_IMPL_TRAIT ,
4441+ /// intended behavior, but may also lead to implementation details being
4442+ /// revealed unintentionally. In particular, it may pose a semver hazard
4443+ /// for authors of libraries who do not wish to make stronger guarantees
4444+ /// about the types than what is written in the trait signature.
4445+ ///
4446+ /// `refining_impl_trait` is a lint group composed of two lints:
4447+ ///
4448+ /// * `refining_impl_trait_reachable`, for refinements that are publically
4449+ /// reachable outside a crate, and
4450+ /// * `refining_impl_trait_internal`, for refinements that are only visible
4451+ /// within a crate.
4452+ ///
4453+ /// We are seeking feedback on each of these lints; see issue
4454+ /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4455+ /// information.
4456+ pub REFINING_IMPL_TRAIT_REACHABLE ,
4457+ Warn ,
4458+ "impl trait in impl method signature does not match trait method signature" ,
4459+ }
4460+
4461+ declare_lint ! {
4462+ /// The `refining_impl_trait_internal` lint detects `impl Trait` return
4463+ /// types in method signatures that are refined by a trait implementation,
4464+ /// meaning the implementation adds information about the return type that
4465+ /// is not present in the trait.
4466+ ///
4467+ /// ### Example
4468+ ///
4469+ /// ```rust,compile_fail
4470+ /// #![deny(refining_impl_trait)]
4471+ ///
4472+ /// use std::fmt::Display;
4473+ ///
4474+ /// trait AsDisplay {
4475+ /// fn as_display(&self) -> impl Display;
4476+ /// }
4477+ ///
4478+ /// impl<'s> AsDisplay for &'s str {
4479+ /// fn as_display(&self) -> Self {
4480+ /// *self
4481+ /// }
4482+ /// }
4483+ ///
4484+ /// fn main() {
4485+ /// // users can observe that the return type of
4486+ /// // `<&str as AsDisplay>::as_display()` is `&str`.
4487+ /// let _x: &str = "".as_display();
4488+ /// }
4489+ /// ```
4490+ ///
4491+ /// {{produces}}
4492+ ///
4493+ /// ### Explanation
4494+ ///
4495+ /// Callers of methods for types where the implementation is known are
4496+ /// able to observe the types written in the impl signature. This may be
4497+ /// intended behavior, but may also lead to implementation details being
4498+ /// revealed unintentionally. In particular, it may pose a semver hazard
4499+ /// for authors of libraries who do not wish to make stronger guarantees
4500+ /// about the types than what is written in the trait signature.
4501+ ///
4502+ /// `refining_impl_trait` is a lint group composed of two lints:
4503+ ///
4504+ /// * `refining_impl_trait_reachable`, for refinements that are publically
4505+ /// reachable outside a crate, and
4506+ /// * `refining_impl_trait_internal`, for refinements that are only visible
4507+ /// within a crate.
4508+ ///
4509+ /// We are seeking feedback on each of these lints; see issue
4510+ /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4511+ /// information.
4512+ pub REFINING_IMPL_TRAIT_INTERNAL ,
44434513 Warn ,
44444514 "impl trait in impl method signature does not match trait method signature" ,
44454515}
0 commit comments