Skip to content

Commit bda2851

Browse files
Rollup merge of #133358 - compiler-errors:pin-coerce, r=eholk
Don't type error if we fail to coerce `Pin<T>` because it doesnt contain a ref Fixes #133222. Also moves some tests into a directory for better bookkeeping. r? eholk or re-roll
2 parents f005c74 + 9455373 commit bda2851

14 files changed

+33
-7
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
215215
}
216216
}
217217

218-
// Examine the supertype and consider auto-borrowing.
218+
// Examine the supertype and consider type-specific coercions, such
219+
// as auto-borrowing, coercing pointer mutability, a `dyn*` coercion,
220+
// or pin-ergonomics.
219221
match *b.kind() {
220222
ty::RawPtr(_, b_mutbl) => {
221223
return self.coerce_unsafe_ptr(a, b, b_mutbl);
@@ -230,7 +232,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
230232
if self.tcx.features().pin_ergonomics()
231233
&& self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) =>
232234
{
233-
return self.coerce_pin(a, b);
235+
let pin_coerce = self.commit_if_ok(|_| self.coerce_pin_ref(a, b));
236+
if pin_coerce.is_ok() {
237+
return pin_coerce;
238+
}
234239
}
235240
_ => {}
236241
}
@@ -797,7 +802,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
797802
/// - `Pin<Box<T>>` as `Pin<&T>`
798803
/// - `Pin<Box<T>>` as `Pin<&mut T>`
799804
#[instrument(skip(self), level = "trace")]
800-
fn coerce_pin(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
805+
fn coerce_pin_ref(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
801806
// We need to make sure the two types are compatible for coercion.
802807
// Then we will build a ReborrowPin adjustment and return that as an InferOk.
803808

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ check-pass
2+
3+
#![feature(pin_ergonomics)]
4+
//~^ WARN the feature `pin_ergonomics` is incomplete
5+
6+
use std::pin::Pin;
7+
8+
fn main() {
9+
let _: Pin<Box<()>> = Box::pin(());
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `pin_ergonomics` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/coerce-non-pointer-pin.rs:3:12
3+
|
4+
LL | #![feature(pin_ergonomics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

tests/ui/async-await/pin-reborrow-const-as-mut.stderr renamed to tests/ui/async-await/pin-ergonomics/reborrow-const-as-mut.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/pin-reborrow-const-as-mut.rs:14:9
2+
--> $DIR/reborrow-const-as-mut.rs:14:9
33
|
44
LL | foo(x);
55
| --- ^ types differ in mutability
@@ -9,7 +9,7 @@ LL | foo(x);
99
= note: expected struct `Pin<&mut Foo>`
1010
found struct `Pin<&Foo>`
1111
note: function defined here
12-
--> $DIR/pin-reborrow-const-as-mut.rs:10:4
12+
--> $DIR/reborrow-const-as-mut.rs:10:4
1313
|
1414
LL | fn foo(_: Pin<&mut Foo>) {
1515
| ^^^ ----------------

tests/ui/async-await/pin-reborrow-once.stderr renamed to tests/ui/async-await/pin-ergonomics/reborrow-once.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0499]: cannot borrow `*x.__pointer` as mutable more than once at a time
2-
--> $DIR/pin-reborrow-once.rs:12:14
2+
--> $DIR/reborrow-once.rs:12:14
33
|
44
LL | twice(x, x);
55
| ----- - ^ second mutable borrow occurs here

tests/ui/async-await/pin-sugar-no-const.stderr renamed to tests/ui/async-await/pin-ergonomics/sugar-no-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected one of `!`, `(`, `::`, `;`, `<`, or `=`, found `i32`
2-
--> $DIR/pin-sugar-no-const.rs:7:18
2+
--> $DIR/sugar-no-const.rs:7:18
33
|
44
LL | let _x: &pin i32 = todo!();
55
| - ^^^ expected one of `!`, `(`, `::`, `;`, `<`, or `=`

0 commit comments

Comments
 (0)