@@ -77,7 +77,8 @@ declare_lint_pass! {
7777 PROC_MACRO_BACK_COMPAT ,
7878 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
7979 PUB_USE_OF_PRIVATE_EXTERN_CRATE ,
80- REFINING_IMPL_TRAIT ,
80+ REFINING_IMPL_TRAIT_INTERNAL ,
81+ REFINING_IMPL_TRAIT_REACHABLE ,
8182 RENAMED_AND_REMOVED_LINTS ,
8283 REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ,
8384 RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES ,
@@ -4310,8 +4311,10 @@ declare_lint! {
43104311}
43114312
43124313declare_lint ! {
4313- /// The `refining_impl_trait` lint detects usages of return-position impl
4314- /// traits in trait signatures which are refined by implementations.
4314+ /// The `refining_impl_trait_reachable` lint detects `impl Trait` return
4315+ /// types in method signatures that are refined by a publically reachable
4316+ /// trait implementation, meaning the implementation adds information about
4317+ /// the return type that is not present in the trait.
43154318 ///
43164319 /// ### Example
43174320 ///
@@ -4333,21 +4336,88 @@ declare_lint! {
43334336 /// fn main() {
43344337 /// // users can observe that the return type of
43354338 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4336- /// let x : &str = "".as_display();
4339+ /// let _x : &str = "".as_display();
43374340 /// }
43384341 /// ```
43394342 ///
43404343 /// {{produces}}
43414344 ///
43424345 /// ### Explanation
43434346 ///
4344- /// Return-position impl trait in traits (RPITITs) desugar to associated types,
4345- /// and callers of methods for types where the implementation is known are
4347+ /// Callers of methods for types where the implementation is known are
43464348 /// able to observe the types written in the impl signature. This may be
4347- /// intended behavior, but may also pose a semver hazard for authors of libraries
4348- /// who do not wish to make stronger guarantees about the types than what is
4349- /// written in the trait signature.
4350- pub REFINING_IMPL_TRAIT ,
4349+ /// intended behavior, but may also lead to implementation details being
4350+ /// revealed unintentionally. In particular, it may pose a semver hazard
4351+ /// for authors of libraries who do not wish to make stronger guarantees
4352+ /// about the types than what is written in the trait signature.
4353+ ///
4354+ /// `refining_impl_trait` is a lint group composed of two lints:
4355+ ///
4356+ /// * `refining_impl_trait_reachable`, for refinements that are publically
4357+ /// reachable outside a crate, and
4358+ /// * `refining_impl_trait_internal`, for refinements that are only visible
4359+ /// within a crate.
4360+ ///
4361+ /// We are seeking feedback on each of these lints; see issue
4362+ /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4363+ /// information.
4364+ pub REFINING_IMPL_TRAIT_REACHABLE ,
4365+ Warn ,
4366+ "impl trait in impl method signature does not match trait method signature" ,
4367+ }
4368+
4369+ declare_lint ! {
4370+ /// The `refining_impl_trait_internal` lint detects `impl Trait` return
4371+ /// types in method signatures that are refined by a trait implementation,
4372+ /// meaning the implementation adds information about the return type that
4373+ /// is not present in the trait.
4374+ ///
4375+ /// ### Example
4376+ ///
4377+ /// ```rust,compile_fail
4378+ /// #![deny(refining_impl_trait)]
4379+ ///
4380+ /// use std::fmt::Display;
4381+ ///
4382+ /// trait AsDisplay {
4383+ /// fn as_display(&self) -> impl Display;
4384+ /// }
4385+ ///
4386+ /// impl<'s> AsDisplay for &'s str {
4387+ /// fn as_display(&self) -> Self {
4388+ /// *self
4389+ /// }
4390+ /// }
4391+ ///
4392+ /// fn main() {
4393+ /// // users can observe that the return type of
4394+ /// // `<&str as AsDisplay>::as_display()` is `&str`.
4395+ /// let _x: &str = "".as_display();
4396+ /// }
4397+ /// ```
4398+ ///
4399+ /// {{produces}}
4400+ ///
4401+ /// ### Explanation
4402+ ///
4403+ /// Callers of methods for types where the implementation is known are
4404+ /// able to observe the types written in the impl signature. This may be
4405+ /// intended behavior, but may also lead to implementation details being
4406+ /// revealed unintentionally. In particular, it may pose a semver hazard
4407+ /// for authors of libraries who do not wish to make stronger guarantees
4408+ /// about the types than what is written in the trait signature.
4409+ ///
4410+ /// `refining_impl_trait` is a lint group composed of two lints:
4411+ ///
4412+ /// * `refining_impl_trait_reachable`, for refinements that are publically
4413+ /// reachable outside a crate, and
4414+ /// * `refining_impl_trait_internal`, for refinements that are only visible
4415+ /// within a crate.
4416+ ///
4417+ /// We are seeking feedback on each of these lints; see issue
4418+ /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4419+ /// information.
4420+ pub REFINING_IMPL_TRAIT_INTERNAL ,
43514421 Warn ,
43524422 "impl trait in impl method signature does not match trait method signature" ,
43534423}
0 commit comments