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

rename y to _y to get the correct compile error #1769

Merged
merged 3 commits into from
Nov 18, 2023

Conversation

aviad-dev
Copy link
Contributor

Without this change, the error is:

   Compiling playground v0.0.1 (/playground)
warning: unused variable: `y`
  --> src/main.rs:13:9
   |
13 |     let y: &'a i32 = &_x;
   |         ^ help: if this is intentional, prefix it with an underscore: `_y`
   |
   = note: `#[warn(unused_variables)]` on by default

error[E0597]: `_x` does not live long enough
  --> src/main.rs:13:22
   |
9  | fn failed_borrow<'a>() {
   |                  -- lifetime `'a` defined here
10 |     let _x = 12;
   |         -- binding `_x` declared here
...
13 |     let y: &'a i32 = &_x;
   |            -------   ^^^ borrowed value does not live long enough
   |            |
   |            type annotation requires that `_x` is borrowed for `'a`
...
17 | }
   | - `_x` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.
warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground` (bin "playground") due to previous error; 1 warning emitted

Without this change, the error is:
```
   Compiling playground v0.0.1 (/playground)
warning: unused variable: `y`
  --> src/main.rs:13:9
   |
13 |     let y: &'a i32 = &_x;
   |         ^ help: if this is intentional, prefix it with an underscore: `_y`
   |
   = note: `#[warn(unused_variables)]` on by default

error[E0597]: `_x` does not live long enough
  --> src/main.rs:13:22
   |
9  | fn failed_borrow<'a>() {
   |                  -- lifetime `'a` defined here
10 |     let _x = 12;
   |         -- binding `_x` declared here
...
13 |     let y: &'a i32 = &_x;
   |            -------   ^^^ borrowed value does not live long enough
   |            |
   |            type annotation requires that `_x` is borrowed for `'a`
...
17 | }
   | - `_x` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.
warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground` (bin "playground") due to previous error; 1 warning emitted
```
@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @marioidival (or someone else) soon.

@kberov
Copy link
Contributor

kberov commented Nov 9, 2023

True. Although the message for the y variable is only a warning, the learner may get confused.

@@ -40,7 +40,7 @@ fn failed_borrow<'a>() {
let _x = 12;

// ERROR: `_x` does not live long enough
let y: &'a i32 = &_x;
let _y: &'a i32 = &_x;
// Attempting to use the lifetime `'a` as an explicit type annotation
// inside the function will fail because the lifetime of `&_x` is shorter
// than that of `y`. A short lifetime cannot be coerced into a longer one.
Copy link
Member

Choose a reason for hiding this comment

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

Can you change that reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see update in 3dffa1e

If that is what you meant, let me know and I'll squash the commits to keep git history tidy.

@marioidival marioidival merged commit a658124 into rust-lang:master Nov 18, 2023
1 check passed
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Nov 21, 2023
Update books

## rust-lang/book

2 commits in 5b6c1ceaa62ecbd6caef08df39b33b3938e99deb..71352deb20727b4dda9ebfe8182709d5bf17dfea
2023-11-09 14:49:45 UTC to 2023-11-09 14:49:16 UTC

