Skip to content

Commit 8069f8d

Browse files
committed
Auto merge of #131934 - matthiaskrgr:rollup-pd3dwxu, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #127462 (std: uefi: Add basic Env variables) - #131537 (Fix range misleading field access) - #131838 (bootstrap: allow setting `--jobs` in config.toml) - #131890 (Update `use` keyword docs to describe precise capturing) - #131899 (Mark unexpected variant res suggestion as having placeholders) - #131908 (rustdoc: Switch from FxHash to sha256 for static file hashing.) - #131916 (small interpreter error cleanup) - #131919 (zero-sized accesses are fine on null pointers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a2a1206 + 7a6d436 commit 8069f8d

File tree

36 files changed

+396
-176
lines changed

36 files changed

+396
-176
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4584,6 +4584,7 @@ dependencies = [
45844584
"rustdoc-json-types",
45854585
"serde",
45864586
"serde_json",
4587+
"sha2",
45874588
"smallvec",
45884589
"tempfile",
45894590
"threadpool",

compiler/rustc_const_eval/src/const_eval/error.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use rustc_span::{Span, Symbol};
1111
use super::CompileTimeMachine;
1212
use crate::errors::{self, FrameNote, ReportErrorExt};
1313
use crate::interpret::{
14-
ErrorHandled, Frame, InterpError, InterpErrorInfo, MachineStopType, err_inval, err_machine_stop,
14+
ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType, err_inval,
15+
err_machine_stop,
1516
};
1617

1718
/// The CTFE machine has some custom error kinds.
@@ -57,7 +58,7 @@ impl MachineStopType for ConstEvalErrKind {
5758
}
5859
}
5960

