Rollup merge of #89461 - crlf0710:dyn_upcasting_lint, r=nikomatsakis
Add `deref_into_dyn_supertrait` lint. Initial implementation of #89460. Resolves #89190. Maybe also worth a beta backport if necessary. r? `@nikomatsakis`
This commit is contained in:
commit
ab276b82b0
6 changed files with 168 additions and 1 deletions
|
@ -3051,6 +3051,7 @@ declare_lint_pass! {
|
|||
BREAK_WITH_LABEL_AND_LOOP,
|
||||
UNUSED_ATTRIBUTES,
|
||||
NON_EXHAUSTIVE_OMITTED_PATTERNS,
|
||||
DEREF_INTO_DYN_SUPERTRAIT,
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -3512,3 +3513,48 @@ declare_lint! {
|
|||
Allow,
|
||||
"detect when patterns of types marked `non_exhaustive` are missed",
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `deref_into_dyn_supertrait` lint is output whenever there is a use of the
|
||||
/// `Deref` implementation with a `dyn SuperTrait` type as `Output`.
|
||||
///
|
||||
/// These implementations will become shadowed when the `trait_upcasting` feature is stablized.
|
||||
/// The `deref` functions will no longer be called implicitly, so there might be behavior change.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust,compile_fail
|
||||
/// #![deny(deref_into_dyn_supertrait)]
|
||||
/// #![allow(dead_code)]
|
||||
///
|
||||
/// use core::ops::Deref;
|
||||
///
|
||||
/// trait A {}
|
||||
/// trait B: A {}
|
||||
/// impl<'a> Deref for dyn 'a + B {
|
||||
/// type Target = dyn A;
|
||||
/// fn deref(&self) -> &Self::Target {
|
||||
/// todo!()
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// fn take_a(_: &dyn A) { }
|
||||
///
|
||||
/// fn take_b(b: &dyn B) {
|
||||
/// take_a(b);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// The dyn upcasting coercion feature adds new coercion rules, taking priority
|
||||
/// over certain other coercion rules, which will cause some behavior change.
|
||||
pub DEREF_INTO_DYN_SUPERTRAIT,
|
||||
Warn,
|
||||
"`Deref` implementation usage with a supertrait trait object for output might be shadowed in the future",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>",
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue