1
Fork 0

allow+update deref_into_dyn_supertrait

this commit makes `deref_into_dyn_supertrait` lint allow-by-default,
removes future incompatibility (we finally live in a broken world), and
changes the wording in the documentation.

previously documentation erroneously said that it lints against *usage*
of the deref impl, while it actually (since 104742) lints on the impl
itself (oooops, my oversight, should have updated it 2+ years ago...)
This commit is contained in:
Waffle Lapkin 2025-02-06 21:57:50 +01:00
parent bc1d68e389
commit 491599569c
No known key found for this signature in database
9 changed files with 63 additions and 75 deletions

View file

@ -1,6 +1,5 @@
use rustc_hir::{self as hir, LangItem};
use rustc_middle::ty;
use rustc_session::lint::FutureIncompatibilityReason;
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::sym;
use rustc_trait_selection::traits::supertraits;
@ -9,12 +8,12 @@ use crate::lints::{SupertraitAsDerefTarget, SupertraitAsDerefTargetLabel};
use crate::{LateContext, LateLintPass, LintContext};
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`.
/// The `deref_into_dyn_supertrait` lint is emitted whenever there is a `Deref` implementation
/// for `dyn SubTrait` with a `dyn SuperTrait` type as the `Output` type.
///
/// These implementations are shadowed by the `trait_upcasting` feature (stabilized since
/// These implementations are "shadowed" by trait upcasting (stabilized since
/// CURRENT_RUSTC_VERSION). The `deref` functions is no longer called implicitly, which might
/// be behavior change compared to previous rustc versions.
/// change behavior compared to previous rustc versions.
///
/// ### Example
///
@ -44,15 +43,14 @@ declare_lint! {
///
/// ### Explanation
///
/// The dyn upcasting coercion feature added a new coercion rules, taking priority
/// over certain other coercion rules, which caused some behavior change.
/// The trait upcasting coercion added a new coercion rule, taking priority over certain other
/// coercion rules, which causes some behavior change compared to older `rustc` versions.
///
/// `deref` can be still called explicitly, it just isn't called as part of a deref coercion
/// (since trait upcasting coercion takes priority).
pub DEREF_INTO_DYN_SUPERTRAIT,
Warn,
"`Deref` implementation usage with a supertrait trait object for output is shadowed by trait upcasting",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>",
};
Allow,
"`Deref` implementation with a supertrait trait object for output is shadowed by trait upcasting",
}
declare_lint_pass!(DerefIntoDynSupertrait => [DEREF_INTO_DYN_SUPERTRAIT]);