summaryrefslogtreecommitdiffstats
path: root/src/tools/rust-analyzer/crates/hir-ty/src/layout/target.rs
blob: adfae0a1abb387eafc9ff7bb14c6ca6b7da6d982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! Target dependent parameters needed for layouts

use std::sync::Arc;

use base_db::CrateId;
use hir_def::layout::TargetDataLayout;

use crate::db::HirDatabase;

pub fn target_data_layout_query(
    db: &dyn HirDatabase,
    krate: CrateId,
) -> Option<Arc<TargetDataLayout>> {
    let crate_graph = db.crate_graph();
    let target_layout = crate_graph[krate].target_layout.as_ref().ok()?;
    let res = TargetDataLayout::parse_from_llvm_datalayout_string(&target_layout);
    if let Err(_e) = &res {
        // FIXME: Print the error here once it implements debug/display
        // also logging here is somewhat wrong, but unfortunately this is the earliest place we can
        // parse that doesn't impose a dependency to the rust-abi crate for project-model
        tracing::error!("Failed to parse target data layout for {krate:?}");
    }
    res.ok().map(Arc::new)
}