@@ -79,7 +79,8 @@ declare_lint_pass! {
79
79
PROC_MACRO_BACK_COMPAT ,
80
80
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
81
81
PUB_USE_OF_PRIVATE_EXTERN_CRATE ,
82
- REFINING_IMPL_TRAIT ,
82
+ REFINING_IMPL_TRAIT_INTERNAL ,
83
+ REFINING_IMPL_TRAIT_REACHABLE ,
83
84
RENAMED_AND_REMOVED_LINTS ,
84
85
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ,
85
86
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES ,
@@ -4402,8 +4403,10 @@ declare_lint! {
4402
4403
}
4403
4404
4404
4405
declare_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.
4407
4410
///
4408
4411
/// ### Example
4409
4412
///
@@ -4425,21 +4428,88 @@ declare_lint! {
4425
4428
/// fn main() {
4426
4429
/// // users can observe that the return type of
4427
4430
/// // `<&str as AsDisplay>::as_display()` is `&str`.
4428
- /// let x : &str = "".as_display();
4431
+ /// let _x : &str = "".as_display();
4429
4432
/// }
4430
4433
/// ```
4431
4434
///
4432
4435
/// {{produces}}
4433
4436
///
4434
4437
/// ### Explanation
4435
4438
///
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
4438
4440
/// 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 ,
4443
4513
Warn ,
4444
4514
"impl trait in impl method signature does not match trait method signature" ,
4445
4515
}
0 commit comments