- Fixed 'Devtools' link (rust-lang/book#3770)
- Fix mdBook links (rust-lang/book#3769)

## rust-lang/rust-by-example

7 commits in 311b84962016b28c75525c86e7b3f49fd9101a39..a6581246f96837113968c02187db24f742af3908
2023-11-18 21:45:20 UTC to 2023-11-07 22:32:53 UTC

- rename `y` to `_y` to get the correct compile error (rust-lang/rust-by-example#1769)
- fix test name in cargo/test.md (rust-lang/rust-by-example#1768)
- Various minor edits for typo fixes, formatting fixes, and clarifications (rust-lang/rust-by-example#1765)
- Update closures.md to correct a typo (rust-lang/rust-by-example#1763)
- Link to the Bulgarian translation (rust-lang/rust-by-example#1764)
- Fix asm example explanation for `inlateout` usage (22.1 Inline Assembly) (rust-lang/rust-by-example#1766)
- Update index.md: Added descriptions for the 'leftover' points (rust-lang/rust-by-example#1767)

## rust-lang/rustc-dev-guide

3 commits in 77dbe5782b2488af3bb489ad702eaff438f465bf..ddb8b1309f9e905804cea1e248a4572fed6b464b
2023-11-18 21:08:13 UTC to 2023-11-08 14:43:50 UTC

- Add link for unsize.md (rust-lang/rustc-dev-guide#1825)
- Fix typo in contribution walkthrough (rust-lang/rustc-dev-guide#1824)
- Update documentation for coverage tests (rust-lang/rustc-dev-guide#1823)
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Nov 21, 2023
Update books

## rust-lang/book

2 commits in 5b6c1ceaa62ecbd6caef08df39b33b3938e99deb..71352deb20727b4dda9ebfe8182709d5bf17dfea
2023-11-09 14:49:45 UTC to 2023-11-09 14:49:16 UTC

- Fixed 'Devtools' link (rust-lang/book#3770)
- Fix mdBook links (rust-lang/book#3769)

## rust-lang/rust-by-example

7 commits in 311b84962016b28c75525c86e7b3f49fd9101a39..a6581246f96837113968c02187db24f742af3908
2023-11-18 21:45:20 UTC to 2023-11-07 22:32:53 UTC

- rename `y` to `_y` to get the correct compile error (rust-lang/rust-by-example#1769)
- fix test name in cargo/test.md (rust-lang/rust-by-example#1768)
- Various minor edits for typo fixes, formatting fixes, and clarifications (rust-lang/rust-by-example#1765)
- Update closures.md to correct a typo (rust-lang/rust-by-example#1763)
- Link to the Bulgarian translation (rust-lang/rust-by-example#1764)
- Fix asm example explanation for `inlateout` usage (22.1 Inline Assembly) (rust-lang/rust-by-example#1766)
- Update index.md: Added descriptions for the 'leftover' points (rust-lang/rust-by-example#1767)

## rust-lang/rustc-dev-guide

3 commits in 77dbe5782b2488af3bb489ad702eaff438f465bf..ddb8b1309f9e905804cea1e248a4572fed6b464b
2023-11-18 21:08:13 UTC to 2023-11-08 14:43:50 UTC

- Add link for unsize.md (rust-lang/rustc-dev-guide#1825)
- Fix typo in contribution walkthrough (rust-lang/rustc-dev-guide#1824)
- Update documentation for coverage tests (rust-lang/rustc-dev-guide#1823)
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2023
Rollup merge of rust-lang#118097 - rustbot:docs-update, r=ehuss

Update books

## rust-lang/book

2 commits in 5b6c1ceaa62ecbd6caef08df39b33b3938e99deb..71352deb20727b4dda9ebfe8182709d5bf17dfea
2023-11-09 14:49:45 UTC to 2023-11-09 14:49:16 UTC

- Fixed 'Devtools' link (rust-lang/book#3770)
- Fix mdBook links (rust-lang/book#3769)

## rust-lang/rust-by-example

7 commits in 311b84962016b28c75525c86e7b3f49fd9101a39..a6581246f96837113968c02187db24f742af3908
2023-11-18 21:45:20 UTC to 2023-11-07 22:32:53 UTC

- rename `y` to `_y` to get the correct compile error (rust-lang/rust-by-example#1769)
- fix test name in cargo/test.md (rust-lang/rust-by-example#1768)
- Various minor edits for typo fixes, formatting fixes, and clarifications (rust-lang/rust-by-example#1765)
- Update closures.md to correct a typo (rust-lang/rust-by-example#1763)
- Link to the Bulgarian translation (rust-lang/rust-by-example#1764)
- Fix asm example explanation for `inlateout` usage (22.1 Inline Assembly) (rust-lang/rust-by-example#1766)
- Update index.md: Added descriptions for the 'leftover' points (rust-lang/rust-by-example#1767)

## rust-lang/rustc-dev-guide

3 commits in 77dbe5782b2488af3bb489ad702eaff438f465bf..ddb8b1309f9e905804cea1e248a4572fed6b464b
2023-11-18 21:08:13 UTC to 2023-11-08 14:43:50 UTC

- Add link for unsize.md (rust-lang/rustc-dev-guide#1825)
- Fix typo in contribution walkthrough (rust-lang/rustc-dev-guide#1824)
- Update documentation for coverage tests (rust-lang/rustc-dev-guide#1823)
@aviad-dev aviad-dev deleted the patch-2 branch January 24, 2024 07:52
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.

None yet

4 participants