rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

mutably borrowed Type Alias incorrectly marked as immutable

Open shyguy1412 opened this issue 1 month ago • 3 comments

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){
}

shyguy1412 avatar Nov 29 '25 13:11 shyguy1412

We don't correctly lower the array size with that expr, that might be the cause. However we shouldn't do borrow checking when there are error types, so this is weird.

ChayimFriedman2 avatar Nov 29 '25 19:11 ChayimFriedman2

@shyguy1412 which version of the rust analyzer are you using?

I updated both my stable toolchain as well as my unstable toolchain and i do not get this error message.

Editor: vnim rust-analyzer versions i tried are stable: ed61e7d7e 2025-11-07 nightly: 1d60f9e 2025-12-01

cerdelen avatar Dec 02 '25 16:12 cerdelen

I'm using the vscode extension at version 0.3.2711

shyguy1412 avatar Dec 10 '25 00:12 shyguy1412