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

Chapter 4.3: Access Descriptor Issue + Missing Clarifications on Suggested Bug Fix #223

Open
Tinku10 opened this issue Nov 9, 2024 · 1 comment

Comments

@Tinku10
Copy link

Tinku10 commented Nov 9, 2024

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • 4.3
    • Chapter 4
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • /ch04-03-fixing-ownership-errors.md

I am completely new to Rust and started going through the book just 2-3 days ago. Sorry if I have incorrectly pointed out anything here.

URL to the section(s) of the book with this problem: https://rust-book.cs.brown.edu/ch04-03-fixing-ownership-errors.html#fixing-an-unsafe-program-copying-vs-moving-out-of-a-collection

Description of the problem: The diagram tells us that v has lost Read access, which in reality it should not.

Suggested fix: Mark v with R

image

Apart from this, I think the section Fixing an Unsafe Program: Not Enough Permissions does not take into account the previously linked main function for the suggested solutions.

Here is the described main function.

fn stringify_name_with_title(name: &Vec<String>) -> String {
    name.push(String::from("Esq."));`{}`
    let full = name.join(" ");
    full
}

fn main() {
    let name = vec![String::from("Ferris")];
    let first = &name[0];
    stringify_name_with_title(&name);
    println!("{}", first);
}

The first suggested fix mutates the name rending the access of first in main problematic.

fn stringify_name_with_title(name: &mut Vec<String>) -> String {
    name.push(String::from("Esq."));
    let full = name.join(" ");
    full
}

The second solution moves the name causing the same problem.

fn stringify_name_with_title(mut name: Vec<String>) -> String {
    name.push(String::from("Esq."));
    let full = name.join(" ");
    full
}
@willcrichton
Copy link
Collaborator

Noting that is another instance of cognitive-engineering-lab/aquascope#85.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants