Skip to content

Emit error instead of ICE when optimized MIR is missing #115353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_monomorphize/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ monomorphize_large_assignments =
.label = value moved from here
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

monomorphize_no_optimized_mir =
missing optimized MIR for an item in the crate `{$crate_name}`
.note = missing optimized MIR for this item (was the crate `{$crate_name}` compiled with `--emit=metadata`?)

monomorphize_recursion_limit =
reached the recursion limit while instantiating `{$shrunk}`
.note = `{$def_path_str}` defined here
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_monomorphize/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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>,
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/rmeta/auxiliary/rmeta-meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
pub struct Foo {
pub field: i32,
}

pub fn missing_optimized_mir() {
println!("indeed");
}
11 changes: 11 additions & 0 deletions tests/ui/rmeta/no_optitimized_mir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// aux-build:rmeta-meta.rs
// no-prefer-dynamic
// build-fail

// Check that we do not ICE when we need optimized MIR but it is missing.

extern crate rmeta_meta;

fn main() {
rmeta_meta::missing_optimized_mir();
}
10 changes: 10 additions & 0 deletions tests/ui/rmeta/no_optitimized_mir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: missing optimized MIR for an item in the crate `rmeta_meta`
|
note: missing optimized MIR for this item (was the crate `rmeta_meta` compiled with `--emit=metadata`?)
--> $DIR/auxiliary/rmeta-meta.rs:10:1
|
LL | pub fn missing_optimized_mir() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error