borrowck: use subtyping instead of equality for ptr-to-ptr casts

This commit is contained in:
Lukas Markeffsky 2024-09-27 20:02:43 +02:00
parent 8302f2e35f
commit 53f45c4332
3 changed files with 2 additions and 29 deletions

View File

@ -2437,7 +2437,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
self.eq_types(
self.sub_types(
src_obj,
dst_obj,
location.to_locations(),

View File

@ -1,4 +1,4 @@
//@ check-fail
//@ check-pass
trait Trait<'a> {}
@ -37,9 +37,6 @@ fn cast_inherent_lt_wrap<'a, 'b>(
fn cast_away_higher_ranked_wrap<'a>(x: *mut dyn for<'b> Trait<'b>) -> *mut Wrapper<dyn Trait<'a>> {
x as _
//~^ error: lifetime may not live long enough
//~| error: mismatched types
//~| one type is more general than the other
}
fn unprincipled_wrap<'a, 'b>(x: *mut (dyn Send + 'a)) -> *mut Wrapper<dyn Sync + 'b> {

View File

@ -1,24 +0,0 @@
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-ok.rs:39:5
|
LL | fn cast_away_higher_ranked_wrap<'a>(x: *mut dyn for<'b> Trait<'b>) -> *mut Wrapper<dyn Trait<'a>> {
| -- lifetime `'a` defined here
LL | x as _
| ^^^^^^ returning this value requires that `'a` must outlive `'static`
|
= note: requirement occurs because of a mutable pointer to `Wrapper<dyn Trait<'_>>`
= note: mutable pointers are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error[E0308]: mismatched types
--> $DIR/ptr-to-trait-obj-ok.rs:39:5
|
LL | x as _
| ^^^^^^ one type is more general than the other
|
= note: expected trait object `dyn for<'b> Trait<'b>`
found trait object `dyn Trait<'_>`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.