@@ -77,7 +77,8 @@ declare_lint_pass! {
77
77
PROC_MACRO_BACK_COMPAT ,
78
78
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
79
79
PUB_USE_OF_PRIVATE_EXTERN_CRATE ,
80
- REFINING_IMPL_TRAIT ,
80
+ REFINING_IMPL_TRAIT_INTERNAL ,
81
+ REFINING_IMPL_TRAIT_REACHABLE ,
81
82
RENAMED_AND_REMOVED_LINTS ,
82
83
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ,
83
84
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES ,
@@ -4310,8 +4311,10 @@ declare_lint! {
4310
4311
}
4311
4312
4312
4313
declare_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.
4315
4318
///
4316
4319
/// ### Example
4317
4320
///
@@ -4333,21 +4336,88 @@ declare_lint! {
4333
4336
/// fn main() {
4334
4337
/// // users can observe that the return type of
4335
4338
/// // `<&str as AsDisplay>::as_display()` is `&str`.
4336
- /// let x : &str = "".as_display();
4339
+ /// let _x : &str = "".as_display();
4337
4340
/// }
4338
4341
/// ```
4339
4342
///
4340
4343
/// {{produces}}
4341
4344
///
4342
4345
/// ### Explanation
4343
4346
///
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
4346
4348
/// 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 ,
4351
4421
Warn ,
4352
4422
"impl trait in impl method signature does not match trait method signature" ,
4353
4423
}
0 commit comments