Skip to content

Commit 2305aad

Browse files
committed
Auto merge of rust-lang#131143 - workingjubilee:rollup-4ke1tor, r=workingjubilee
Rollup of 3 pull requests Successful merges: - rust-lang#130885 (panic when an interpreter error gets unintentionally discarded) - rust-lang#131108 (Revert rust-lang#131060 "Drop conditionally applied cargo `-Zon-broken-pipe=kill` flags") - rust-lang#131121 (A couple of fixes for dataflow graphviz dumps) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9e3e517 + cd084ab commit 2305aad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1589
-1355
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt;
2-
31
use rustc_data_structures::fx::FxIndexMap;
42
use rustc_data_structures::graph;
53
use rustc_index::bit_set::BitSet;
@@ -425,10 +423,6 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
425423
Borrows { tcx, body, borrow_set, borrows_out_of_scope_at_location }
426424
}
427425

428-
pub fn location(&self, idx: BorrowIndex) -> &Location {
429-
&self.borrow_set[idx].reserve_location
430-
}
431-
432426
/// Add all borrows to the kill set, if those borrows are out of scope at `location`.
433427
/// That means they went out of a nonlexical scope
434428
fn kill_loans_out_of_scope_at_location(
@@ -615,8 +609,4 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
615609
}
616610
}
617611

618-
impl DebugWithContext<Borrows<'_, '_>> for BorrowIndex {
619-
fn fmt_with(&self, ctxt: &Borrows<'_, '_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
620-
write!(f, "{:?}", ctxt.location(*self))
621-
}
622-
}
612+
impl<C> DebugWithContext<C> for BorrowIndex {}

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use rustc_middle::{bug, span_bug, ty};
66
use rustc_span::def_id::DefId;
77

88
use crate::interpret::{
9-
self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, throw_machine_stop,
9+
self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, interp_ok,
10+
throw_machine_stop,
1011
};
1112

1213
/// Macro for machine-specific `InterpError` without allocation.
@@ -79,7 +80,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
7980
throw_machine_stop_str!("can't access mutable globals in ConstProp");
8081
}
8182

82-
Ok(())
83+
interp_ok(())
8384
}
8485

8586
fn find_mir_or_eval_fn(
@@ -127,7 +128,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
127128
right: &interpret::ImmTy<'tcx, Self::Provenance>,
128129
) -> interpret::InterpResult<'tcx, ImmTy<'tcx, Self::Provenance>> {
129130
use rustc_middle::mir::BinOp::*;
130-
Ok(match bin_op {
131+
interp_ok(match bin_op {
131132
Eq | Ne | Lt | Le | Gt | Ge => {
132133
// Types can differ, e.g. fn ptrs with different `for`.
133134
assert_eq!(left.layout.abi, right.layout.abi);

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+31-22
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::const_eval::CheckAlignment;
2020
use crate::interpret::{
2121
CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpError,
2222
InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, StackPopCleanup, create_static_alloc,
23-
eval_nullary_intrinsic, intern_const_alloc_recursive, throw_exhaust,
23+
eval_nullary_intrinsic, intern_const_alloc_recursive, interp_ok, throw_exhaust,
2424
};
2525
use crate::{CTRL_C_RECEIVED, errors};
2626

@@ -98,19 +98,19 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
9898
return Err(ecx
9999
.tcx
100100
.dcx()
101-
.emit_err(errors::DanglingPtrInFinal { span: ecx.tcx.span, kind: intern_kind })
102-
.into());
101+
.emit_err(errors::DanglingPtrInFinal { span: ecx.tcx.span, kind: intern_kind }))
102+
.into();
103103
}
104104
Err(InternResult::FoundBadMutablePointer) => {
105105
return Err(ecx
106106
.tcx
107107
.dcx()
108-
.emit_err(errors::MutablePtrInFinal { span: ecx.tcx.span, kind: intern_kind })
109-
.into());
108+
.emit_err(errors::MutablePtrInFinal { span: ecx.tcx.span, kind: intern_kind }))
109+
.into();
110110
}
111111
}
112112

113-
Ok(R::make_result(ret, ecx))
113+
interp_ok(R::make_result(ret, ecx))
114114
}
115115

116116
/// The `InterpCx` is only meant to be used to do field and index projections into constants for
@@ -147,7 +147,8 @@ pub fn mk_eval_cx_for_const_val<'tcx>(
147147
ty: Ty<'tcx>,
148148
) -> Option<(CompileTimeInterpCx<'tcx>, OpTy<'tcx>)> {
149149
let ecx = mk_eval_cx_to_read_const_val(tcx.tcx, tcx.span, param_env, CanAccessMutGlobal::No);
150-
let op = ecx.const_val_to_op(val, ty, None).ok()?;
150+
// FIXME: is it a problem to discard the error here?
151+
let op = ecx.const_val_to_op(val, ty, None).discard_err()?;
151152
Some((ecx, op))
152153
}
153154

@@ -185,12 +186,16 @@ pub(super) fn op_to_const<'tcx>(
185186
_ => false,
186187
};
187188
let immediate = if force_as_immediate {
188-
match ecx.read_immediate(op) {
189+
match ecx.read_immediate(op).report_err() {
189190
Ok(imm) => Right(imm),
190-
Err(err) if !for_diagnostics => {
191-
panic!("normalization works on validated constants: {err:?}")
191+
Err(err) => {
192+
if for_diagnostics {
193+
// This discard the error, but for diagnostics that's okay.
194+
op.as_mplace_or_imm()
195+
} else {
196+
panic!("normalization works on validated constants: {err:?}")
197+
}
192198
}
193-
_ => op.as_mplace_or_imm(),
194199
}
195200
} else {
196201
op.as_mplace_or_imm()
@@ -283,17 +288,19 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
283288
let ty::FnDef(_, args) = ty.kind() else {
284289
bug!("intrinsic with type {:?}", ty);
285290
};
286-
return eval_nullary_intrinsic(tcx, key.param_env, def_id, args).map_err(|error| {
287-
let span = tcx.def_span(def_id);
288-
289-
super::report(
290-
tcx,
291-
error.into_kind(),
292-
span,
293-
|| (span, vec![]),
294-
|span, _| errors::NullaryIntrinsicError { span },
295-
)
296-
});
291+
return eval_nullary_intrinsic(tcx, key.param_env, def_id, args).report_err().map_err(
292+
|error| {
293+
let span = tcx.def_span(def_id);
294+
295+
super::report(
296+
tcx,
297+
error.into_kind(),
298+
span,
299+
|| (span, vec![]),
300+
|span, _| errors::NullaryIntrinsicError { span },
301+
)
302+
},
303+
);
297304
}
298305

299306
tcx.eval_to_allocation_raw(key).map(|val| turn_into_const_value(tcx, val, key))
@@ -376,6 +383,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
376383
);
377384
let res = ecx.load_mir(cid.instance.def, cid.promoted);
378385
res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, body))
386+
.report_err()
379387
.map_err(|error| report_eval_error(&ecx, cid, error))
380388
}
381389

@@ -400,6 +408,7 @@ fn const_validate_mplace<'tcx>(
400408
}
401409
};
402410
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)
411+
.report_err()
403412
// Instead of just reporting the `InterpError` via the usual machinery, we give a more targeted
404413
// error about the validation failure.
405414
.map_err(|error| report_validation_error(&ecx, cid, error, alloc_id))?;

0 commit comments

Comments
 (0)