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

Fix wording on the aliasing section #366

Merged
merged 2 commits into from
Jun 24, 2022
Merged

Conversation

JohnTitor
Copy link
Member

It should've said "the value of a local variable cannot alias
things...".

Fixes #362

@JohnTitor JohnTitor requested a review from a team May 29, 2022 11:31
@ehuss
Copy link
Contributor

ehuss commented May 29, 2022

I've read this over several times, and I'm not clear on this.

The original says: "the value of a local variable can't be aliased by things that existed before it was declared" which I read to be true. The local variable can't be aliased before it is declared because it doesn't exist, yet. There is nothing to alias. That is:

fn compute(input: &u32, output: &mut u32) {
    // Up to this point, nothing can alias `temp` because `temp` doesn't exist, yet.
    let mut temp = *output;
    if *input > 10 {
        temp = 1;
    }
    if *input > 5 {
        temp *= 2;
    }
    *output = temp;
}

The new version says: "the value of a local variable cannot alias things that existed before it was declared."
This doesn't seem correct to me because local variables can be created which alias things before their declaration.

fn f(a: &str) {
    let b = a;  // local variable `b` created an alias of `a`
}

Can you help me understand the proposed correction?

@JohnTitor
Copy link
Member Author

Thanks for pointing out, hmm, I was confused then. So, we should say "We're still relying on alias analysis to assume that input doesn't alias temp" instead, right?

It should've said "the value of a local variable cannot alias
things...".
@JohnTitor
Copy link
Member Author

Friendly-ping @ehuss it'd be great if you could take another look :)

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to go ahead and approve, though I'm not sure swapping the terms matters much. I would think that aliasing is symmetric (if foo aliases bar, then bar aliases foo).

@ehuss ehuss merged commit 155ea82 into rust-lang:master Jun 24, 2022
@JohnTitor JohnTitor deleted the tweak-aliasing branch June 24, 2022 23:13
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 5, 2022
Update books

## nomicon

2 commits in 3a43983b76174342b7dbd3e12ea2c49f762e52be..70db9e4189f64d1d8e2451b1046111fb356b6dc2
2022-05-30 17:01:30 +0900 to 2022-06-27 20:47:21 +0900
- should be `size_of` instead of `align_of` (rust-lang/nomicon#371)
- Fix wording on the aliasing section (rust-lang/nomicon#366)

## book

20 commits in efbafdba3618487fbc9305318fcab9775132ac15..cf2653a5ca553cbbb4a17f1a7db1947820f6a775
2022-06-19 21:06:50 -0400 to 2022-07-05 12:07:58 -0400
- Frontmatter
- Update to Rust 1.62
- Extract where clause example so it'll get rustfmtted in the future
- Merge remote-tracking branch 'origin/pr/3238' into extract-where-clause-example
- Fix line wrapping of lib placement fix
- Fix grammar, spelling, and line wrapping of description of appendices
- Merge remote-tracking branch 'origin/pr/3244' into binlib
- Clarify *type* parameter names
- Fix listing 8-21. Fixes rust-lang/book#3251
- Propagate tech review changes for ch13
- Responses to tech review of chapter 13
- Tech review comments on chapter 13
- Fix double the
- Propagate tech review chapter 1 changes to src
- Address tech review comments for chapter 1
- Tech review comments for chapter 1
- Fix grammar
- Fix grammar
- Edits to edits to the introduction
- Comments from nostarch on the introduction

## rust-by-example

8 commits in 1095df2a5850f2d345fad43a30633133365875ba..83724ca387a2a1cd3e8d848f62820020760e358b
2022-06-18 21:47:12 -0300 to 2022-07-05 10:38:07 -0300
- changing names of params (rust-lang/rust-by-example#1567)
- Update incorrect print output in std/box.md (rust-lang/rust-by-example#1564)
- minor typo (rust-lang/rust-by-example#1563)
- fix: Fibonacci sequence starts from zero (rust-lang/rust-by-example#1562)
- add Vietnamese version on README.md (rust-lang/rust-by-example#1561)
- Update variadics.md (rust-lang/rust-by-example#1559)
- Change fold to sum in fn hof.md (rust-lang/rust-by-example#1560)
- Small typo, fixed compileable -> compilable (rust-lang/rust-by-example#1556)

## rustc-dev-guide

8 commits in 048d925f0a955aac601c4160c0e7f05771bcf63b..eb83839e903a0a8f1406f7e941886273f189b26b
2022-06-21 22:25:34 +0900 to 2022-07-03 15:17:39 +0900
- Suggest a separate build directory for rust-analyzer (rust-lang/rustc-dev-guide#1378)
- Change the old filename, "src/stage0.txt" to "src/stage0.json" (rust-lang/rustc-dev-guide#1383)
- Add the config needed to get rust-analyzer working on src/bootstrap (rust-lang/rustc-dev-guide#1381)
- Fix path to hir_id_validator.rs
- leave formatOnSave to the user (rust-lang/rustc-dev-guide#1380)
- diagnostics: structs with new slug syntax (rust-lang/rustc-dev-guide#1377)
- Few readability fixes
- humorust: Forbid pineapple on pizza (rust-lang/rustc-dev-guide#1374)

## embedded-book

1 commits in e17dcef5e96346ee3d7fa56820ddc7e5c39636bc..766979590da8100998f0d662499d4a901d8d1640
2022-06-19 10:28:00 +0000 to 2022-07-04 09:13:58 +0000
- "linker `link.exe` not found" fix  (rust-embedded/book#321)
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

Successfully merging this pull request may close these issues.

Is the proof of the assume thattemp doesn't alias inputwrong in section 3.2
2 participants