mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
lower adjusts in simple index except the last one
This commit is contained in:
parent
8a6ca86247
commit
d7fe4e2fa8
2 changed files with 27 additions and 1 deletions
|
@ -216,8 +216,15 @@ impl MirLowerCtx<'_> {
|
||||||
index_fn,
|
index_fn,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let adjusts = self
|
||||||
|
.infer
|
||||||
|
.expr_adjustments
|
||||||
|
.get(base)
|
||||||
|
.and_then(|x| x.split_last())
|
||||||
|
.map(|x| x.1)
|
||||||
|
.unwrap_or(&[]);
|
||||||
let Some((mut p_base, current)) =
|
let Some((mut p_base, current)) =
|
||||||
self.lower_expr_as_place_without_adjust(current, *base, true)?
|
self.lower_expr_as_place_with_adjust(current, *base, true, adjusts)?
|
||||||
else {
|
else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -564,6 +564,25 @@ fn f(x: [(i32, u8); 10]) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn index() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- minicore: coerce_unsized, index, slice
|
||||||
|
fn f() {
|
||||||
|
let x = [1, 2, 3];
|
||||||
|
x[2] = 5;
|
||||||
|
//^^^^^^^^ 💡 error: cannot mutate immutable variable `x`
|
||||||
|
let x = &mut x;
|
||||||
|
//^^^^^^ 💡 error: cannot mutate immutable variable `x`
|
||||||
|
let mut x = x;
|
||||||
|
//^^^^^ 💡 weak: variable does not need to be mutable
|
||||||
|
x[2] = 5;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn overloaded_index() {
|
fn overloaded_index() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
|
|
Loading…
Reference in a new issue