Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir/eval.rs')
-rw-r--r--crates/hir-ty/src/mir/eval.rs229
1 files changed, 99 insertions, 130 deletions
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index 16075d9073..8143dc05c3 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -272,6 +272,7 @@ const STACK_OFFSET: usize = 1 << 30;
const HEAP_OFFSET: usize = 1 << 29;
impl Address {
+ #[allow(clippy::double_parens)]
fn from_bytes(it: &[u8]) -> Result<Self> {
Ok(Address::from_usize(from_bytes!(usize, it)))
}
@@ -291,12 +292,11 @@ impl Address {
}
fn to_usize(&self) -> usize {
- let as_num = match self {
+ match self {
Stack(it) => *it + STACK_OFFSET,
Heap(it) => *it + HEAP_OFFSET,
Invalid(it) => *it,
- };
- as_num
+ }
}
fn map(&self, f: impl FnOnce(usize) -> usize) -> Address {
@@ -485,8 +485,7 @@ impl DropFlags {
fn remove_place(&mut self, p: &Place, store: &ProjectionStore) -> bool {
// FIXME: replace parents with parts
- if let Some(parent) = p.iterate_over_parents(store).find(|it| self.need_drop.contains(&it))
- {
+ if let Some(parent) = p.iterate_over_parents(store).find(|it| self.need_drop.contains(it)) {
self.need_drop.remove(&parent);
return true;
}
@@ -551,7 +550,7 @@ pub fn interpret_mir(
memory_map.vtable.shrink_to_fit();
MemoryMap::Complex(Box::new(memory_map))
};
- return Ok(intern_const_scalar(ConstScalar::Bytes(bytes, memory_map), ty));
+ Ok(intern_const_scalar(ConstScalar::Bytes(bytes, memory_map), ty))
})();
(it, MirOutput { stdout: evaluator.stdout, stderr: evaluator.stderr })
}
@@ -562,12 +561,12 @@ const EXECUTION_LIMIT: usize = 100_000;
const EXECUTION_LIMIT: usize = 10_000_000;
impl Evaluator<'_> {
- pub fn new<'a>(
- db: &'a dyn HirDatabase,
+ pub fn new(
+ db: &dyn HirDatabase,
owner: DefWithBodyId,
assert_placeholder_ty_is_unused: bool,
trait_env: Option<Arc<TraitEnvironment>>,
- ) -> Evaluator<'a> {
+ ) -> Evaluator<'_> {
let crate_id = owner.module(db.upcast()).krate();
Evaluator {
stack: vec![0],
@@ -585,7 +584,7 @@ impl Evaluator<'_> {
assert_placeholder_ty_is_unused,
stack_depth_limit: 100,
execution_limit: EXECUTION_LIMIT,
- memory_limit: 1000_000_000, // 2GB, 1GB for stack and 1GB for heap
+ memory_limit: 1_000_000_000, // 2GB, 1GB for stack and 1GB for heap
layout_cache: RefCell::new(Default::default()),
projected_ty_cache: RefCell::new(Default::default()),
not_special_fn_cache: RefCell::new(Default::default()),
@@ -752,7 +751,7 @@ impl Evaluator<'_> {
Variants::Multiple { variants, .. } => {
&variants[match f.parent {
hir_def::VariantId::EnumVariantId(it) => {
- RustcEnumVariantIdx(it.local_id)
+ RustcEnumVariantIdx(it.lookup(self.db.upcast()).index as usize)
}
_ => {
return Err(MirEvalError::TypeError(
@@ -816,8 +815,8 @@ impl Evaluator<'_> {
})
}
- fn interpret_mir<'slf>(
- &'slf mut self,
+ fn interpret_mir(
+ &mut self,
body: Arc<MirBody>,
args: impl Iterator<Item = IntervalOrOwned>,
) -> Result<Interval> {
@@ -837,7 +836,7 @@ impl Evaluator<'_> {
not_supported!("missing stack frame");
};
let e = (|| {
- let mut locals = &mut my_stack_frame.locals;
+ let locals = &mut my_stack_frame.locals;
let body = locals.body.clone();
loop {
let current_block = &body.basic_blocks[current_block_idx];
@@ -849,12 +848,10 @@ impl Evaluator<'_> {
for statement in &current_block.statements {
match &statement.kind {
StatementKind::Assign(l, r) => {
- let addr = self.place_addr(l, &locals)?;
- let result = self.eval_rvalue(r, &mut locals)?;
+ let addr = self.place_addr(l, locals)?;
+ let result = self.eval_rvalue(r, locals)?;
self.copy_from_interval_or_owned(addr, result)?;
- locals
- .drop_flags
- .add_place(l.clone(), &locals.body.projection_store);
+ locals.drop_flags.add_place(*l, &locals.body.projection_store);
}
StatementKind::Deinit(_) => not_supported!("de-init statement"),
StatementKind::StorageLive(_)
@@ -878,20 +875,20 @@ impl Evaluator<'_> {
cleanup: _,
from_hir_call: _,
} => {
- let destination_interval = self.place_interval(destination, &locals)?;
- let fn_ty = self.operand_ty(func, &locals)?;
+ let destination_interval = self.place_interval(destination, locals)?;
+ let fn_ty = self.operand_ty(func, locals)?;
let args = args
.iter()
- .map(|it| self.operand_ty_and_eval(it, &mut locals))
+ .map(|it| self.operand_ty_and_eval(it, locals))
.collect::<Result<Vec<_>>>()?;
let stack_frame = match &fn_ty.kind(Interner) {
TyKind::Function(_) => {
- let bytes = self.eval_operand(func, &mut locals)?;
+ let bytes = self.eval_operand(func, locals)?;
self.exec_fn_pointer(
bytes,
destination_interval,
&args,
- &locals,
+ locals,
*target,
terminator.span,
)?
@@ -901,7 +898,7 @@ impl Evaluator<'_> {
generic_args,
destination_interval,
&args,
- &locals,
+ locals,
*target,
terminator.span,
)?,
@@ -909,7 +906,7 @@ impl Evaluator<'_> {
};
locals
.drop_flags
- .add_place(destination.clone(), &locals.body.projection_store);
+ .add_place(*destination, &locals.body.projection_store);
if let Some(stack_frame) = stack_frame {
self.code_stack.push(my_stack_frame);
current_block_idx = stack_frame.locals.body.start_block;
@@ -924,7 +921,7 @@ impl Evaluator<'_> {
}
TerminatorKind::SwitchInt { discr, targets } => {
let val = u128::from_le_bytes(pad16(
- self.eval_operand(discr, &mut locals)?.get(&self)?,
+ self.eval_operand(discr, locals)?.get(self)?,
false,
));
current_block_idx = targets.target_for_value(val);
@@ -938,7 +935,7 @@ impl Evaluator<'_> {
));
}
TerminatorKind::Drop { place, target, unwind: _ } => {
- self.drop_place(place, &mut locals, terminator.span)?;
+ self.drop_place(place, locals, terminator.span)?;
current_block_idx = *target;
}
_ => not_supported!("unknown terminator"),
@@ -1081,7 +1078,7 @@ impl Evaluator<'_> {
}
}
Rvalue::UnaryOp(op, val) => {
- let mut c = self.eval_operand(val, locals)?.get(&self)?;
+ let mut c = self.eval_operand(val, locals)?.get(self)?;
let mut ty = self.operand_ty(val, locals)?;
while let TyKind::Ref(_, _, z) = ty.kind(Interner) {
ty = z.clone();
@@ -1124,8 +1121,8 @@ impl Evaluator<'_> {
Rvalue::CheckedBinaryOp(op, lhs, rhs) => 'binary_op: {
let lc = self.eval_operand(lhs, locals)?;
let rc = self.eval_operand(rhs, locals)?;
- let mut lc = lc.get(&self)?;
- let mut rc = rc.get(&self)?;
+ let mut lc = lc.get(self)?;
+ let mut rc = rc.get(self)?;
let mut ty = self.operand_ty(lhs, locals)?;
while let TyKind::Ref(_, _, z) = ty.kind(Interner) {
ty = z.clone();
@@ -1277,12 +1274,12 @@ impl Evaluator<'_> {
}
Rvalue::Discriminant(p) => {
let ty = self.place_ty(p, locals)?;
- let bytes = self.eval_place(p, locals)?.get(&self)?;
+ let bytes = self.eval_place(p, locals)?.get(self)?;
let result = self.compute_discriminant(ty, bytes)?;
Owned(result.to_le_bytes().to_vec())
}
Rvalue::Repeat(it, len) => {
- let len = match try_const_usize(self.db, &len) {
+ let len = match try_const_usize(self.db, len) {
Some(it) => it as usize,
None => not_supported!("non evaluatable array len in repeat Rvalue"),
};
@@ -1308,13 +1305,13 @@ impl Evaluator<'_> {
AggregateKind::Array(_) => {
let mut r = vec![];
for it in values {
- let value = it.get(&self)?;
+ let value = it.get(self)?;
r.extend(value);
}
Owned(r)
}
AggregateKind::Tuple(ty) => {
- let layout = self.layout(&ty)?;
+ let layout = self.layout(ty)?;
Owned(self.make_by_layout(
layout.size.bytes_usize(),
&layout,
@@ -1329,7 +1326,7 @@ impl Evaluator<'_> {
.fields
.offset(u32::from(f.local_id.into_raw()) as usize)
.bytes_usize();
- let op = values[0].get(&self)?;
+ let op = values[0].get(self)?;
let mut result = vec![0; layout.size.bytes_usize()];
result[offset..offset + op.len()].copy_from_slice(op);
Owned(result)
@@ -1345,7 +1342,7 @@ impl Evaluator<'_> {
)?)
}
AggregateKind::Closure(ty) => {
- let layout = self.layout(&ty)?;
+ let layout = self.layout(ty)?;
Owned(self.make_by_layout(
layout.size.bytes_usize(),
&layout,
@@ -1390,14 +1387,11 @@ impl Evaluator<'_> {
| CastKind::PointerExposeAddress
| CastKind::PointerFromExposedAddress => {
let current_ty = self.operand_ty(operand, locals)?;
- let is_signed = match current_ty.kind(Interner) {
- TyKind::Scalar(s) => match s {
- chalk_ir::Scalar::Int(_) => true,
- _ => false,
- },
- _ => false,
- };
- let current = pad16(self.eval_operand(operand, locals)?.get(&self)?, is_signed);
+ let is_signed = matches!(
+ current_ty.kind(Interner),
+ TyKind::Scalar(chalk_ir::Scalar::Int(_))
+ );
+ let current = pad16(self.eval_operand(operand, locals)?.get(self)?, is_signed);
let dest_size =
self.size_of_sized(target_ty, locals, "destination of int to int cast")?;
Owned(current[0..dest_size].to_vec())
@@ -1412,22 +1406,12 @@ impl Evaluator<'_> {
fn compute_discriminant(&self, ty: Ty, bytes: &[u8]) -> Result<i128> {
let layout = self.layout(&ty)?;
- let enum_id = 'b: {
- match ty.kind(Interner) {
- TyKind::Adt(e, _) => match e.0 {
- AdtId::EnumId(e) => break 'b e,
- _ => (),
- },
- _ => (),
- }
+ let &TyKind::Adt(chalk_ir::AdtId(AdtId::EnumId(e)), _) = ty.kind(Interner) else {
return Ok(0);
};
match &layout.variants {
Variants::Single { index } => {
- let r = self.const_eval_discriminant(EnumVariantId {
- parent: enum_id,
- local_id: index.0,
- })?;
+ let r = self.const_eval_discriminant(self.db.enum_data(e).variants[index.0].0)?;
Ok(r)
}
Variants::Multiple { tag, tag_encoding, variants, .. } => {
@@ -1446,17 +1430,15 @@ impl Evaluator<'_> {
let candidate_tag = i128::from_le_bytes(pad16(tag, false))
.wrapping_sub(*niche_start as i128)
as usize;
- let variant = variants
+ let idx = variants
.iter_enumerated()
.map(|(it, _)| it)
.filter(|it| it != untagged_variant)
.nth(candidate_tag)
.unwrap_or(*untagged_variant)
.0;
- let result = self.const_eval_discriminant(EnumVariantId {
- parent: enum_id,
- local_id: variant,
- })?;
+ let result =
+ self.const_eval_discriminant(self.db.enum_data(e).variants[idx].0)?;
Ok(result)
}
}
@@ -1525,7 +1507,7 @@ impl Evaluator<'_> {
let mut r = Vec::with_capacity(16);
let addr = addr.get(self)?;
r.extend(addr.iter().copied());
- r.extend(len.to_le_bytes().into_iter());
+ r.extend(len.to_le_bytes());
Owned(r)
}
t => {
@@ -1537,7 +1519,7 @@ impl Evaluator<'_> {
let mut r = Vec::with_capacity(16);
let addr = addr.get(self)?;
r.extend(addr.iter().copied());
- r.extend(vtable.to_le_bytes().into_iter());
+ r.extend(vtable.to_le_bytes());
Owned(r)
}
TyKind::Adt(id, target_subst) => match &current_ty.kind(Interner) {
@@ -1551,7 +1533,7 @@ impl Evaluator<'_> {
AdtId::EnumId(_) => not_supported!("unsizing enums"),
};
let Some((last_field, _)) =
- self.db.struct_data(id).variant_data.fields().iter().rev().next()
+ self.db.struct_data(id).variant_data.fields().iter().next_back()
else {
not_supported!("unsizing struct without field");
};
@@ -1579,14 +1561,16 @@ impl Evaluator<'_> {
subst: Substitution,
locals: &Locals,
) -> Result<(usize, Arc<Layout>, Option<(usize, usize, i128)>)> {
- let adt = it.adt_id();
+ let adt = it.adt_id(self.db.upcast());
if let DefWithBodyId::VariantId(f) = locals.body.owner {
if let VariantId::EnumVariantId(it) = it {
- if AdtId::from(f.parent) == adt {
- // Computing the exact size of enums require resolving the enum discriminants. In order to prevent loops (and
- // infinite sized type errors) we use a dummy layout
- let i = self.const_eval_discriminant(it)?;
- return Ok((16, self.layout(&TyBuilder::unit())?, Some((0, 16, i))));
+ if let AdtId::EnumId(e) = adt {
+ if f.lookup(self.db.upcast()).parent == e {
+ // Computing the exact size of enums require resolving the enum discriminants. In order to prevent loops (and
+ // infinite sized type errors) we use a dummy layout
+ let i = self.const_eval_discriminant(it)?;
+ return Ok((16, self.layout(&TyBuilder::unit())?, Some((0, 16, i))));
+ }
}
}
}
@@ -1602,8 +1586,9 @@ impl Evaluator<'_> {
VariantId::EnumVariantId(it) => it,
_ => not_supported!("multi variant layout for non-enums"),
};
- let rustc_enum_variant_idx = RustcEnumVariantIdx(enum_variant_id.local_id);
let mut discriminant = self.const_eval_discriminant(enum_variant_id)?;
+ let lookup = enum_variant_id.lookup(self.db.upcast());
+ let rustc_enum_variant_idx = RustcEnumVariantIdx(lookup.index as usize);
let variant_layout = variants[rustc_enum_variant_idx].clone();
let have_tag = match tag_encoding {
TagEncoding::Direct => true,
@@ -1654,7 +1639,7 @@ impl Evaluator<'_> {
}
for (i, op) in values.enumerate() {
let offset = variant_layout.fields.offset(i).bytes_usize();
- let op = op.get(&self)?;
+ let op = op.get(self)?;
match result.get_mut(offset..offset + op.len()) {
Some(it) => it.copy_from_slice(op),
None => return Err(MirEvalError::BrokenLayout(Box::new(variant_layout.clone()))),
@@ -1677,6 +1662,7 @@ impl Evaluator<'_> {
})
}
+ #[allow(clippy::double_parens)]
fn allocate_const_in_heap(&mut self, locals: &Locals, konst: &Const) -> Result<Interval> {
let ty = &konst.data(Interner).ty;
let chalk_ir::ConstValue::Concrete(c) = &konst.data(Interner).value else {
@@ -1695,7 +1681,7 @@ impl Evaluator<'_> {
}
result_owner = self
.db
- .const_eval(const_id.into(), subst, Some(self.trait_env.clone()))
+ .const_eval(const_id, subst, Some(self.trait_env.clone()))
.map_err(|e| {
let name = const_id.name(self.db.upcast());
MirEvalError::ConstEvalError(name, Box::new(e))
@@ -1778,9 +1764,8 @@ impl Evaluator<'_> {
)));
}
};
- Ok(mem.get_mut(pos..pos + size).ok_or_else(|| {
- MirEvalError::UndefinedBehavior("out of bound memory write".to_string())
- })?)
+ mem.get_mut(pos..pos + size)
+ .ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory write".to_string()))
}
fn write_memory(&mut self, addr: Address, r: &[u8]) -> Result<()> {
@@ -1847,8 +1832,8 @@ impl Evaluator<'_> {
.then(|| (layout.size.bytes_usize(), layout.align.abi.bytes() as usize)));
}
if let DefWithBodyId::VariantId(f) = locals.body.owner {
- if let Some((adt, _)) = ty.as_adt() {
- if AdtId::from(f.parent) == adt {
+ if let Some((AdtId::EnumId(e), _)) = ty.as_adt() {
+ if f.lookup(self.db.upcast()).parent == e {
// Computing the exact size of enums require resolving the enum discriminants. In order to prevent loops (and
// infinite sized type errors) we use a dummy size
return Ok(Some((16, 16)));
@@ -1856,10 +1841,10 @@ impl Evaluator<'_> {
}
}
let layout = self.layout(ty);
- if self.assert_placeholder_ty_is_unused {
- if matches!(layout, Err(MirEvalError::LayoutError(LayoutError::HasPlaceholder, _))) {
- return Ok(Some((0, 1)));
- }
+ if self.assert_placeholder_ty_is_unused
+ && matches!(layout, Err(MirEvalError::LayoutError(LayoutError::HasPlaceholder, _)))
+ {
+ return Ok(Some((0, 1)));
}
let layout = layout?;
Ok(layout
@@ -1969,14 +1954,14 @@ impl Evaluator<'_> {
if let Some(ty) = check_inner {
for i in 0..count {
let offset = element_size * i;
- rec(this, &b[offset..offset + element_size], &ty, locals, mm)?;
+ rec(this, &b[offset..offset + element_size], ty, locals, mm)?;
}
}
}
}
}
chalk_ir::TyKind::Array(inner, len) => {
- let len = match try_const_usize(this.db, &len) {
+ let len = match try_const_usize(this.db, len) {
Some(it) => it as usize,
None => not_supported!("non evaluatable array len in patching addresses"),
};
@@ -2019,10 +2004,8 @@ impl Evaluator<'_> {
bytes,
e,
) {
- let data = &this.db.enum_data(e).variants[v].variant_data;
- let field_types = this
- .db
- .field_types(EnumVariantId { parent: e, local_id: v }.into());
+ let data = &this.db.enum_variant_data(v).variant_data;
+ let field_types = this.db.field_types(v.into());
for (f, _) in data.fields().iter() {
let offset =
l.fields.offset(u32::from(f.into_raw()) as usize).bytes_usize();
@@ -2039,7 +2022,7 @@ impl Evaluator<'_> {
Ok(())
}
let mut mm = ComplexMemoryMap::default();
- rec(&self, bytes, ty, locals, &mut mm)?;
+ rec(self, bytes, ty, locals, &mut mm)?;
Ok(mm)
}
@@ -2093,14 +2076,13 @@ impl Evaluator<'_> {
}
AdtId::UnionId(_) => (),
AdtId::EnumId(e) => {
- if let Some((variant, layout)) = detect_variant_from_bytes(
+ if let Some((ev, layout)) = detect_variant_from_bytes(
&layout,
self.db,
self.trait_env.clone(),
self.read_memory(addr, layout.size.bytes_usize())?,
e,
) {
- let ev = EnumVariantId { parent: e, local_id: variant };
for (i, (_, ty)) in self.db.field_types(ev.into()).iter().enumerate() {
let offset = layout.fields.offset(i).bytes_usize();
let ty = ty.clone().substitute(Interner, subst);
@@ -2123,7 +2105,7 @@ impl Evaluator<'_> {
}
}
TyKind::Array(inner, len) => {
- let len = match try_const_usize(self.db, &len) {
+ let len = match try_const_usize(self.db, len) {
Some(it) => it as usize,
None => not_supported!("non evaluatable array len in patching addresses"),
};
@@ -2147,8 +2129,8 @@ impl Evaluator<'_> {
| TyKind::Str
| TyKind::Never
| TyKind::Closure(_, _)
- | TyKind::Generator(_, _)
- | TyKind::GeneratorWitness(_, _)
+ | TyKind::Coroutine(_, _)
+ | TyKind::CoroutineWitness(_, _)
| TyKind::Foreign(_)
| TyKind::Error
| TyKind::Placeholder(_)
@@ -2173,7 +2155,7 @@ impl Evaluator<'_> {
let next_ty = self.vtable_map.ty(id)?.clone();
match &next_ty.kind(Interner) {
TyKind::FnDef(def, generic_args) => {
- self.exec_fn_def(*def, generic_args, destination, args, &locals, target_bb, span)
+ self.exec_fn_def(*def, generic_args, destination, args, locals, target_bb, span)
}
TyKind::Closure(id, subst) => {
self.exec_closure(*id, bytes.slice(0..0), subst, destination, args, locals, span)
@@ -2207,7 +2189,7 @@ impl Evaluator<'_> {
closure_data.get(self)?.to_owned()
};
let arg_bytes = iter::once(Ok(closure_data))
- .chain(args.iter().map(|it| Ok(it.get(&self)?.to_owned())))
+ .chain(args.iter().map(|it| Ok(it.get(self)?.to_owned())))
.collect::<Result<Vec<_>>>()?;
let interval = self
.interpret_mir(mir_body, arg_bytes.into_iter().map(IntervalOrOwned::Owned))
@@ -2235,7 +2217,7 @@ impl Evaluator<'_> {
let generic_args = generic_args.clone();
match def {
CallableDefId::FunctionId(def) => {
- if let Some(_) = self.detect_fn_trait(def) {
+ if self.detect_fn_trait(def).is_some() {
return self.exec_fn_trait(
def,
args,
@@ -2258,7 +2240,7 @@ impl Evaluator<'_> {
}
CallableDefId::StructId(id) => {
let (size, variant_layout, tag) =
- self.layout_of_variant(id.into(), generic_args, &locals)?;
+ self.layout_of_variant(id.into(), generic_args, locals)?;
let result = self.make_by_layout(
size,
&variant_layout,
@@ -2270,7 +2252,7 @@ impl Evaluator<'_> {
}
CallableDefId::EnumVariantId(id) => {
let (size, variant_layout, tag) =
- self.layout_of_variant(id.into(), generic_args, &locals)?;
+ self.layout_of_variant(id.into(), generic_args, locals)?;
let result = self.make_by_layout(
size,
&variant_layout,
@@ -2365,7 +2347,7 @@ impl Evaluator<'_> {
}
}),
);
- return self.exec_fn_with_args(
+ self.exec_fn_with_args(
def,
&args_for_target,
generics_for_target,
@@ -2373,7 +2355,7 @@ impl Evaluator<'_> {
destination,
target_bb,
span,
- );
+ )
}
MirOrDynIndex::Mir(body) => self.exec_looked_up_function(
body,
@@ -2425,7 +2407,7 @@ impl Evaluator<'_> {
target_bb: Option<BasicBlockId>,
span: MirSpan,
) -> Result<Option<StackFrame>> {
- let func = args.get(0).ok_or(MirEvalError::TypeError("fn trait with no arg"))?;
+ let func = args.first().ok_or(MirEvalError::TypeError("fn trait with no arg"))?;
let mut func_ty = func.ty.clone();
let mut func_data = func.interval;
while let TyKind::Ref(_, _, z) = func_ty.kind(Interner) {
@@ -2441,25 +2423,10 @@ impl Evaluator<'_> {
}
match &func_ty.kind(Interner) {
TyKind::FnDef(def, subst) => {
- return self.exec_fn_def(
- *def,
- subst,
- destination,
- &args[1..],
- locals,
- target_bb,
- span,
- );
+ self.exec_fn_def(*def, subst, destination, &args[1..], locals, target_bb, span)
}
TyKind::Function(_) => {
- return self.exec_fn_pointer(
- func_data,
- destination,
- &args[1..],
- locals,
- target_bb,
- span,
- );
+ self.exec_fn_pointer(func_data, destination, &args[1..], locals, target_bb, span)
}
TyKind::Closure(closure, subst) => {
return self.exec_closure(
@@ -2495,7 +2462,7 @@ impl Evaluator<'_> {
self.write_memory(addr, &result)?;
IntervalAndTy { interval: Interval { addr, size }, ty }
};
- return self.exec_fn_with_args(
+ self.exec_fn_with_args(
def,
&[arg0.clone(), arg1],
generic_args,
@@ -2503,7 +2470,7 @@ impl Evaluator<'_> {
destination,
target_bb,
span,
- );
+ )
}
}
}
@@ -2523,7 +2490,7 @@ impl Evaluator<'_> {
self.allocate_const_in_heap(locals, &konst)?
} else {
let ty = &self.db.infer(st.into())[self.db.body(st.into()).body_expr];
- let Some((size, align)) = self.size_align_of(&ty, locals)? else {
+ let Some((size, align)) = self.size_align_of(ty, locals)? else {
not_supported!("unsized extern static");
};
let addr = self.heap_allocate(size, align)?;
@@ -2540,11 +2507,13 @@ impl Evaluator<'_> {
match r {
Ok(r) => Ok(r),
Err(e) => {
- let data = self.db.enum_data(variant.parent);
+ let db = self.db.upcast();
+ let loc = variant.lookup(db);
+ let enum_loc = loc.parent.lookup(db);
let name = format!(
"{}::{}",
- data.name.display(self.db.upcast()),
- data.variants[variant.local_id].name.display(self.db.upcast())
+ enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast()),
+ loc.id.item_tree(db)[loc.id.value].name.display(db.upcast()),
);
Err(MirEvalError::ConstEvalError(name, Box::new(e)))
}
@@ -2635,8 +2604,8 @@ impl Evaluator<'_> {
| TyKind::Str
| TyKind::Never
| TyKind::Closure(_, _)
- | TyKind::Generator(_, _)
- | TyKind::GeneratorWitness(_, _)
+ | TyKind::Coroutine(_, _)
+ | TyKind::CoroutineWitness(_, _)
| TyKind::Foreign(_)
| TyKind::Error
| TyKind::Placeholder(_)
@@ -2679,7 +2648,7 @@ pub fn render_const_using_debug_impl(
db.upcast(),
&hir_def::path::Path::from_known_path_with_no_generic(ModPath::from_segments(
hir_expand::mod_path::PathKind::Abs,
- [name![core], name![fmt], name![Debug]].into_iter(),
+ [name![core], name![fmt], name![Debug]],
)),
) else {
not_supported!("core::fmt::Debug not found");
@@ -2711,7 +2680,7 @@ pub fn render_const_using_debug_impl(
db.upcast(),
&hir_def::path::Path::from_known_path_with_no_generic(ModPath::from_segments(
hir_expand::mod_path::PathKind::Abs,
- [name![std], name![fmt], name![format]].into_iter(),
+ [name![std], name![fmt], name![format]],
)),
) else {
not_supported!("std::fmt::format not found");