Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14464 - HKalbasi:dev, r=HKalbasi
lower adjusts in simple index except the last one fix #14463
bors 2023-04-01
parent ffb04ae · parent d7fe4e2 · commit 1ce25f1
-rw-r--r--crates/hir-ty/src/mir/lower/as_place.rs9
-rw-r--r--crates/ide-diagnostics/src/handlers/mutability_errors.rs19
2 files changed, 27 insertions, 1 deletions
diff --git a/crates/hir-ty/src/mir/lower/as_place.rs b/crates/hir-ty/src/mir/lower/as_place.rs
index 86fee99b78..91163e5bd6 100644
--- a/crates/hir-ty/src/mir/lower/as_place.rs
+++ b/crates/hir-ty/src/mir/lower/as_place.rs
@@ -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);
};
diff --git a/crates/ide-diagnostics/src/handlers/mutability_errors.rs b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
index ecd1db7ea8..564b756402 100644
--- a/crates/ide-diagnostics/src/handlers/mutability_errors.rs
+++ b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
@@ -565,6 +565,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(
r#"