Skip to content

Compound assignment desugaring doesn't take into account autoderef #2085

@theemathas

Description

@theemathas

In the reference, compound assignment expressions with non-primitive operands are described as being desugared into method calls. That is, x += y is turned into x.add_assign(y).

This desugaring is incorrect. The += form does not do autoderef, while the .add_assign form does autoderef. For example:

use std::ops::AddAssign;
fn foo<T: AddAssign<U>, U>(x: &mut &mut T, y: U) {
    // This compiles
    x.add_assign(y);
    // This doesn't compile
    x += y;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions