Don't type error if we fail to coerce Pin because it doesnt contain a ref

This commit is contained in:
Michael Goulet 2024-11-23 01:41:14 +00:00
parent dd920fa31d
commit 9455373d20
6 changed files with 33 additions and 7 deletions

View file

@ -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.

View file

@ -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(());
}

View file

@ -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

View file

@ -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>) {
| ^^^ ----------------

View file

@ -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

View file

@ -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 `=`