Skip to content

Commit b5471fa

Browse files
authored
Unrolled build for rust-lang#124516
Rollup merge of rust-lang#124516 - oli-obk:taint_const_eval, r=RalfJung Allow monomorphization time const eval failures if the cause is a type layout issue r? `@RalfJung` fixes rust-lang#124348
2 parents 39d2f2a + 4cf34cb commit b5471fa

File tree

8 files changed

+76
-14
lines changed

8 files changed

+76
-14
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::mem;
22

33
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagArg};
44
use rustc_hir::CRATE_HIR_ID;
5-
use rustc_middle::mir::interpret::Provenance;
5+
use rustc_middle::mir::interpret::{Provenance, ReportedErrorInfo};
66
use rustc_middle::mir::AssertKind;
77
use rustc_middle::query::TyCtxtAt;
88
use rustc_middle::ty::TyCtxt;
@@ -139,9 +139,10 @@ where
139139
ErrorHandled::TooGeneric(span)
140140
}
141141
err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar, span),
142-
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
143-
ErrorHandled::Reported(guar.into(), span)
144-
}
142+
err_inval!(Layout(LayoutError::ReferencesError(guar))) => ErrorHandled::Reported(
143+
ReportedErrorInfo::tainted_by_errors(guar),
144+
span,
145+
),
145146
// Report remaining errors.
146147
_ => {
147148
let (our_span, frames) = get_span_and_frames();

compiler/rustc_const_eval/src/interpret/eval_context.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11811181
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
11821182
M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
11831183
let const_val = val.eval(*ecx.tcx, ecx.param_env, span).map_err(|err| {
1184-
if M::ALL_CONSTS_ARE_PRECHECKED && !matches!(err, ErrorHandled::TooGeneric(..)) {
1185-
// Looks like the const is not captued by `required_consts`, that's bad.
1186-
bug!("interpret const eval failure of {val:?} which is not in required_consts");
1184+
if M::ALL_CONSTS_ARE_PRECHECKED {
1185+
match err {
1186+
ErrorHandled::TooGeneric(..) => {},
1187+
ErrorHandled::Reported(reported, span) => {
1188+
if reported.is_tainted_by_errors() {
1189+
// const-eval will return "tainted" errors if e.g. the layout cannot
1190+
// be computed as the type references non-existing names.
1191+
// See <https://github.com/rust-lang/rust/issues/124348>.
1192+
} else {
1193+
// Looks like the const is not captued by `required_consts`, that's bad.
1194+
span_bug!(span, "interpret const eval failure of {val:?} which is not in required_consts");
1195+
}
1196+
}
1197+
}
11871198
}
11881199
err.emit_note(*ecx.tcx);
11891200
err

compiler/rustc_middle/src/mir/interpret/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ impl ReportedErrorInfo {
6666
pub fn tainted_by_errors(error: ErrorGuaranteed) -> ReportedErrorInfo {
6767
ReportedErrorInfo { is_tainted_by_errors: true, error }
6868
}
69+
pub fn is_tainted_by_errors(&self) -> bool {
70+
self.is_tainted_by_errors
71+
}
6972
}
7073

7174
impl From<ErrorGuaranteed> for ReportedErrorInfo {

tests/crashes/124348.rs

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! ICE test #124348
2+
//! We should not be running const eval if the layout has errors.
3+
4+
enum Eek {
5+
TheConst,
6+
UnusedByTheConst(Sum),
7+
//~^ ERROR cannot find type `Sum` in this scope
8+
}
9+
10+
const EEK_ZERO: &[Eek] = &[];
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0412]: cannot find type `Sum` in this scope
2+
--> $DIR/erroneous_type_in_const_return_value.rs:6:22
3+
|
4+
LL | UnusedByTheConst(Sum),
5+
| ^^^ not found in this scope
6+
|
7+
help: consider importing this trait
8+
|
9+
LL + use std::iter::Sum;
10+
|
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0412`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! ICE test #124348
2+
//! We should not be running const eval if the layout has errors.
3+
4+
enum Eek {
5+
TheConst,
6+
UnusedByTheConst(Sum),
7+
//~^ ERROR cannot find type `Sum` in this scope
8+
}
9+
10+
const fn foo() {
11+
let x: &'static [Eek] = &[];
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0412]: cannot find type `Sum` in this scope
2+
--> $DIR/erroneous_type_in_promoted.rs:6:22
3+
|
4+
LL | UnusedByTheConst(Sum),
5+
| ^^^ not found in this scope
6+
|
7+
help: consider importing this trait
8+
|
9+
LL + use std::iter::Sum;
10+
|
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)