-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Weird error for mutable references in a loop #70255
Comments
Oh, you're right, the reduced example in #54663 and mine match almost exactly, so I'll close this issue to avoid the noise. It's first time I hear about polonius TBH, is there anything to read about timeline and differences with current NLL implementation? |
The following posts go a bit in depth on polonius (https://github.com/rust-lang/polonius)
As for timeline, I’m unaware if one is set, but progress is being made by the working group! https://rust-lang.github.io/compiler-team/working-groups/polonius/ |
@memoryruins Thanks! By the way, I just double-checked, and while first snippet does compile under Given that this part seems different from other linked issues (for them polonius does fix the problem), I'm hesitantly reopening this one for tracking. |
Ah my mistake, thanks for double-checking and reopening! - if let Some(res) = Some(item) {
+ if let Some(res) = Some::<&mut _>(item) { + let item_: &mut _ = item;
- if let Some(res) = Some(item) {
+ if let Some(res) = Some(item_) { - if let Some(res) = Some(item) {
+ if let Some(res) = Some(&mut *item) { I'll leave it to someone else to explain if this is expected or not :) |
I ran into this error a few days ago. My solution was to use raw pointer to work around. loop {
if let Ok(x) = self.try_recv_ref() {
unsafe {
return &*(x as *const T);
}
}
} Is there a way to solve this problem without nightly or unsafe? |
@qiujiangkun Can you share the full working snippet on play.rust-lang.org? In my case, I found than intermediate boolean variable helped as an ugly but working workaround, maybe it's possible in yours too. |
Sure. |
I tried this code:
I expected to see this happen: code successfully compiles because mutable reference is used only temporarily in an
if
block.Instead, this happened: Rust fails to compile with an error.
Without
noop
it also fails, although with slightly different error:Error:
Meta
rustc --version --verbose
:(although reproduces in all Rust versions I could find)
The text was updated successfully, but these errors were encountered: