Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a18f043
Add regression test
oli-obk Apr 23, 2024
c24148e
Allow coercing functions whose signature differs in opaque types in t…
oli-obk Apr 23, 2024
72968e5
Rename `FrameworkOnlyWindows` to `RawDylibOnlyWindows`
tbu- May 22, 2024
711338b
rustc: Use `tcx.used_crates(())` more
petrochenkov May 10, 2024
8369dbb
Use correct param-env in MissingCopyImplementations
compiler-errors May 22, 2024
c24d1c7
Rewrite `core-no-oom-handling` as rmake.rs
Oneirical May 22, 2024
d4e5426
rewrite and rename `issue-24445` to rmake
Oneirical May 22, 2024
ae49dbe
Cleanup: Fix up some diagnostics
fmease May 17, 2024
1f17e27
Rewrite and rename `issue-38237` to rmake
Oneirical May 22, 2024
3ac1a80
Remove unneeded string conversion
tbu- May 23, 2024
301c8de
Add regression tests
oli-obk May 23, 2024
4cf34cb
Allow const eval failures if the cause is a type layout issue
oli-obk Apr 29, 2024
abcf400
Rollup merge of #124297 - oli-obk:define_opaque_types13, r=jackh726
matthiaskrgr May 23, 2024
eb6b35b
Rollup merge of #124516 - oli-obk:taint_const_eval, r=RalfJung
matthiaskrgr May 23, 2024
eda4a35
Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk
matthiaskrgr May 23, 2024
337987b
Rollup merge of #125210 - fmease:fix-up-some-diags, r=davidtwco
matthiaskrgr May 23, 2024
c9e457d
Rollup merge of #125409 - tbu-:pr_raw_dylib_only_windows, r=lcnr
matthiaskrgr May 23, 2024
e713b2a
Rollup merge of #125416 - compiler-errors:param-env-missing-copy, r=lcnr
matthiaskrgr May 23, 2024
eb1b9b0
Rollup merge of #125421 - Oneirical:bundle-them-yet-again, r=jieyouxu
matthiaskrgr May 23, 2024
cf92f4c
Rollup merge of #125438 - tbu-:pr_rm_to_string_lossy, r=jieyouxu
matthiaskrgr May 23, 2024
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
Prev Previous commit
Next Next commit
Allow const eval failures if the cause is a type layout issue
  • Loading branch information
oli-obk committed May 23, 2024
commit 4cf34cb75268d13a3ec08476058e96fb5b1c1eef
9 changes: 5 additions & 4 deletions compiler/rustc_const_eval/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem;

use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagArg};
use rustc_hir::CRATE_HIR_ID;
use rustc_middle::mir::interpret::Provenance;
use rustc_middle::mir::interpret::{Provenance, ReportedErrorInfo};
use rustc_middle::mir::AssertKind;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -139,9 +139,10 @@ where
ErrorHandled::TooGeneric(span)
}
err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar, span),
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
ErrorHandled::Reported(guar.into(), span)
}
err_inval!(Layout(LayoutError::ReferencesError(guar))) => ErrorHandled::Reported(
ReportedErrorInfo::tainted_by_errors(guar),
span,
),
// Report remaining errors.
_ => {
let (our_span, frames) = get_span_and_frames();
Expand Down
17 changes: 14 additions & 3 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
let const_val = val.eval(*ecx.tcx, ecx.param_env, span).map_err(|err| {
if M::ALL_CONSTS_ARE_PRECHECKED && !matches!(err, ErrorHandled::TooGeneric(..)) {
// Looks like the const is not captued by `required_consts`, that's bad.
bug!("interpret const eval failure of {val:?} which is not in required_consts");
if M::ALL_CONSTS_ARE_PRECHECKED {
match err {
ErrorHandled::TooGeneric(..) => {},
ErrorHandled::Reported(reported, span) => {
if reported.is_tainted_by_errors() {
// const-eval will return "tainted" errors if e.g. the layout cannot
// be computed as the type references non-existing names.
// See <https://github.com/rust-lang/rust/issues/124348>.
} else {
// Looks like the const is not captued by `required_consts`, that's bad.
span_bug!(span, "interpret const eval failure of {val:?} which is not in required_consts");
}
}
}
}
err.emit_note(*ecx.tcx);
err
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ impl ReportedErrorInfo {
pub fn tainted_by_errors(error: ErrorGuaranteed) -> ReportedErrorInfo {
ReportedErrorInfo { is_tainted_by_errors: true, error }
}
pub fn is_tainted_by_errors(&self) -> bool {
self.is_tainted_by_errors
}
}

impl From<ErrorGuaranteed> for ReportedErrorInfo {
Expand Down
7 changes: 0 additions & 7 deletions tests/crashes/124348.rs

This file was deleted.

12 changes: 12 additions & 0 deletions tests/ui/consts/erroneous_type_in_const_return_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! ICE test #124348
//! We should not be running const eval if the layout has errors.

enum Eek {
TheConst,
UnusedByTheConst(Sum),
//~^ ERROR cannot find type `Sum` in this scope
}

const EEK_ZERO: &[Eek] = &[];

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/consts/erroneous_type_in_const_return_value.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0412]: cannot find type `Sum` in this scope
--> $DIR/erroneous_type_in_const_return_value.rs:6:22
|
LL | UnusedByTheConst(Sum),
| ^^^ not found in this scope
|
help: consider importing this trait
|
LL + use std::iter::Sum;
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
14 changes: 0 additions & 14 deletions tests/ui/consts/erroneous_type_in_promoted.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ help: consider importing this trait
LL + use std::iter::Sum;
|

note: erroneous constant encountered
--> $DIR/erroneous_type_in_promoted.rs:11:29
|
LL | let x: &'static [Eek] = &[];
| ^^^

note: erroneous constant encountered
--> $DIR/erroneous_type_in_promoted.rs:11:29
|
LL | let x: &'static [Eek] = &[];
| ^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.