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.rs75
1 files changed, 52 insertions, 23 deletions
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index 9aa2eeebc1..9e23550451 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -21,7 +21,7 @@ use hir_expand::name::Name;
use la_arena::ArenaMap;
use rustc_apfloat::Float;
use rustc_hash::FxHashMap;
-use span::FileId;
+use span::{Edition, FileId};
use syntax::TextRange;
use triomphe::Arc;
@@ -157,13 +157,18 @@ impl MirLowerError {
f: &mut String,
db: &dyn HirDatabase,
span_formatter: impl Fn(FileId, TextRange) -> String,
+ edition: Edition,
) -> std::result::Result<(), std::fmt::Error> {
match self {
MirLowerError::ConstEvalError(name, e) => {
writeln!(f, "In evaluating constant {name}")?;
match &**e {
- ConstEvalError::MirLowerError(e) => e.pretty_print(f, db, span_formatter)?,
- ConstEvalError::MirEvalError(e) => e.pretty_print(f, db, span_formatter)?,
+ ConstEvalError::MirLowerError(e) => {
+ e.pretty_print(f, db, span_formatter, edition)?
+ }
+ ConstEvalError::MirEvalError(e) => {
+ e.pretty_print(f, db, span_formatter, edition)?
+ }
}
}
MirLowerError::MissingFunctionDefinition(owner, it) => {
@@ -171,15 +176,15 @@ impl MirLowerError {
writeln!(
f,
"Missing function definition for {}",
- body.pretty_print_expr(db.upcast(), *owner, *it)
+ body.pretty_print_expr(db.upcast(), *owner, *it, edition)
)?;
}
MirLowerError::TypeMismatch(e) => match e {
Some(e) => writeln!(
f,
"Type mismatch: Expected {}, found {}",
- e.expected.display(db),
- e.actual.display(db),
+ e.expected.display(db, edition),
+ e.actual.display(db, edition),
)?,
None => writeln!(f, "Type mismatch: types mismatch with {{unknown}}",)?,
},
@@ -189,11 +194,11 @@ impl MirLowerError {
writeln!(
f,
"Generic arg not provided for {}",
- param.name().unwrap_or(&Name::missing()).display(db.upcast())
+ param.name().unwrap_or(&Name::missing()).display(db.upcast(), edition)
)?;
writeln!(f, "Provided args: [")?;
for g in subst.iter(Interner) {
- write!(f, " {},", g.display(db))?;
+ write!(f, " {},", g.display(db, edition))?;
}
writeln!(f, "]")?;
}
@@ -242,8 +247,8 @@ impl From<LayoutError> for MirLowerError {
}
impl MirLowerError {
- fn unresolved_path(db: &dyn HirDatabase, p: &Path) -> Self {
- Self::UnresolvedName(p.display(db).to_string())
+ fn unresolved_path(db: &dyn HirDatabase, p: &Path, edition: Edition) -> Self {
+ Self::UnresolvedName(p.display(db, edition).to_string())
}
}
@@ -337,7 +342,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.push_assignment(current, place, Operand::Copy(p).into(), expr_id.into());
Ok(Some(current))
}
- Adjust::Borrow(AutoBorrow::Ref(m) | AutoBorrow::RawPtr(m)) => {
+ Adjust::Borrow(AutoBorrow::Ref(_, m) | AutoBorrow::RawPtr(m)) => {
let Some((p, current)) =
self.lower_expr_as_place_with_adjust(current, expr_id, true, rest)?
else {
@@ -436,7 +441,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
VariantId::UnionId(_) => implementation_error!("Union variant as path"),
}
} else {
- let unresolved_name = || MirLowerError::unresolved_path(self.db, p);
+ let unresolved_name =
+ || MirLowerError::unresolved_path(self.db, p, self.edition());
let resolver = resolver_for_expr(self.db.upcast(), self.owner, expr_id);
resolver
.resolve_path_in_value_ns_fully(self.db.upcast(), p)
@@ -662,7 +668,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
let (func_id, generic_args) =
self.infer.method_resolution(expr_id).ok_or_else(|| {
MirLowerError::UnresolvedMethod(
- method_name.display(self.db.upcast()).to_string(),
+ method_name.display(self.db.upcast(), self.edition()).to_string(),
)
})?;
let func = Operand::from_fn(self.db, func_id, generic_args);
@@ -803,7 +809,9 @@ impl<'ctx> MirLowerCtx<'ctx> {
};
let variant_id =
self.infer.variant_resolution_for_expr(expr_id).ok_or_else(|| match path {
- Some(p) => MirLowerError::UnresolvedName(p.display(self.db).to_string()),
+ Some(p) => MirLowerError::UnresolvedName(
+ p.display(self.db, self.edition()).to_string(),
+ ),
None => MirLowerError::RecordLiteralWithoutPath,
})?;
let subst = match self.expr_ty_without_adjust(expr_id).kind(Interner) {
@@ -1172,8 +1180,15 @@ impl<'ctx> MirLowerCtx<'ctx> {
let placeholder_subst = self.placeholder_subst();
let tmp_ty =
capture.ty.clone().substitute(Interner, &placeholder_subst);
- let tmp: Place = self.temp(tmp_ty, current, capture.span)?.into();
- self.push_assignment(current, tmp, Rvalue::Ref(*bk, p), capture.span);
+ // FIXME: Handle more than one span.
+ let capture_spans = capture.spans();
+ let tmp: Place = self.temp(tmp_ty, current, capture_spans[0])?.into();
+ self.push_assignment(
+ current,
+ tmp,
+ Rvalue::Ref(*bk, p),
+ capture_spans[0],
+ );
operands.push(Operand::Move(tmp));
}
CaptureKind::ByValue => operands.push(Operand::Move(p)),
@@ -1378,7 +1393,9 @@ impl<'ctx> MirLowerCtx<'ctx> {
"only `char` and numeric types are allowed in range patterns"
),
};
- let unresolved_name = || MirLowerError::unresolved_path(self.db, c.as_ref());
+ let edition = self.edition();
+ let unresolved_name =
+ || MirLowerError::unresolved_path(self.db, c.as_ref(), edition);
let resolver = self.owner.resolver(self.db.upcast());
let pr = resolver
.resolve_path_in_value_ns(self.db.upcast(), c.as_ref())
@@ -1904,19 +1921,25 @@ impl<'ctx> MirLowerCtx<'ctx> {
match r {
Ok(r) => Ok(r),
Err(e) => {
+ let edition = self.edition();
let db = self.db.upcast();
let loc = variant.lookup(db);
let enum_loc = loc.parent.lookup(db);
let name = format!(
"{}::{}",
- 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()),
+ enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast(), edition),
+ loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition),
);
Err(MirLowerError::ConstEvalError(name.into(), Box::new(e)))
}
}
}
+ fn edition(&self) -> Edition {
+ let krate = self.owner.krate(self.db.upcast());
+ self.db.crate_graph()[krate].edition
+ }
+
fn drop_until_scope(
&mut self,
scope_index: usize,
@@ -2121,18 +2144,24 @@ pub fn mir_body_for_closure_query(
}
pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<MirBody>> {
+ let krate = def.krate(db.upcast());
+ let edition = db.crate_graph()[krate].edition;
let detail = match def {
- DefWithBodyId::FunctionId(it) => db.function_data(it).name.display(db.upcast()).to_string(),
- DefWithBodyId::StaticId(it) => db.static_data(it).name.display(db.upcast()).to_string(),
+ DefWithBodyId::FunctionId(it) => {
+ db.function_data(it).name.display(db.upcast(), edition).to_string()
+ }
+ DefWithBodyId::StaticId(it) => {
+ db.static_data(it).name.display(db.upcast(), edition).to_string()
+ }
DefWithBodyId::ConstId(it) => db
.const_data(it)
.name
.clone()
.unwrap_or_else(Name::missing)
- .display(db.upcast())
+ .display(db.upcast(), edition)
.to_string(),
DefWithBodyId::VariantId(it) => {
- db.enum_variant_data(it).name.display(db.upcast()).to_string()
+ db.enum_variant_data(it).name.display(db.upcast(), edition).to_string()
}
DefWithBodyId::InTypeConstId(it) => format!("in type const {it:?}"),
};