Skip to content

Commit 9fca0a4

Browse files
committed
Auto merge of rust-lang#14316 - HKalbasi:master, r=HKalbasi
Fix stack overflow when derefrencing `&!` fix rust-lang#14310
2 parents 070f8f8 + a980b56 commit 9fca0a4

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

crates/hir-ty/src/consteval/tests.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ fn reference_autoderef() {
146146
"#,
147147
3,
148148
);
149+
check_number(
150+
r#"
151+
struct Foo<T> { x: T }
152+
impl<T> Foo<T> {
153+
fn foo(&mut self) -> T { self.x }
154+
}
155+
fn f(i: &mut &mut Foo<Foo<i32>>) -> i32 {
156+
((**i).x).foo()
157+
}
158+
fn g(i: Foo<Foo<i32>>) -> i32 {
159+
i.x.foo()
160+
}
161+
const GOAL: i32 = f(&mut &mut Foo { x: Foo { x: 3 } }) + g(Foo { x: Foo { x: 5 } });
162+
"#,
163+
8,
164+
);
149165
}
150166

151167
#[test]

crates/hir-ty/src/mir/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl MirLowerCtx<'_> {
637637
}
638638
Expr::Box { .. } => not_supported!("box expression"),
639639
Expr::Field { .. } | Expr::Index { .. } | Expr::UnaryOp { op: hir_def::expr::UnaryOp::Deref, .. } => {
640-
let Some((p, current)) = self.lower_expr_as_place(current, expr_id, true)? else {
640+
let Some((p, current)) = self.lower_expr_as_place_without_adjust(current, expr_id, true)? else {
641641
return Ok(None);
642642
};
643643
self.push_assignment(current, place, Operand::Copy(p).into(), expr_id.into());

crates/hir-ty/src/mir/lower/as_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl MirLowerCtx<'_> {
110110
}
111111
}
112112

113-
fn lower_expr_as_place_without_adjust(
113+
pub(super) fn lower_expr_as_place_without_adjust(
114114
&mut self,
115115
current: BasicBlockId,
116116
expr_id: ExprId,

crates/ide-diagnostics/src/handlers/mutability_errors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ fn main() {
336336
);
337337
}
338338

339+
#[test]
340+
fn regression_14310() {
341+
check_diagnostics(
342+
r#"
343+
fn clone(mut i: &!) -> ! {
344+
//^^^^^ 💡 weak: variable does not need to be mutable
345+
*i
346+
}
347+
"#,
348+
);
349+
}
350+
339351
#[test]
340352
fn match_bindings() {
341353
check_diagnostics(

0 commit comments

Comments
 (0)