Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using struct update syntax, permission for the source struct variable seem off #129

Open
phdye opened this issue Mar 7, 2024 · 1 comment
Labels
bug Something isn't working permissions

Comments

@phdye
Copy link

phdye commented Mar 7, 2024

Line: let b = User { age: 1, ..a };
Shows permissions for "..a" as no-read (orange circle empty) and not owner (red-circle empty). At that point, would not a still be the owner and also have read access?

Or am I interpreting the empty circles incorrectly and, if so, are they documented somewhere that I have missed?

Thanks

struct User {
    name : String,
    age : i32,
}

fn main() {
    let mut a = User { name: String::from("Jeff"), age: 2 };
    a.age += 1;
    let b = User { age: 1, ..a };
    a.age += 1;
    println!("{} {}", b.name, b.age);
}
@gavinleroy
Copy link
Collaborator

An empty circle is best interpreted as "the read (R) permission is required, but it's missing." Exchange "read" for "write" or "own" depending on which color it is. The circles also expand to the permission character if you hover over them. The most thorough explanation of the diagrams is our chapter on References and Borrowing.

However, the code provided does show a bug! We didn't have a test for struct update syntax and it's showing the permissions on a after the move, not before :(

@gavinleroy gavinleroy added bug Something isn't working permissions labels Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working permissions
Projects
None yet
Development

No branches or pull requests

2 participants