mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
lower adjusts in simple index except the last one
This commit is contained in:
parent
8a6ca86247
commit
d7fe4e2fa8
@ -216,8 +216,15 @@ impl MirLowerCtx<'_> {
|
||||
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)) =
|
||||
self.lower_expr_as_place_without_adjust(current, *base, true)?
|
||||
self.lower_expr_as_place_with_adjust(current, *base, true, adjusts)?
|
||||
else {
|
||||
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]
|
||||
fn overloaded_index() {
|
||||
check_diagnostics(
|
||||
|
Loading…
Reference in New Issue
Block a user