diff options
Diffstat (limited to 'compiler/rustc_mir_transform/src')
6 files changed, 23 insertions, 22 deletions
diff --git a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs index 757dc093755..ade6555f4d2 100644 --- a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs +++ b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs @@ -1,6 +1,5 @@ use crate::MirPass; use rustc_hir::def::DefKind; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::*; use rustc_middle::ty::layout; use rustc_middle::ty::{self, TyCtxt}; @@ -46,7 +45,6 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls { // // Here we test for this function itself whether its ABI allows // unwinding or not. - let body_flags = tcx.codegen_fn_attrs(def_id).flags; let body_ty = tcx.type_of(def_id); let body_abi = match body_ty.kind() { ty::FnDef(..) => body_ty.fn_sig(tcx).abi(), @@ -54,7 +52,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls { ty::Generator(..) => Abi::Rust, _ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty), }; - let body_can_unwind = layout::fn_can_unwind(tcx, body_flags, body_abi); + let body_can_unwind = layout::fn_can_unwind(tcx, Some(def_id), body_abi); // Look in this function body for any basic blocks which are terminated // with a function call, and whose function we're calling may unwind. @@ -73,19 +71,19 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls { TerminatorKind::Call { func, .. } => { let ty = func.ty(body, tcx); let sig = ty.fn_sig(tcx); - let flags = match ty.kind() { - ty::FnPtr(_) => CodegenFnAttrFlags::empty(), - ty::FnDef(def_id, _) => tcx.codegen_fn_attrs(*def_id).flags, + let fn_def_id = match ty.kind() { + ty::FnPtr(_) => None, + &ty::FnDef(def_id, _) => Some(def_id), _ => span_bug!(span, "invalid callee of type {:?}", ty), }; - layout::fn_can_unwind(tcx, flags, sig.abi()) + layout::fn_can_unwind(tcx, fn_def_id, sig.abi()) } TerminatorKind::Drop { .. } | TerminatorKind::DropAndReplace { .. } => { tcx.sess.opts.debugging_opts.panic_in_drop == PanicStrategy::Unwind - && layout::fn_can_unwind(tcx, CodegenFnAttrFlags::empty(), Abi::Rust) + && layout::fn_can_unwind(tcx, None, Abi::Rust) } TerminatorKind::Assert { .. } | TerminatorKind::FalseUnwind { .. } => { - layout::fn_can_unwind(tcx, CodegenFnAttrFlags::empty(), Abi::Rust) + layout::fn_can_unwind(tcx, None, Abi::Rust) } _ => continue, }; diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index dde79214b16..1f73b7da815 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -375,7 +375,8 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> { } let callee_features = &self.tcx.codegen_fn_attrs(func_did).target_features; - let self_features = &self.tcx.codegen_fn_attrs(self.body_did).target_features; + // The body might be a constant, so it doesn't have codegen attributes. + let self_features = &self.tcx.body_codegen_attrs(self.body_did.to_def_id()).target_features; // Is `callee_features` a subset of `calling_features`? if !callee_features.iter().all(|feature| self_features.contains(feature)) { diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 144ea0ec619..d5d4bfa255b 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -18,13 +18,13 @@ //! First upvars are stored //! It is followed by the generator state field. //! Then finally the MIR locals which are live across a suspension point are stored. -//! +//! ```ignore (illustrative) //! struct Generator { //! upvars..., //! state: u32, //! mir_locals..., //! } -//! +//! ``` //! This pass computes the meaning of the state field and the MIR locals which are live //! across a suspension point. There are however three hardcoded generator states: //! 0 - Generator have not been resumed yet diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index 3c14a324c36..7cd7d26328a 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -14,7 +14,7 @@ pub struct MatchBranchSimplification; /// /// For example: /// -/// ```rust +/// ```ignore (MIR) /// bb0: { /// switchInt(move _3) -> [42_isize: bb1, otherwise: bb2]; /// } @@ -32,7 +32,7 @@ pub struct MatchBranchSimplification; /// /// into: /// -/// ```rust +/// ```ignore (MIR) /// bb0: { /// _2 = Eq(move _3, const 42_isize); /// goto -> bb3; diff --git a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs index da683a33651..bbfaace7041 100644 --- a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs +++ b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs @@ -12,7 +12,7 @@ use rustc_middle::{ /// Pass to convert `if` conditions on integrals into switches on the integral. /// For an example, it turns something like /// -/// ``` +/// ```ignore (MIR) /// _3 = Eq(move _4, const 43i32); /// StorageDead(_4); /// switchInt(_3) -> [false: bb2, otherwise: bb3]; @@ -20,7 +20,7 @@ use rustc_middle::{ /// /// into: /// -/// ``` +/// ```ignore (MIR) /// switchInt(_4) -> [43i32: bb3, otherwise: bb2]; /// ``` pub struct SimplifyComparisonIntegral; diff --git a/compiler/rustc_mir_transform/src/simplify_try.rs b/compiler/rustc_mir_transform/src/simplify_try.rs index ce4b45062e8..b3d45c7a221 100644 --- a/compiler/rustc_mir_transform/src/simplify_try.rs +++ b/compiler/rustc_mir_transform/src/simplify_try.rs @@ -1,10 +1,12 @@ //! The general point of the optimizations provided here is to simplify something like: //! //! ```rust +//! # fn foo<T, E>(x: Result<T, E>) -> Result<T, E> { //! match x { //! Ok(x) => Ok(x), //! Err(x) => Err(x) //! } +//! # } //! ``` //! //! into just `x`. @@ -23,7 +25,7 @@ use std::slice::Iter; /// /// This is done by transforming basic blocks where the statements match: /// -/// ```rust +/// ```ignore (MIR) /// _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY ); /// _TMP_2 = _LOCAL_TMP; /// ((_LOCAL_0 as Variant).FIELD: TY) = move _TMP_2; @@ -32,7 +34,7 @@ use std::slice::Iter; /// /// into: /// -/// ```rust +/// ```ignore (MIR) /// _LOCAL_0 = move _LOCAL_1 /// ``` pub struct SimplifyArmIdentity; @@ -472,7 +474,7 @@ impl Visitor<'_> for LocalUseCounter { } /// Match on: -/// ```rust +/// ```ignore (MIR) /// _LOCAL_INTO = ((_LOCAL_FROM as Variant).FIELD: TY); /// ``` fn match_get_variant_field<'tcx>( @@ -492,7 +494,7 @@ fn match_get_variant_field<'tcx>( } /// Match on: -/// ```rust +/// ```ignore (MIR) /// ((_LOCAL_FROM as Variant).FIELD: TY) = move _LOCAL_INTO; /// ``` fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> { @@ -507,7 +509,7 @@ fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local } /// Match on: -/// ```rust +/// ```ignore (MIR) /// discriminant(_LOCAL_TO_SET) = VAR_IDX; /// ``` fn match_set_discr(stmt: &Statement<'_>) -> Option<(Local, VariantIdx)> { @@ -690,7 +692,7 @@ impl<'tcx> SimplifyBranchSameOptimizationFinder<'_, 'tcx> { /// /// Statements can be trivially equal if the kinds match. /// But they can also be considered equal in the following case A: - /// ``` + /// ```ignore (MIR) /// discriminant(_0) = 0; // bb1 /// _0 = move _1; // bb2 /// ``` |
