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