60-
/// The errors become [`InterpError::MachineStop`] when being raised.
61+
/// The errors become [`InterpErrorKind::MachineStop`] when being raised.
6162
impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
6263
fn into(self) -> InterpErrorInfo<'tcx> {
6364
err_machine_stop!(self).into()
@@ -124,7 +125,7 @@ pub fn get_span_and_frames<'tcx>(
124125
/// `get_span_and_frames`.
125126
pub(super) fn report<'tcx, C, F, E>(
126127
tcx: TyCtxt<'tcx>,
127-
error: InterpError<'tcx>,
128+
error: InterpErrorKind<'tcx>,
128129
span: Span,
129130
get_span_and_frames: C,
130131
mk: F,

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::{debug, instrument, trace};
1818
use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine};
1919
use crate::const_eval::CheckAlignment;
2020
use crate::interpret::{
21-
CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpError,
21+
CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpErrorKind,
2222
InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, StackPopCleanup, create_static_alloc,
2323
eval_nullary_intrinsic, intern_const_alloc_recursive, interp_ok, throw_exhaust,
2424
};
@@ -463,7 +463,7 @@ fn report_validation_error<'tcx>(
463463
error: InterpErrorInfo<'tcx>,
464464
alloc_id: AllocId,
465465
) -> ErrorHandled {
466-
if !matches!(error.kind(), InterpError::UndefinedBehavior(_)) {
466+
if !matches!(error.kind(), InterpErrorKind::UndefinedBehavior(_)) {
467467
// Some other error happened during validation, e.g. an unsupported operation.
468468
return report_eval_error(ecx, cid, error);
469469
}

compiler/rustc_const_eval/src/errors.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::{
99
use rustc_hir::ConstContext;
1010
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
1111
use rustc_middle::mir::interpret::{
12-
CheckInAllocMsg, CtfeProvenance, ExpectedKind, InterpError, InvalidMetaKind,
12+
CheckInAllocMsg, CtfeProvenance, ExpectedKind, InterpErrorKind, InvalidMetaKind,
1313
InvalidProgramInfo, Misalignment, Pointer, PointerKind, ResourceExhaustionInfo,
1414
UndefinedBehaviorInfo, UnsupportedOpInfo, ValidationErrorInfo,
1515
};
@@ -835,23 +835,23 @@ impl ReportErrorExt for UnsupportedOpInfo {
835835
}
836836
}
837837

838-
impl<'tcx> ReportErrorExt for InterpError<'tcx> {
838+
impl<'tcx> ReportErrorExt for InterpErrorKind<'tcx> {
839839
fn diagnostic_message(&self) -> DiagMessage {
840840
match self {
841-
InterpError::UndefinedBehavior(ub) => ub.diagnostic_message(),
842-
InterpError::Unsupported(e) => e.diagnostic_message(),
843-
InterpError::InvalidProgram(e) => e.diagnostic_message(),
844-
InterpError::ResourceExhaustion(e) => e.diagnostic_message(),
845-
InterpError::MachineStop(e) => e.diagnostic_message(),
841+
InterpErrorKind::UndefinedBehavior(ub) => ub.diagnostic_message(),
842+
InterpErrorKind::Unsupported(e) => e.diagnostic_message(),
843+
InterpErrorKind::InvalidProgram(e) => e.diagnostic_message(),
844+
InterpErrorKind::ResourceExhaustion(e) => e.diagnostic_message(),
845+
InterpErrorKind::MachineStop(e) => e.diagnostic_message(),
846846
}
847847
}
848848
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
849849
match self {
850-
InterpError::UndefinedBehavior(ub) => ub.add_args(diag),
851-
InterpError::Unsupported(e) => e.add_args(diag),
852-
InterpError::InvalidProgram(e) => e.add_args(diag),
853-
InterpError::ResourceExhaustion(e) => e.add_args(diag),
854-
InterpError::MachineStop(e) => e.add_args(&mut |name, value| {
850+
InterpErrorKind::UndefinedBehavior(ub) => ub.add_args(diag),
851+
InterpErrorKind::Unsupported(e) => e.add_args(diag),
852+
InterpErrorKind::InvalidProgram(e) => e.add_args(diag),
853+
InterpErrorKind::ResourceExhaustion(e) => e.add_args(diag),
854+
InterpErrorKind::MachineStop(e) => e.add_args(&mut |name, value| {
855855
diag.arg(name, value);
856856
}),
857857
}

compiler/rustc_const_eval/src/interpret/call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
471471
// Don't forget to mark "initially live" locals as live.
472472
self.storage_live_for_always_live_locals()?;
473473
};
474-
res.inspect_err(|_| {
474+
res.inspect_err_kind(|_| {
475475
// Don't show the incomplete stack frame in the error stacktrace.
476476
self.stack_mut().pop();
477477
})

compiler/rustc_const_eval/src/interpret/eval_context.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_trait_selection::traits::ObligationCtxt;
1919
use tracing::{debug, instrument, trace};
2020

2121
use super::{
22-
Frame, FrameInfo, GlobalId, InterpError, InterpErrorInfo, InterpResult, MPlaceTy, Machine,
22+
Frame, FrameInfo, GlobalId, InterpErrorInfo, InterpErrorKind, InterpResult, MPlaceTy, Machine,
2323
MemPlaceMeta, Memory, OpTy, Place, PlaceTy, PointerArithmetic, Projectable, Provenance,
2424
err_inval, interp_ok, throw_inval, throw_ub, throw_ub_custom,
2525
};
@@ -73,7 +73,7 @@ where
7373
}
7474

7575
impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
76-
type LayoutOfResult = Result<TyAndLayout<'tcx>, InterpError<'tcx>>;
76+
type LayoutOfResult = Result<TyAndLayout<'tcx>, InterpErrorKind<'tcx>>;
7777

7878
#[inline]
7979
fn layout_tcx_at_span(&self) -> Span {
@@ -82,20 +82,25 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
8282
}
8383

8484
#[inline]
85-
fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> InterpError<'tcx> {
85+
fn handle_layout_err(
86+
&self,
87+
err: LayoutError<'tcx>,
88+
_: Span,
89+
_: Ty<'tcx>,
90+
) -> InterpErrorKind<'tcx> {
8691
err_inval!(Layout(err))
8792
}
8893
}
8994

9095
impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
91-
type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpError<'tcx>>;
96+
type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpErrorKind<'tcx>>;
9297

9398
fn handle_fn_abi_err(
9499
&self,
95100
err: FnAbiError<'tcx>,
96101
_span: Span,
97102
_fn_abi_request: FnAbiRequest<'tcx>,
98-
) -> InterpError<'tcx> {
103+
) -> InterpErrorKind<'tcx> {
99104
match err {
100105
FnAbiError::Layout(err) => err_inval!(Layout(err)),
101106
FnAbiError::AdjustForForeignAbi(err) => {

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
324324
dist.checked_neg().unwrap(), // i64::MIN is impossible as no allocation can be that large
325325
CheckInAllocMsg::OffsetFromTest,
326326
)
327-
.map_err(|_| {
327+
.map_err_kind(|_| {
328328
// Make the error more specific.
329329
err_ub_custom!(
330330
fluent::const_eval_offset_from_different_allocations,
331331
name = intrinsic_name,
332332
)
333-
.into()
334333
})?;
335334

336335
// Perform division by size to compute return value.

compiler/rustc_const_eval/src/interpret/validity.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use rustc_hir as hir;
1717
use rustc_middle::bug;
1818
use rustc_middle::mir::interpret::ValidationErrorKind::{self, *};
1919
use rustc_middle::mir::interpret::{
20-
ExpectedKind, InterpError, InterpErrorInfo, InvalidMetaKind, Misalignment, PointerKind,
21-
Provenance, UnsupportedOpInfo, ValidationErrorInfo, alloc_range, interp_ok,
20+
ExpectedKind, InterpErrorKind, InvalidMetaKind, Misalignment, PointerKind, Provenance,
21+
UnsupportedOpInfo, ValidationErrorInfo, alloc_range, interp_ok,
2222
};
2323
use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
2424
use rustc_middle::ty::{self, Ty};
@@ -37,8 +37,8 @@ use super::{
3737

3838
// for the validation errors
3939
#[rustfmt::skip]
40-
use super::InterpError::UndefinedBehavior as Ub;
41-
use super::InterpError::Unsupported as Unsup;
40+
use super::InterpErrorKind::UndefinedBehavior as Ub;
41+
use super::InterpErrorKind::Unsupported as Unsup;
4242
use super::UndefinedBehaviorInfo::*;
4343
use super::UnsupportedOpInfo::*;
4444

@@ -97,20 +97,19 @@ macro_rules! try_validation {
9797
($e:expr, $where:expr,
9898
$( $( $p:pat_param )|+ => $kind: expr ),+ $(,)?
9999
) => {{
100-
$e.map_err(|e| {
100+
$e.map_err_kind(|e| {
101101
// We catch the error and turn it into a validation failure. We are okay with
102102
// allocation here as this can only slow down builds that fail anyway.
103-
let (kind, backtrace) = e.into_parts();
104-
match kind {
103+
match e {
105104
$(
106105
$($p)|+ => {
107106
err_validation_failure!(
108107
$where,
109108
$kind
110-
).into()
109+
)
111110
}
112111
),+,
113-
_ => InterpErrorInfo::from_parts(kind, backtrace),
112+
e => e,
114113
}
115114
})?
116115
}};
@@ -1230,11 +1229,10 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
12301229
// No need for an alignment check here, this is not an actual memory access.
12311230
let alloc = self.ecx.get_ptr_alloc(mplace.ptr(), size)?.expect("we already excluded size 0");
12321231

1233-
alloc.get_bytes_strip_provenance().map_err(|err| {
1232+
alloc.get_bytes_strip_provenance().map_err_kind(|kind| {
12341233
// Some error happened, try to provide a more detailed description.
12351234
// For some errors we might be able to provide extra information.
12361235
// (This custom logic does not fit the `try_validation!` macro.)
1237-
let (kind, backtrace) = err.into_parts();
12381236
match kind {
12391237
Ub(InvalidUninitBytes(Some((_alloc_id, access)))) | Unsup(ReadPointerAsInt(Some((_alloc_id, access)))) => {
12401238
// Some byte was uninitialized, determine which
@@ -1247,14 +1245,14 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
12471245
self.path.push(PathElem::ArrayElem(i));
12481246

12491247
if matches!(kind, Ub(InvalidUninitBytes(_))) {
1250-
err_validation_failure!(self.path, Uninit { expected }).into()
1248+
err_validation_failure!(self.path, Uninit { expected })
12511249
} else {
1252-
err_validation_failure!(self.path, PointerAsInt { expected }).into()
1250+
err_validation_failure!(self.path, PointerAsInt { expected })
12531251
}
12541252
}
12551253

12561254
// Propagate upwards (that will also check for unexpected errors).
1257-
_ => return InterpErrorInfo::from_parts(kind, backtrace),
1255+
err => err,
12581256
}
12591257
})?;
12601258

@@ -1368,12 +1366,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
13681366
v.reset_padding(val)?;
13691367
interp_ok(())
13701368
})
1371-
.map_err(|err| {
1369+
.map_err_info(|err| {
13721370
if !matches!(
13731371
err.kind(),
13741372
err_ub!(ValidationError { .. })
1375-
| InterpError::InvalidProgram(_)
1376-
| InterpError::Unsupported(UnsupportedOpInfo::ExternTypeField)
1373+
| InterpErrorKind::InvalidProgram(_)
1374+
| InterpErrorKind::Unsupported(UnsupportedOpInfo::ExternTypeField)
13771375
) {
13781376
bug!(
13791377
"Unexpected error during validation: {}",

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn report_unexpected_variant_res(
419419
}
420420
}
421421

422-
err.multipart_suggestion_verbose(descr, suggestion, Applicability::MaybeIncorrect);
422+
err.multipart_suggestion_verbose(descr, suggestion, Applicability::HasPlaceholders);
423423
err
424424
}
425425
Res::Def(DefKind::Variant, _) if expr.is_none() => {

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable};
1818
use rustc_target::abi::{Align, HasDataLayout, Size};
1919

2020
use super::{
21-
AllocId, BadBytesAccess, CtfeProvenance, InterpError, InterpResult, Pointer, PointerArithmetic,
22-
Provenance, ResourceExhaustionInfo, Scalar, ScalarSizeMismatch, UndefinedBehaviorInfo,
23-
UnsupportedOpInfo, interp_ok, read_target_uint, write_target_uint,
21+
AllocId, BadBytesAccess, CtfeProvenance, InterpErrorKind, InterpResult, Pointer,
22+
PointerArithmetic, Provenance, ResourceExhaustionInfo, Scalar, ScalarSizeMismatch,
23+
UndefinedBehaviorInfo, UnsupportedOpInfo, interp_ok, read_target_uint, write_target_uint,
2424
};
2525
use crate::ty;
2626

@@ -199,22 +199,22 @@ impl From<ScalarSizeMismatch> for AllocError {
199199
}
200200

201201
impl AllocError {
202-
pub fn to_interp_error<'tcx>(self, alloc_id: AllocId) -> InterpError<'tcx> {
202+
pub fn to_interp_error<'tcx>(self, alloc_id: AllocId) -> InterpErrorKind<'tcx> {
203203
use AllocError::*;
204204
match self {
205205
ScalarSizeMismatch(s) => {
206-
InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ScalarSizeMismatch(s))
206+
InterpErrorKind::UndefinedBehavior(UndefinedBehaviorInfo::ScalarSizeMismatch(s))
207207
}
208-
ReadPointerAsInt(info) => InterpError::Unsupported(
208+
ReadPointerAsInt(info) => InterpErrorKind::Unsupported(
209209
UnsupportedOpInfo::ReadPointerAsInt(info.map(|b| (alloc_id, b))),
210210
),
211-
OverwritePartialPointer(offset) => InterpError::Unsupported(
211+
OverwritePartialPointer(offset) => InterpErrorKind::Unsupported(
212212
UnsupportedOpInfo::OverwritePartialPointer(Pointer::new(alloc_id, offset)),
213213
),
214-
ReadPartialPointer(offset) => InterpError::Unsupported(
214+
ReadPartialPointer(offset) => InterpErrorKind::Unsupported(
215215
UnsupportedOpInfo::ReadPartialPointer(Pointer::new(alloc_id, offset)),
216216
),
217-
InvalidUninitBytes(info) => InterpError::UndefinedBehavior(
217+
InvalidUninitBytes(info) => InterpErrorKind::UndefinedBehavior(
218218
UndefinedBehaviorInfo::InvalidUninitBytes(info.map(|b| (alloc_id, b))),
219219
),
220220
}
@@ -318,7 +318,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
318318
pub fn try_uninit<'tcx>(size: Size, align: Align) -> InterpResult<'tcx, Self> {
319319
Self::uninit_inner(size, align, || {
320320
ty::tls::with(|tcx| tcx.dcx().delayed_bug("exhausted memory during interpretation"));
321-
InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted)
321+
InterpErrorKind::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted)
322322
})
323323
.into()
324324
}

0 commit comments

Comments
 (0)