about summary refs log tree commit diff
path: root/compiler/rustc_monomorphize/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-09-05 07:15:15 +0200
committerGitHub <noreply@github.com>2023-09-05 07:15:15 +0200
commita73c663ec4b1adc3cf9f82604c8cb552d3b593b6 (patch)
tree488da6ce4b19b7be53765b46788449fba11c851d /compiler/rustc_monomorphize/src
parent9c609ae158aab27f1e7df446de6f2c09414012a9 (diff)
parent456007af125d3822285135659ea5ea0b67084b66 (diff)
Rollup merge of #115353 - Enselic:no-optimized-mir, r=oli-obk
Emit error instead of ICE when optimized MIR is missing

Closes #51388
Diffstat (limited to 'compiler/rustc_monomorphize/src')
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs8
-rw-r--r--compiler/rustc_monomorphize/src/errors.rs10
2 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index bf88360a8c1..36cc0204dff 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -192,7 +192,8 @@ use rustc_target::abi::Size;
 use std::path::PathBuf;
 
 use crate::errors::{
-    EncounteredErrorWhileInstantiating, LargeAssignmentsLint, RecursionLimit, TypeLengthLimit,
+    EncounteredErrorWhileInstantiating, LargeAssignmentsLint, NoOptimizedMir, RecursionLimit,
+    TypeLengthLimit,
 };
 
 #[derive(PartialEq)]
@@ -960,7 +961,10 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
     }
 
     if !tcx.is_mir_available(def_id) {
-        bug!("no MIR available for {:?}", def_id);
+        tcx.sess.emit_fatal(NoOptimizedMir {
+            span: tcx.def_span(def_id),
+            crate_name: tcx.crate_name(def_id.krate),
+        });
     }
 
     true
diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs
index 495a73490a2..fdcc95f137f 100644
--- a/compiler/rustc_monomorphize/src/errors.rs
+++ b/compiler/rustc_monomorphize/src/errors.rs
@@ -4,7 +4,7 @@ use crate::fluent_generated as fluent;
 use rustc_errors::ErrorGuaranteed;
 use rustc_errors::IntoDiagnostic;
 use rustc_macros::{Diagnostic, LintDiagnostic};
-use rustc_span::Span;
+use rustc_span::{Span, Symbol};
 
 #[derive(Diagnostic)]
 #[diag(monomorphize_recursion_limit)]
@@ -33,6 +33,14 @@ pub struct TypeLengthLimit {
     pub type_length: usize,
 }
 
+#[derive(Diagnostic)]
+#[diag(monomorphize_no_optimized_mir)]
+pub struct NoOptimizedMir {
+    #[note]
+    pub span: Span,
+    pub crate_name: Symbol,
+}
+
 pub struct UnusedGenericParamsHint {
     pub span: Span,
     pub param_spans: Vec<Span>,