about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-18 00:35:19 +0000
committerbors <bors@rust-lang.org>2022-03-18 00:35:19 +0000
commitcd119057160cedea245aa2679add56723f3dc784 (patch)
tree21335c52669bb2665024cf37adf8d892925d9d31 /compiler/rustc_codegen_ssa/src
parent4ca56d2b7bbe275bc6c9f3cd698c6e0719a07182 (diff)
parent4493826d07bf38cca058b4d9e75bce14ceeeaab9 (diff)
downloadrust-cd119057160cedea245aa2679add56723f3dc784.tar.gz
rust-cd119057160cedea245aa2679add56723f3dc784.zip
Auto merge of #95056 - Dylan-DPC:rollup-swtuw2n, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #91133 (Improve `unsafe` diagnostic)
 - #93222 (Make ErrorReported impossible to construct outside `rustc_errors`)
 - #93745 (Stabilize ADX target feature)
 - #94309 ([generator_interior] Be more precise with scopes of borrowed places)
 - #94698 (Remove redundant code from copy-suggestions)
 - #94731 (Suggest adding `{ .. }` around a const function call with arguments)
 - #94960 (Fix many spelling mistakes)
 - #94982 (Add deprecated_safe feature gate and attribute, cc #94978)
 - #94997 (debuginfo: Fix ICE when generating name for type that produces a layout error.)
 - #95000 (Fixed wrong type name in comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs25
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/mod.rs3
-rw-r--r--compiler/rustc_codegen_ssa/src/target_features.rs2
3 files changed, 25 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
index f39f260225e..ffc8f55bc0c 100644
--- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
+++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
@@ -74,9 +74,30 @@ fn push_debuginfo_type_name<'tcx>(
         ty::Float(float_ty) => output.push_str(float_ty.name_str()),
         ty::Foreign(def_id) => push_item_name(tcx, def_id, qualified, output),
         ty::Adt(def, substs) => {
-            let ty_and_layout = tcx.layout_of(ParamEnv::reveal_all().and(t)).expect("layout error");
+            // `layout_for_cpp_like_fallback` will be `Some` if we want to use the fallback encoding.
+            let layout_for_cpp_like_fallback = if cpp_like_debuginfo && def.is_enum() {
+                match tcx.layout_of(ParamEnv::reveal_all().and(t)) {
+                    Ok(layout) => {
+                        if !wants_c_like_enum_debuginfo(layout) {
+                            Some(layout)
+                        } else {
+                            // This is a C-like enum so we don't want to use the fallback encoding
+                            // for the name.
+                            None
+                        }
+                    }
+                    Err(e) => {
+                        // Computing the layout can still fail here, e.g. if the target architecture
+                        // cannot represent the type. See https://github.com/rust-lang/rust/issues/94961.
+                        tcx.sess.fatal(&format!("{}", e));
+                    }
+                }
+            } else {
+                // We are not emitting cpp-like debuginfo or this isn't even an enum.
+                None
+            };
 
-            if def.is_enum() && cpp_like_debuginfo && !wants_c_like_enum_debuginfo(ty_and_layout) {
+            if let Some(ty_and_layout) = layout_for_cpp_like_fallback {
                 msvc_enum_fallback(
                     tcx,
                     ty_and_layout,
diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs
index 40a8e2388e2..6c139df0a85 100644
--- a/compiler/rustc_codegen_ssa/src/mir/mod.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs
@@ -1,5 +1,4 @@
 use crate::traits::*;
-use rustc_errors::ErrorGuaranteed;
 use rustc_middle::mir;
 use rustc_middle::mir::interpret::ErrorHandled;
 use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, TyAndLayout};
@@ -191,7 +190,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
             all_consts_ok = false;
             match err {
                 // errored or at least linted
-                ErrorHandled::Reported(ErrorGuaranteed) | ErrorHandled::Linted => {}
+                ErrorHandled::Reported(_) | ErrorHandled::Linted => {}
                 ErrorHandled::TooGeneric => {
                     span_bug!(const_.span, "codgen encountered polymorphic constant: {:?}", err)
                 }
diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs
index ff7415af373..dd214d96166 100644
--- a/compiler/rustc_codegen_ssa/src/target_features.rs
+++ b/compiler/rustc_codegen_ssa/src/target_features.rs
@@ -148,7 +148,7 @@ const AARCH64_TIED_FEATURES: &[&[&str]] = &[
 ];
 
 const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
-    ("adx", Some(sym::adx_target_feature)),
+    ("adx", None),
     ("aes", None),
     ("avx", None),
     ("avx2", None),