rust-lang / rust-lang/rust-analyzer
mutably borrowed Type Alias incorrectly marked as immutable
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
this is a weird one. When asserting the type of the length of an array with as usize a bug occurs where passing a variable that is &mut Alias into a function that take &Alias marks that variable as immutable.
This does not happen when the type alias is changed to type ArrayAlias = [u16; 8];
type ArrayAlias = [u16; 8 as usize];
fn main() {}
fn produce_error(array: &mut ArrayAlias) {
mark_register_immutable(array);
array[0] = 5; // cannot mutate immutable variable `array`
}
fn mark_register_immutable(_: &ArrayAlias){
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Rust snippet and compare it with the version using type ArrayAlias = [u16; 8];. Trace how the type alias with 8 as usize is handled when passing &mut ArrayAlias to &ArrayAlias. Done means array[0] = 5 remains mutable in the reproducer, with coverage for both alias definitions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100