about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-11-23 01:41:14 +0000
committerMichael Goulet <michael@errs.io>2024-11-23 01:41:18 +0000
commit9455373d203addf6f34fc8ee25a9ee5211314dcb (patch)
tree89a379eee6822a1659a43b4e1e6ca99b8af233e7
parentdd920fa31de604e620cb8d46710823ccacd78abe (diff)
downloadrust-9455373d203addf6f34fc8ee25a9ee5211314dcb.tar.gz
rust-9455373d203addf6f34fc8ee25a9ee5211314dcb.zip
Don't type error if we fail to coerce Pin because it doesnt contain a ref
-rw-r--r--compiler/rustc_hir_typeck/src/coercion.rs11
-rw-r--r--tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.rs10
-rw-r--r--tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.stderr11
-rw-r--r--tests/ui/async-await/pin-ergonomics/reborrow-const-as-mut.stderr4
-rw-r--r--tests/ui/async-await/pin-ergonomics/reborrow-once.stderr2
-rw-r--r--tests/ui/async-await/pin-ergonomics/sugar-no-const.stderr2
6 files changed, 33 insertions, 7 deletions
diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs
index 11e03229265..bf41dcbe4a3 100644
--- a/compiler/rustc_hir_typeck/src/coercion.rs
+++ b/compiler/rustc_hir_typeck/src/coercion.rs
@@ -215,7 +215,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
             }
         }
 
-        // Examine the supertype and consider auto-borrowing.
+        // Examine the supertype and consider type-specific coercions, such
+        // as auto-borrowing, coercing pointer mutability, a `dyn*` coercion,
+        // or pin-ergonomics.
         match *b.kind() {
             ty::RawPtr(_, b_mutbl) => {
                 return self.coerce_unsafe_ptr(a, b, b_mutbl);
@@ -230,7 +232,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
                 if self.tcx.features().pin_ergonomics()
                     && self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) =>
             {
-                return self.coerce_pin(a, b);
+                let pin_coerce = self.commit_if_ok(|_| self.coerce_pin_ref(a, b));
+                if pin_coerce.is_ok() {
+                    return pin_coerce;
+                }
             }
             _ => {}
         }
@@ -797,7 +802,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
     /// - `Pin<Box<T>>` as `Pin<&T>`
     /// - `Pin<Box<T>>` as `Pin<&mut T>`
     #[instrument(skip(self), level = "trace")]
-    fn coerce_pin(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
+    fn coerce_pin_ref(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
         // We need to make sure the two types are compatible for coercion.
         // Then we will build a ReborrowPin adjustment and return that as an InferOk.
 
diff --git a/tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.rs b/tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.rs
new file mode 100644
index 00000000000..a95665f126d
--- /dev/null
+++ b/tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.rs
@@ -0,0 +1,10 @@
+//@ check-pass
+
+#![feature(pin_ergonomics)]
+//~^ WARN the feature `pin_ergonomics` is incomplete
+
+use std::pin::Pin;
+
+fn main() {
+    let _: Pin<Box<()>> = Box::pin(());
+}
diff --git a/tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.stderr b/tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.stderr
new file mode 100644
index 00000000000..2deb5b09884
--- /dev/null
+++ b/tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.stderr
@@ -0,0 +1,11 @@
+warning: the feature `pin_ergonomics` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/coerce-non-pointer-pin.rs:3:12
+   |
+LL | #![feature(pin_ergonomics)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information
+   = note: `#[warn(incomplete_features)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/async-await/pin-ergonomics/reborrow-const-as-mut.stderr b/tests/ui/async-await/pin-ergonomics/reborrow-const-as-mut.stderr
index 2c2d9ec2717..36bbf1c493a 100644
--- a/tests/ui/async-await/pin-ergonomics/reborrow-const-as-mut.stderr
+++ b/tests/ui/async-await/pin-ergonomics/reborrow-const-as-mut.stderr
@@ -1,5 +1,5 @@
 error[E0308]: mismatched types
-  --> $DIR/pin-reborrow-const-as-mut.rs:14:9
+  --> $DIR/reborrow-const-as-mut.rs:14:9
    |
 LL |     foo(x);
    |     --- ^ types differ in mutability
@@ -9,7 +9,7 @@ LL |     foo(x);
    = note: expected struct `Pin<&mut Foo>`
               found struct `Pin<&Foo>`
 note: function defined here
-  --> $DIR/pin-reborrow-const-as-mut.rs:10:4
+  --> $DIR/reborrow-const-as-mut.rs:10:4
    |
 LL | fn foo(_: Pin<&mut Foo>) {
    |    ^^^ ----------------
diff --git a/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr b/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr
index b8fde8ffee8..a1ea2b4a57a 100644
--- a/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr
+++ b/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr
@@ -1,5 +1,5 @@
 error[E0499]: cannot borrow `*x.__pointer` as mutable more than once at a time
-  --> $DIR/pin-reborrow-once.rs:12:14
+  --> $DIR/reborrow-once.rs:12:14
    |
 LL |     twice(x, x);
    |     ----- -  ^ second mutable borrow occurs here
diff --git a/tests/ui/async-await/pin-ergonomics/sugar-no-const.stderr b/tests/ui/async-await/pin-ergonomics/sugar-no-const.stderr
index 5f01156c1f0..822cfffcb8c 100644
--- a/tests/ui/async-await/pin-ergonomics/sugar-no-const.stderr
+++ b/tests/ui/async-await/pin-ergonomics/sugar-no-const.stderr
@@ -1,5 +1,5 @@
 error: expected one of `!`, `(`, `::`, `;`, `<`, or `=`, found `i32`
-  --> $DIR/pin-sugar-no-const.rs:7:18
+  --> $DIR/sugar-no-const.rs:7:18
    |
 LL |     let _x: &pin i32 = todo!();
    |           -      ^^^ expected one of `!`, `(`, `::`, `;`, `<`, or `=`