Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't type error if we fail to coerce Pin<T> because it doesnt contain a ref #133358

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
_ => {}
}
Expand Down Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.rs
Original file line number Diff line number Diff line change
@@ -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(());
}
11 changes: 11 additions & 0 deletions tests/ui/async-await/pin-ergonomics/coerce-non-pointer-pin.stderr
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>) {
| ^^^ ----------------
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 `=`
Expand Down
Loading