Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,16 @@ rustc_queries! {
remap_env_constness
}

/// Computes the alignment of a type. Note that this implicitly
/// executes in "reveal all" mode, and will normalize the input type.
query align_of(
key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
) -> Result<ty::alignment::AbiAndPrefAlign, ty::layout::LayoutError<'tcx>> {
depth_limit
desc { "computing alignment of `{}`", key.value }
remap_env_constness
}

/// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
///
/// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/alignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use rustc_target::abi::AbiAndPrefAlign;
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,17 @@ impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
}
}

pub trait AlignOf<'tcx>: LayoutOf<'tcx> {
#[inline]
fn align_of(&self, ty: Ty<'tcx>) -> Result<AbiAndPrefAlign, LayoutError<'tcx>> {
let span = self.layout_tcx_at_span();
let tcx = self.tcx().at(span);
tcx.align_of(self.param_env().and(ty))
}
}

impl<'tcx, C: LayoutOf<'tcx>> AlignOf<'tcx> for C {}

impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx>
where
C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub use self::typeck_results::{
pub mod _match;
pub mod abstract_const;
pub mod adjustment;
pub mod alignment;
pub mod binding;
pub mod cast;
pub mod codec;
Expand Down
Loading