Skip to content

Commit 4915995

Browse files
committed
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...)
1 parent bc1d68e commit 4915995

9 files changed

+63
-75
lines changed

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_hir::{self as hir, LangItem};
22
use rustc_middle::ty;
3-
use rustc_session::lint::FutureIncompatibilityReason;
43
use rustc_session::{declare_lint, declare_lint_pass};
54
use rustc_span::sym;
65
use rustc_trait_selection::traits::supertraits;
@@ -9,12 +8,12 @@ use crate::lints::{SupertraitAsDerefTarget, SupertraitAsDerefTargetLabel};
98
use crate::{LateContext, LateLintPass, LintContext};
109

1110
declare_lint! {
12-
/// The `deref_into_dyn_supertrait` lint is output whenever there is a use of the
13-
/// `Deref` implementation with a `dyn SuperTrait` type as `Output`.
11+
/// The `deref_into_dyn_supertrait` lint is emitted whenever there is a `Deref` implementation
12+
/// for `dyn SubTrait` with a `dyn SuperTrait` type as the `Output` type.
1413
///
15-
/// These implementations are shadowed by the `trait_upcasting` feature (stabilized since
14+
/// These implementations are "shadowed" by trait upcasting (stabilized since
1615
/// CURRENT_RUSTC_VERSION). The `deref` functions is no longer called implicitly, which might
17-
/// be behavior change compared to previous rustc versions.
16+
/// change behavior compared to previous rustc versions.
1817
///
1918
/// ### Example
2019
///
@@ -44,15 +43,14 @@ declare_lint! {
4443
///
4544
/// ### Explanation
4645
///
47-
/// The dyn upcasting coercion feature added a new coercion rules, taking priority
48-
/// over certain other coercion rules, which caused some behavior change.
46+
/// The trait upcasting coercion added a new coercion rule, taking priority over certain other
47+
/// coercion rules, which causes some behavior change compared to older `rustc` versions.
48+
///
49+
/// `deref` can be still called explicitly, it just isn't called as part of a deref coercion
50+
/// (since trait upcasting coercion takes priority).
4951
pub DEREF_INTO_DYN_SUPERTRAIT,
50-
Warn,
51-
"`Deref` implementation usage with a supertrait trait object for output is shadowed by trait upcasting",
52-
@future_incompatible = FutureIncompatibleInfo {
53-
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
54-
reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>",
55-
};
52+
Allow,
53+
"`Deref` implementation with a supertrait trait object for output is shadowed by trait upcasting",
5654
}
5755

5856
declare_lint_pass!(DerefIntoDynSupertrait => [DEREF_INTO_DYN_SUPERTRAIT]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ check-pass
2+
#![warn(deref_into_dyn_supertrait)]
3+
use std::ops::Deref;
4+
5+
trait Bar<T> {}
6+
trait Foo: Bar<i32> {}
7+
8+
impl<'a> Deref for dyn Foo + 'a {
9+
//~^ warn: this `Deref` implementation is covered by an implicit supertrait coercion
10+
type Target = dyn Bar<u32> + 'a;
11+
12+
fn deref(&self) -> &Self::Target {
13+
todo!()
14+
}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: this `Deref` implementation is covered by an implicit supertrait coercion
2+
--> $DIR/deref-upcast-shadowing-lint.rs:8:1
3+
|
4+
LL | impl<'a> Deref for dyn Foo + 'a {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Foo` implements `Deref<Target = dyn Bar<u32>>` which conflicts with supertrait `Bar<i32>`
6+
LL |
7+
LL | type Target = dyn Bar<u32> + 'a;
8+
| -------------------------------- target type is a supertrait of `dyn Foo`
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/deref-upcast-shadowing-lint.rs:2:9
12+
|
13+
LL | #![warn(deref_into_dyn_supertrait)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
16+
warning: 1 warning emitted
17+

tests/ui/traits/trait-upcasting/migrate-lint-deny-regions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#![deny(deref_into_dyn_supertrait)]
1+
//@ check-pass
2+
#![warn(deref_into_dyn_supertrait)]
23

34
use std::ops::Deref;
45

56
trait Bar<'a> {}
67
trait Foo<'a>: Bar<'a> {}
78

89
impl<'a> Deref for dyn Foo<'a> {
9-
//~^ ERROR this `Deref` implementation is covered by an implicit supertrait coercion
10-
//~| WARN this will change its meaning in a future release!
10+
//~^ warn: this `Deref` implementation is covered by an implicit supertrait coercion
1111
type Target = dyn Bar<'a>;
1212

1313
fn deref(&self) -> &Self::Target {
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
error: this `Deref` implementation is covered by an implicit supertrait coercion
2-
--> $DIR/migrate-lint-deny-regions.rs:8:1
1+
warning: this `Deref` implementation is covered by an implicit supertrait coercion
2+
--> $DIR/migrate-lint-deny-regions.rs:9:1
33
|
44
LL | impl<'a> Deref for dyn Foo<'a> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Foo<'_>` implements `Deref<Target = dyn Bar<'_>>` which conflicts with supertrait `Bar<'_>`
6-
...
6+
LL |
77
LL | type Target = dyn Bar<'a>;
88
| -------------------------- target type is a supertrait of `dyn Foo<'_>`
99
|
10-
= warning: this will change its meaning in a future release!
11-
= note: for more information, see issue #89460 <https://github.com/rust-lang/rust/issues/89460>
1210
note: the lint level is defined here
13-
--> $DIR/migrate-lint-deny-regions.rs:1:9
11+
--> $DIR/migrate-lint-deny-regions.rs:2:9
1412
|
15-
LL | #![deny(deref_into_dyn_supertrait)]
13+
LL | #![warn(deref_into_dyn_supertrait)]
1614
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1715

18-
error: aborting due to 1 previous error
16+
warning: 1 warning emitted
1917

tests/ui/traits/trait-upcasting/migrate-lint-deny.rs

-25
This file was deleted.

tests/ui/traits/trait-upcasting/migrate-lint-deny.stderr

-19
This file was deleted.

tests/ui/traits/trait-upcasting/migrate-lint-different-substs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ check-pass
2+
#![warn(deref_into_dyn_supertrait)]
23

34
use std::ops::Deref;
45

@@ -9,8 +10,7 @@ trait Foo: Bar<i32> {
910
}
1011

1112
impl<'a> Deref for dyn Foo + 'a {
12-
//~^ WARN this `Deref` implementation is covered by an implicit supertrait coercion
13-
//~| WARN this will change its meaning in a future release!
13+
//~^ warn: this `Deref` implementation is covered by an implicit supertrait coercion
1414
type Target = dyn Bar<u32> + 'a;
1515

1616
fn deref(&self) -> &Self::Target {
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
warning: this `Deref` implementation is covered by an implicit supertrait coercion
2-
--> $DIR/migrate-lint-different-substs.rs:11:1
2+
--> $DIR/migrate-lint-different-substs.rs:12:1
33
|
44
LL | impl<'a> Deref for dyn Foo + 'a {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Foo` implements `Deref<Target = dyn Bar<u32>>` which conflicts with supertrait `Bar<i32>`
6-
...
6+
LL |
77
LL | type Target = dyn Bar<u32> + 'a;
88
| -------------------------------- target type is a supertrait of `dyn Foo`
99
|
10-
= warning: this will change its meaning in a future release!
11-
= note: for more information, see issue #89460 <https://github.com/rust-lang/rust/issues/89460>
12-
= note: `#[warn(deref_into_dyn_supertrait)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/migrate-lint-different-substs.rs:2:9
12+
|
13+
LL | #![warn(deref_into_dyn_supertrait)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1315

1416
warning: 1 warning emitted
1517

0 commit comments

Comments
 (0)