Skip to content

Commit 4b69743

Browse files
committed
Emit error instead of ICE when optimized MIR is missing
Closes 51388.
1 parent e877e2a commit 4b69743

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

compiler/rustc_monomorphize/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ monomorphize_large_assignments =
1414
.label = value moved from here
1515
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
1616
17+
monomorphize_no_optimized_mir =
18+
Optimized MIR unavailable for `{$def}`. Was it compiled with just `--emit=metadata` and without `-Zalways-encode-mir`?
19+
1720
monomorphize_recursion_limit =
1821
reached the recursion limit while instantiating `{$shrunk}`
1922
.note = `{$def_path_str}` defined here

compiler/rustc_monomorphize/src/collector.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ use rustc_target::abi::Size;
192192
use std::path::PathBuf;
193193

194194
use crate::errors::{
195-
EncounteredErrorWhileInstantiating, LargeAssignmentsLint, RecursionLimit, TypeLengthLimit,
195+
EncounteredErrorWhileInstantiating, LargeAssignmentsLint, NoOptimizedMir, RecursionLimit,
196+
TypeLengthLimit,
196197
};
197198

198199
#[derive(PartialEq)]
@@ -950,7 +951,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
950951
}
951952

952953
if !tcx.is_mir_available(def_id) {
953-
bug!("no MIR available for {:?}", def_id);
954+
tcx.sess.emit_fatal(NoOptimizedMir { def: tcx.def_path_str(def_id) });
954955
}
955956

956957
true

compiler/rustc_monomorphize/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ pub struct TypeLengthLimit {
3333
pub type_length: usize,
3434
}
3535

36+
#[derive(Diagnostic)]
37+
#[diag(monomorphize_no_optimized_mir)]
38+
pub struct NoOptimizedMir {
39+
pub def: String,
40+
}
41+
3642
pub struct UnusedGenericParamsHint {
3743
pub span: Span,
3844
pub param_spans: Vec<Span>,

tests/ui/rmeta/auxiliary/rmeta-meta.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
pub struct Foo {
77
pub field: i32,
88
}
9+
10+
pub fn missing_optimized_mir() {
11+
println!("indeed");
12+
}

tests/ui/rmeta/no_optitimized_mir.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:rmeta-meta.rs
2+
// no-prefer-dynamic
3+
// build-fail
4+
5+
// Check that we do not ICE when we need optimized MIR but it is missing.
6+
7+
extern crate rmeta_meta;
8+
9+
fn main() {
10+
rmeta_meta::missing_optimized_mir();
11+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: Optimized MIR unavailable for `missing_optimized_mir`. Was it compiled with just `--emit=metadata` and without `-Zalways-encode-mir`?
2+
3+
error: aborting due to previous error
4+

0 commit comments

Comments
 (0)