forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#118026 - compiler-errors:deref-into-dyn-regions, r=lcnr Don't consider regions in `deref_into_dyn_supertrait` lint I actually wonder if we should just warn on *any* deref impl with a target type that matches a supertrait by *def-id*. cc rust-lang#89460 r? types
- Loading branch information
Showing
7 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/ui/traits/trait-upcasting/inference-behavior-change-deref.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![deny(deref_into_dyn_supertrait)] | ||
#![feature(trait_upcasting)] // remove this and the test compiles | ||
|
||
use std::ops::Deref; | ||
|
||
trait Bar<T> {} | ||
impl<T, U> Bar<U> for T {} | ||
|
||
trait Foo: Bar<i32> { | ||
fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar<u32> + 'a); | ||
} | ||
|
||
impl Foo for () { | ||
fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar<u32> + 'a) { | ||
self | ||
} | ||
} | ||
|
||
impl<'a> Deref for dyn Foo + 'a { | ||
type Target = dyn Bar<u32> + 'a; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
self.as_dyn_bar_u32() | ||
} | ||
} | ||
|
||
fn take_dyn<T>(x: &dyn Bar<T>) -> T { | ||
todo!() | ||
} | ||
|
||
fn main() { | ||
let x: &dyn Foo = &(); | ||
let y = take_dyn(x); | ||
let z: u32 = y; | ||
//~^ ERROR mismatched types | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/traits/trait-upcasting/inference-behavior-change-deref.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/inference-behavior-change-deref.rs:34:18 | ||
| | ||
LL | let z: u32 = y; | ||
| --- ^ expected `u32`, found `i32` | ||
| | | ||
| expected due to this | ||
| | ||
help: you can convert an `i32` to a `u32` and panic if the converted value doesn't fit | ||
| | ||
LL | let z: u32 = y.try_into().unwrap(); | ||
| ++++++++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
18 changes: 18 additions & 0 deletions
18
tests/ui/traits/trait-upcasting/migrate-lint-deny-regions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![deny(deref_into_dyn_supertrait)] | ||
|
||
use std::ops::Deref; | ||
|
||
trait Bar<'a> {} | ||
trait Foo<'a>: Bar<'a> {} | ||
|
||
impl<'a> Deref for dyn Foo<'a> { | ||
//~^ ERROR dyn Foo<'_>` implements `Deref` with supertrait `Bar<'_>` as target | ||
//~| WARN this will change its meaning in a future release! | ||
type Target = dyn Bar<'a>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
todo!() | ||
} | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
tests/ui/traits/trait-upcasting/migrate-lint-deny-regions.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error: `dyn Foo<'_>` implements `Deref` with supertrait `Bar<'_>` as target | ||
--> $DIR/migrate-lint-deny-regions.rs:8:1 | ||
| | ||
LL | impl<'a> Deref for dyn Foo<'a> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | type Target = dyn Bar<'a>; | ||
| -------------------------- target type is set here | ||
| | ||
= warning: this will change its meaning in a future release! | ||
= note: for more information, see issue #89460 <https://github.com/rust-lang/rust/issues/89460> | ||
note: the lint level is defined here | ||
--> $DIR/migrate-lint-deny-regions.rs:1:9 | ||
| | ||
LL | #![deny(deref_into_dyn_supertrait)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters