Skip to content

Lifetime issues: assigning to a mutable reference with part of its current value #72477

Open
@Ekleog

Description

@Ekleog

Edit: simplified reproducer as well as workaround available at #72477 (comment)

Hello,

While trying to implement an AsyncRead wrapper, I have hit something that I think is the borrow-checker being too restrictive with &mut inside Pin.

I originally thought it was an issue in pin-project, but @taiki-e pointed out that the issue also happens with raw Pin, in taiki-e/pin-project#226 (comment) (thank you!)

Copying the example here (with an explicit lifetime):

pub struct Foo<'a> {
    buf: &'a mut [u8],
}

impl<'a> Foo<'a> {
    fn foo<'b>(self: std::pin::Pin<&'b mut Self>) {
        self.buf = &mut self.buf[1..];
    }
}

(playground)

This is potentially related to #54934 ; but seeing as it manifests in a completely different way (ie. it doesn't manifest with just & references in the original example with pin-project linked above, though the example code here is incorrect indeed), I thought it'd be better to open another issue, as at worst it'd be fixed at the same time as #54934 and would just add another test.

As usual, thank you for all you do on this great language!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions