about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Markeffsky <@>2024-09-27 20:02:43 +0200
committerLukas Markeffsky <@>2024-09-27 21:04:32 +0200
commit53f45c4332fa3703bc6866699a40df5fba2fd8ca (patch)
tree4c727347e9f2db67d4c96ee0afb514cf4913a103
parent8302f2e35fe7d9fc4cafbe2d5057775e82fc9690 (diff)
downloadrust-53f45c4332fa3703bc6866699a40df5fba2fd8ca.tar.gz
rust-53f45c4332fa3703bc6866699a40df5fba2fd8ca.zip
borrowck: use subtyping instead of equality for ptr-to-ptr casts
-rw-r--r--compiler/rustc_borrowck/src/type_check/mod.rs2
-rw-r--r--tests/ui/cast/ptr-to-trait-obj-ok.rs5
-rw-r--r--tests/ui/cast/ptr-to-trait-obj-ok.stderr24
3 files changed, 2 insertions, 29 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs
index 16e51e82f85..6b17879de26 100644
--- a/compiler/rustc_borrowck/src/type_check/mod.rs
+++ b/compiler/rustc_borrowck/src/type_check/mod.rs
@@ -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(),
diff --git a/tests/ui/cast/ptr-to-trait-obj-ok.rs b/tests/ui/cast/ptr-to-trait-obj-ok.rs
index f30472667b7..dbeee9d2944 100644
--- a/tests/ui/cast/ptr-to-trait-obj-ok.rs
+++ b/tests/ui/cast/ptr-to-trait-obj-ok.rs
@@ -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> {
diff --git a/tests/ui/cast/ptr-to-trait-obj-ok.stderr b/tests/ui/cast/ptr-to-trait-obj-ok.stderr
deleted file mode 100644
index 8de07691c21..00000000000
--- a/tests/ui/cast/ptr-to-trait-obj-ok.stderr
+++ /dev/null
@@ -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`.