Skip to content

Borrowck doesn't propagate mutability to supercomponents correctly #3828

Description

@nikomatsakis

Borrowck doesn't always propagate mutability correctly to base components.

Here is an example:

struct Foo {
    x: uint
}

struct Bar {
    foo: Foo
}

fn main() {
    let mut b = Bar { foo: Foo { x: 3 } };
    let p = &b;
    let q = &mut b.foo.x;
    let r = &p.foo.x;
    io::println(fmt!("*r = %u", *r));
    *q += 1;
    io::println(fmt!("*r = %u", *r));
}

Here, r has type &uint and thus *r should always yield the same result. The problem is that when creating the loan for &mut we propagate &const as the required type for base loans. This causes us to miss the conflict.

I have a fix for this already prepared.

Activity

  1. added a commit that references this issue on Aug 22, 2024
  2. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions