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

Fixed logical mistake #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fixed logical mistake #139

wants to merge 1 commit into from

Conversation

VPaulV
Copy link
Contributor

@VPaulV VPaulV commented Apr 13, 2023

 //let xr = &mut x;     // Error - there is already an immutable ref, so we 

Should be xr1 (or any other name here), with xr it will compile just fine

```
 //let xr = &mut x;     // Error - there is already an immutable ref, so we 
```
Should be xr1 (or any other name here), with just xr it will compile just fine
Copy link
Owner

@nrc nrc left a comment

Choose a reason for hiding this comment

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

Thanks for catching this! To make the error, I think it also needs a usage of xr after the creation of xr1 in order to keep xr alive long enough

@@ -67,7 +67,7 @@ fn foo() {
let mut x = 5;
let xr = &x; // Ok (creates an immutable ref)
//*xr = 4; // Error - mutating immutable ref
//let xr = &mut x; // Error - there is already an immutable ref, so we
//let xr1 = &mut x; // Error - there is already an immutable ref, so we
// can't make a mutable one

Copy link
Owner

Choose a reason for hiding this comment

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

To make this actually error, we need another call to bar(xr) in here

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.

2 participants