-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add detailed diagnostics for E0386. #27758
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
**y = 2; // error, cannot assign to data in an immutable container | ||
``` | ||
|
||
This error can be fixed by making the container mutable: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or using internal mutability, using std::cell
fc17c88
to
7e976a2
Compare
@Manishearth This one is ready to be re-reviewed as well now. 😄 r? @Manishearth |
`RefCell`: | ||
|
||
``` | ||
let y: Cell<_> = Cell::new(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go along the lines of the example above, let y: Box<Cell<_>> = Box::new(Cell::new(x))
, and then y.set(2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes much more sense! Fixing now! 👍
This adds detailed diagnostics for E0386, 'cannot assign to data in an immutable container'.
Types with interior mutability like `Cell` and `RefCell` can be used to skirt the restriction on mutating mutable values inside an immutable container.
7e976a2
to
b0b2952
Compare
@Manishearth Good for another round. 😄 |
@bors r+ rollup |
📌 Commit b0b2952 has been approved by |
This adds detailed diagnostics for E0386, 'cannot assign to data in an immutable container'. This is part of #24407. r? @Manishearth
💔 Test failed - auto-linux-64-opt |
@Manishearth Tests here failed, but for reasons seemingly unrelated to the changes in this PR. What do you peeps normally do in this circumstance? Retry the build? |
@bors retry it's an intermittent tcp issue |
This adds detailed diagnostics for E0386, 'cannot assign to data in an immutable container'. This is part of #24407. r? @Manishearth
This adds detailed diagnostics for E0386, 'cannot assign to data in an
immutable container'.
This is part of #24407.
r? @Manishearth