mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Don't compute layout if TargetDataLayout
is not available
This commit is contained in:
parent
5306eb06cc
commit
77efa0267d
5 changed files with 19 additions and 36 deletions
|
@ -1,7 +1,5 @@
|
|||
//! Compute the binary representation of a type
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use base_db::CrateId;
|
||||
use chalk_ir::{AdtId, TyKind};
|
||||
use hir_def::{
|
||||
|
@ -31,19 +29,19 @@ mod adt;
|
|||
mod target;
|
||||
|
||||
struct LayoutCx<'a> {
|
||||
db: &'a dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
target: &'a TargetDataLayout,
|
||||
}
|
||||
|
||||
impl LayoutCalculator for LayoutCx<'_> {
|
||||
type TargetDataLayoutRef = Arc<TargetDataLayout>;
|
||||
impl<'a> LayoutCalculator for LayoutCx<'a> {
|
||||
type TargetDataLayoutRef = &'a TargetDataLayout;
|
||||
|
||||
fn delay_bug(&self, txt: &str) {
|
||||
never!("{}", txt);
|
||||
}
|
||||
|
||||
fn current_data_layout(&self) -> Arc<TargetDataLayout> {
|
||||
self.db.target_data_layout(self.krate)
|
||||
fn current_data_layout(&self) -> &'a TargetDataLayout {
|
||||
self.target
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +54,8 @@ fn scalar(dl: &TargetDataLayout, value: Primitive) -> Layout {
|
|||
}
|
||||
|
||||
pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty, krate: CrateId) -> Result<Layout, LayoutError> {
|
||||
let cx = LayoutCx { db, krate };
|
||||
let Some(target) = db.target_data_layout(krate) else { return Err(LayoutError::TargetLayoutNotAvailable) };
|
||||
let cx = LayoutCx { krate, target: &target };
|
||||
let dl = &*cx.current_data_layout();
|
||||
Ok(match ty.kind(Interner) {
|
||||
TyKind::Adt(AdtId(def), subst) => db.layout_of_adt(*def, subst.clone())?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue