Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir/lower.rs')
-rw-r--r--crates/hir-ty/src/mir/lower.rs72
1 files changed, 46 insertions, 26 deletions
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index 95c93b5f3e..9816902fc0 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -50,6 +50,8 @@ use crate::{
utils::ClosureSubst,
};
+use super::OperandKind;
+
mod as_place;
mod pattern_matching;
@@ -329,7 +331,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
let Some((p, current)) = self.lower_expr_as_place(current, expr_id, true)? else {
return Ok(None);
};
- Ok(Some((Operand::Copy(p), current)))
+ Ok(Some((Operand { kind: OperandKind::Copy(p), span: Some(expr_id.into()) }, current)))
}
fn lower_expr_to_place_with_adjust(
@@ -352,7 +354,12 @@ impl<'ctx> MirLowerCtx<'ctx> {
else {
return Ok(None);
};
- self.push_assignment(current, place, Operand::Copy(p).into(), expr_id.into());
+ self.push_assignment(
+ current,
+ place,
+ Operand { kind: OperandKind::Copy(p), span: None }.into(),
+ expr_id.into(),
+ );
Ok(Some(current))
}
Adjust::Borrow(AutoBorrow::Ref(_, m) | AutoBorrow::RawPtr(m)) => {
@@ -376,7 +383,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
place,
Rvalue::Cast(
CastKind::PointerCoercion(*cast),
- Operand::Copy(p),
+ Operand { kind: OperandKind::Copy(p), span: None },
last.target.clone(),
),
expr_id.into(),
@@ -482,7 +489,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.push_assignment(
current,
place,
- Operand::Copy(temp).into(),
+ Operand { kind: OperandKind::Copy(temp), span: None }.into(),
expr_id.into(),
);
Ok(Some(current))
@@ -523,21 +530,24 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.push_assignment(
current,
place,
- Operand::Constant(
- ConstData {
- ty,
- value: chalk_ir::ConstValue::BoundVar(BoundVar::new(
- DebruijnIndex::INNERMOST,
- generics.type_or_const_param_idx(p.into()).ok_or(
- MirLowerError::TypeError(
- "fail to lower const generic param",
- ),
- )?,
- )),
- }
- .intern(Interner),
- )
- .into(),
+ Rvalue::from(Operand {
+ kind: OperandKind::Constant(
+ ConstData {
+ ty,
+ value: chalk_ir::ConstValue::BoundVar(BoundVar::new(
+ DebruijnIndex::INNERMOST,
+ generics.type_or_const_param_idx(p.into()).ok_or(
+ MirLowerError::TypeError(
+ "fail to lower const generic param",
+ ),
+ )?,
+ )),
+ }
+ .intern(Interner),
+ )
+ .into(),
+ span: None,
+ }),
expr_id.into(),
);
Ok(Some(current))
@@ -882,7 +892,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
})),
&mut self.result.projection_store,
);
- Operand::Copy(p)
+ Operand { kind: OperandKind::Copy(p), span: None }
}
})
.collect(),
@@ -984,7 +994,12 @@ impl<'ctx> MirLowerCtx<'ctx> {
else {
return Ok(None);
};
- self.push_assignment(current, place, Operand::Copy(p).into(), expr_id.into());
+ self.push_assignment(
+ current,
+ place,
+ Operand { kind: OperandKind::Copy(p), span: None }.into(),
+ expr_id.into(),
+ );
Ok(Some(current))
}
Expr::UnaryOp {
@@ -1061,8 +1076,11 @@ impl<'ctx> MirLowerCtx<'ctx> {
else {
return Ok(None);
};
- let r_value =
- Rvalue::CheckedBinaryOp(op.into(), Operand::Copy(lhs_place), rhs_op);
+ let r_value = Rvalue::CheckedBinaryOp(
+ op.into(),
+ Operand { kind: OperandKind::Copy(lhs_place), span: None },
+ rhs_op,
+ );
self.push_assignment(current, lhs_place, r_value, expr_id.into());
return Ok(Some(current));
}
@@ -1237,9 +1255,11 @@ impl<'ctx> MirLowerCtx<'ctx> {
Rvalue::Ref(*bk, p),
capture_spans[0],
);
- operands.push(Operand::Move(tmp));
+ operands.push(Operand { kind: OperandKind::Move(tmp), span: None });
+ }
+ CaptureKind::ByValue => {
+ operands.push(Operand { kind: OperandKind::Move(p), span: None })
}
- CaptureKind::ByValue => operands.push(Operand::Move(p)),
}
}
self.push_assignment(
@@ -1481,7 +1501,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
.const_eval(const_id, subst, None)
.map_err(|e| MirLowerError::ConstEvalError(name.into(), Box::new(e)))?
};
- Ok(Operand::Constant(c))
+ Ok(Operand { kind: OperandKind::Constant(c), span: None })
}
fn write_bytes_to_place(