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

pin_ergonomics leads to bizarre "expected Pin<X> found Pin<X>" type errors #133222

Open
yotamofek opened this issue Nov 19, 2024 · 4 comments
Open
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions C-bug Category: This is a bug. F-pin_ergonomics `#![feature(pin_ergonomics)]` requires-incomplete-features This issue requires the use of incomplete features. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@yotamofek
Copy link
Contributor

I know pin_ergonomics is in very early stages, but I was eager to try it out and ran into this somewhat fundamental issue.
cc #130494

I tried this code:

#![feature(pin_ergonomics)]

use std::pin::Pin;

pub fn foo() {
    let _: Pin<Box<()>> = Box::pin(());
}

I expected to see this happen: should compile

Instead, this happened: got a compilation error


error[E0308]: mismatched types
 --> src/lib.rs:6:27
  |
6 |     let _: Pin<Box<()>> = Box::pin(());
  |                           ^^^^^^^^^^^^ types differ
  |
  = note: expected struct `Pin<_>`
             found struct `Pin<_>`

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (f2a35426b 2024-11-16)
binary: rustc
commit-hash: f2a35426b6586178c44b27cedae182502092e898
commit-date: 2024-11-16
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3
@yotamofek yotamofek added the C-bug Category: This is a bug. label Nov 19, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 19, 2024
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-pin_ergonomics `#![feature(pin_ergonomics)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 19, 2024
@fmease
Copy link
Member

fmease commented Nov 19, 2024

Conceptually simpler reproducer:

#![feature(pin_ergonomics)]
fn mk() -> std::pin::Pin<()> { loop {} }

rustc file.rs --crate-type=lib -Zverbose-internals -Ztrim-diagnostic-paths=no -Aincomplete-features:

error[E0308]: mismatched types
 --> file.rs:2:32
  |
2 | fn mk() -> std::pin::Pin<()> { loop {} }
  |                                ^^^^^^^ types differ
  |
  = note: expected struct `std::pin::Pin<()>`
             found struct `std::pin::Pin<()>`

@fmease
Copy link
Member

fmease commented Nov 19, 2024

And less artificial:

#![feature(pin_ergonomics)]

struct X;
impl std::ops::Deref for X { type Target = u32; fn deref(&self) -> &Self::Target { &0 } }

fn main() {
    let _: std::pin::Pin<X> = std::pin::Pin::new(X);
}

rustc file.rs -Zverbose-internals -Ztrim-diagnostic-paths=no -Aincomplete-features:

error[E0308]: mismatched types
 --> file.rs:8:31
  |
8 |     let _: std::pin::Pin<X> = std::pin::Pin::new(X);
  |                               ^^^^^^^^^^^^^^^^^^^^^ types differ
  |
  = note: expected struct `std::pin::Pin<X>`
             found struct `std::pin::Pin<X>`

@fmease fmease changed the title pin_ergonomics feature breaks Box::pin pin_ergonomics leads to bizzare expected X found X type errors Nov 19, 2024
@fmease fmease changed the title pin_ergonomics leads to bizzare expected X found X type errors pin_ergonomics leads to bizarre expected X found X type errors Nov 19, 2024
@fmease fmease changed the title pin_ergonomics leads to bizarre expected X found X type errors pin_ergonomics leads to bizarre expected Pin<X> found Pin<X> type errors Nov 19, 2024
@fmease fmease added the requires-incomplete-features This issue requires the use of incomplete features. label Nov 19, 2024
@fmease
Copy link
Member

fmease commented Nov 20, 2024

Possibly due to the following:

Err(TypeError::Mismatch)


Where Coercible(Pin<X>, Pin<Y>) always results in a TypeMismatch if X and Y are not of the form &[mut] Xp and &[mut] Yp respectively even if Coercible(X, Y). For context, this happens in extract_pin_mut inside coerce_pin inside coerce. Rephrased, the coercion fails if extract_pin_mut fails to find a "coercion candidate" (Pin<&[mut] _>) which is the case in all three reproducers given above.

@fmease fmease added the A-coercions Area: implicit and explicit `expr as Type` coercions label Nov 20, 2024
@fmease
Copy link
Member

fmease commented Nov 20, 2024

cc @eholk

@fmease fmease changed the title pin_ergonomics leads to bizarre expected Pin<X> found Pin<X> type errors pin_ergonomics leads to bizarre "expected Pin<X> found Pin<X>" type errors Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions C-bug Category: This is a bug. F-pin_ergonomics `#![feature(pin_ergonomics)]` requires-incomplete-features This issue requires the use of incomplete features. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants