Skip to content

Wrong "cannot mutate immutable variable array (E0384)" #15670

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

Closed
xxshady opened this issue Sep 26, 2023 · 16 comments · Fixed by #15860
Closed

Wrong "cannot mutate immutable variable array (E0384)" #15670

xxshady opened this issue Sep 26, 2023 · 16 comments · Fixed by #15860
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@xxshady
Copy link

xxshady commented Sep 26, 2023

rust-analyzer version: 0.4.1674-standalone (d3cc3bc 2023-09-25)

rustc version: 1.72.0 (5680fa18f 2023-08-23)

rust-analyzer complains about "immutable variable", but rustc compiles this code without issues

However this doesnt cause any issues:

@xxshady xxshady added the C-bug Category: bug label Sep 26, 2023
@xxshady
Copy link
Author

xxshady commented Sep 26, 2023

Probably related to #14463 and #14612

@lnicola lnicola added A-diagnostics diagnostics / error reporting A-mir and removed A-mir labels Sep 26, 2023
@HKalbasi
Copy link
Member

Can't reproduce this. Does it happen in a standalone project? Also your playground link is empty.

@lnicola
Copy link
Member

lnicola commented Sep 26, 2023

Yeah, it doesn't even trigger for me on:

    fn repro<'a>(&'a self, idx: usize) {
        let array = &mut self.array;
        array[idx] = 1;
    }

nor on:

    fn repro<'a>(&'a self, idx: usize) {
        let array = &self.array;
        array[idx] = 1;
    }

@xxshady
Copy link
Author

xxshady commented Sep 26, 2023

Can't reproduce this. Does it happen in a standalone project? Also your playground link is empty.

Oh, I'm sorry: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cc8b0dc5315b9bc75d6caa9e5faa85d4

@lnicola
Copy link
Member

lnicola commented Sep 26, 2023

Can't reproduce, does it still show up if you restart Code?

@xxshady
Copy link
Author

xxshady commented Sep 26, 2023

I opened project where I reproduced it and now I can't 😐
rust-analyzer version: 0.4.1674-standalone (d3cc3bc 2023-09-25)
Same RA version

@xxshady
Copy link
Author

xxshady commented Sep 26, 2023

I'm closing issue then xd

@xxshady xxshady closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
@xxshady
Copy link
Author

xxshady commented Sep 26, 2023

First time I got it (at the time when i could still reproduce it) after I opened this folder in vscode: https://github.com/rust-in-action/code/blob/25f2e2277cbd527ab8bf5e8b68a17672215874f3/ch5/ch5-cpu3

rust-analyzer showed error on this line: https://github.com/rust-in-action/code/blob/19c4349758b57bdb233e186746bfec03ad9ea88d/ch5/ch5-cpu3/src/main.rs#L49

@lnicola
Copy link
Member

lnicola commented Sep 27, 2023

Still can't reproduce. I opened just that directory.

image

I do get errors at the bottom of the file because of the syntax errors in main, but nothing else changes if I fix them.

@lnicola lnicola reopened this Sep 27, 2023
@xxshady
Copy link
Author

xxshady commented Sep 27, 2023

Then there is no issue xd

@lnicola
Copy link
Member

lnicola commented Sep 27, 2023

Well, you seem to have one, but I have no idea why.

@xxshady
Copy link
Author

xxshady commented Sep 27, 2023

I opened project where I reproduced it and now I can't 😐

Sorry for confusion, I can't reproduce it anymore either

@xxshady
Copy link
Author

xxshady commented Sep 27, 2023

Maybe it was caching issue or something like that

@lnicola
Copy link
Member

lnicola commented Sep 27, 2023

If it happens again, take a look at the Output panel, there are two RA channels there. Maybe you'll find something.

@lnicola lnicola added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Sep 27, 2023
@mati865
Copy link
Contributor

mati865 commented Nov 9, 2023

I have encountered the same issue in some FFI code.
Reduced example:
image

code:

pub struct A {}
pub unsafe fn foo(a: *mut A) {
    let b = || -> *mut A { &mut *a };
    let _ = b();
}

playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6ac27c26e10eb46113dc10e88d939c60

@lnicola
Copy link
Member

lnicola commented Nov 9, 2023

This got closed by mistake, but feel free to open a new issue if needed, xxshady.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants