Skip to content

&pin!() stopped being deref-coerced in rust 1.88 #153425

@theemathas

Description

@theemathas

I expected the following code to compile, since Pin implements Deref, so it should be possible to do a deref coercion from the type &Pin<i32> to the type &i32.

fn main() {
    let _x: &i32 = &std::pin::pin!(1i32);
}

The above code compiles without errors in rust 1.87.0. However, it produces the following compile error in rust 1.88.0

error[E0308]: mismatched types
 --> <source>:2:21
  |
2 |     let _x: &i32 = &std::pin::pin!(1i32);
  |                     ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `Pin<&mut i32>`
  |
  = note: expected type `i32`
           found struct `Pin<&mut i32>`
  = note: this error originates in the macro `std::pin::pin` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

This presumably regressed in #139114, which changed pin!() to use super let. This uses a block expression in the syntax, which then presumably runs into the bug in #23014.

I don't know if there are any realistic use cases which run into this problem. (Hopefully not.)

cc @dianne @m-ou-se (who worked on super let).

cc @jackh726 (who seemed to have recently been working on coercions).

Meta

Tested on Godbolt with rustc versions 1.87.0 and 1.88.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coercionsArea: implicit and explicit `expr as Type` coercionsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-pinArea: PinC-bugCategory: This is a bug.F-super_letit's super, let's go!P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions