Skip to content

Error in derived PartialOrd impl on structs with mut reference fields #43816

@arkeet

Description

@arkeet

This fails to compile, with a rather cryptic error message: [playground]

#[derive(PartialEq, PartialOrd)]
struct Bad<'a>(&'a mut u8);

This is one of the errors in the expanded code (the rest are similar):

// error[E0389]: cannot borrow data mutably in a `&` reference
fn lt(&self, __arg_0: &Bad<'a>) -> bool {
    match *__arg_0 {
        Bad(ref __self_1_0) =>
//          -------------- consider changing this to `ref mut __self_1_0`
        match *self {
            Bad(ref __self_0_0) =>
            (*__self_0_0) < (*__self_1_0) ||
//                          ^^^^^^^^^^^^^ assignment into an immutable reference
                !((*__self_1_0) < (*__self_0_0)) && false,
        },
    }
}

Seems quite similar to #15689.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API 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