1
Fork 0

Emit error instead of ICE when optimized MIR is missing

Closes 51388.
This commit is contained in:
Martin Nordholts 2023-08-29 19:29:14 +02:00
parent e877e2a2c9
commit 456007af12
6 changed files with 44 additions and 3 deletions

View file

@ -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)]
@ -950,7 +951,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

View file

@ -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>,