Skip to content

Commit 0d4eb09

Browse files
committed
Auto merge of #154503 - RalfJung:rollup-DkU2JXL, r=RalfJung
Rollup of 11 pull requests Successful merges: - #152880 (Tweak incorrect assoc item note) - #153526 (Fix LegacyKeyValueFormat report from docker build: i686) - #153613 (interpreter error reporting: remove arguments that are always the same) - #154029 (Replace `truncate(0)` with `clear()`) - #154125 (Inline and remove `DepGraphData::try_mark_parent_green`.) - #154185 (Prevent no_threads RwLock's write() impl from setting mode to -1 when it is locked for reading) - #154394 (Normalize rustc path prefix when testing `-Z track-diagnostics`) - #154450 (Use the normal arg-parsing machinery for `-Zassert-incr-state`) - #154475 (Emit a pre-expansion feature gate warning for `box`'ed struct field patterns) - #154500 (EnumSizeOpt: use Allocation::write_scalar instead of manual endianess logic) - #154502 (interpret: ensure that untupled arguments are actually tuples)
2 parents 7e28c74 + c47e0e1 commit 0d4eb09

File tree

171 files changed

+786
-685
lines changed

Some content is hidden

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

171 files changed

+786
-685
lines changed

‎compiler/rustc_const_eval/src/const_eval/error.rs‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::{fmt, mem};
22

3-
use rustc_errors::Diag;
3+
use rustc_errors::{Diag, E0080};
44
use rustc_middle::mir::AssertKind;
55
use rustc_middle::mir::interpret::{
66
AllocId, Provenance, ReportedErrorInfo, UndefinedBehaviorInfo, UnsupportedOpInfo,
77
};
88
use rustc_middle::query::TyCtxtAt;
99
use rustc_middle::ty::ConstInt;
1010
use rustc_middle::ty::layout::LayoutError;
11-
use rustc_span::{Span, Symbol};
11+
use rustc_span::{DUMMY_SP, Span, Symbol};
1212

1313
use super::CompileTimeMachine;
1414
use crate::errors::{self, FrameNote};
@@ -164,36 +164,30 @@ pub fn get_span_and_frames<'tcx>(
164164
/// This will use the `mk` function for adding more information to the error.
165165
/// You can use it to add a stacktrace of current execution according to
166166
/// `get_span_and_frames` or just give context on where the const eval error happened.
167-
pub(super) fn report<'tcx, C, F>(
167+
pub(super) fn report<'tcx>(
168168
ecx: &InterpCx<'tcx, CompileTimeMachine<'tcx>>,
169169
error: InterpErrorKind<'tcx>,
170-
span: Span,
171-
get_span_and_frames: C,
172-
mk: F,
173-
) -> ErrorHandled
174-
where
175-
C: FnOnce() -> (Span, Vec<FrameNote>),
176-
F: FnOnce(&mut Diag<'_>, Span, Vec<FrameNote>),
177-
{
170+
mk: impl FnOnce(&mut Diag<'_>, Span, Vec<FrameNote>),
171+
) -> ErrorHandled {
178172
let tcx = ecx.tcx.tcx;
179173
// Special handling for certain errors
180174
match error {
181175
// Don't emit a new diagnostic for these errors, they are already reported elsewhere or
182176
// should remain silent.
183-
err_inval!(AlreadyReported(info)) => ErrorHandled::Reported(info, span),
177+
err_inval!(AlreadyReported(info)) => ErrorHandled::Reported(info, DUMMY_SP),
184178
err_inval!(Layout(LayoutError::TooGeneric(_))) | err_inval!(TooGeneric) => {
185-
ErrorHandled::TooGeneric(span)
179+
ErrorHandled::TooGeneric(DUMMY_SP)
186180
}
187181
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
188182
// This can occur in infallible promoteds e.g. when a non-existent type or field is
189183
// encountered.
190-
ErrorHandled::Reported(ReportedErrorInfo::allowed_in_infallible(guar), span)
184+
ErrorHandled::Reported(ReportedErrorInfo::allowed_in_infallible(guar), DUMMY_SP)
191185
}
192186
// Report remaining errors.
193187
_ => {
194-
let (our_span, frames) = get_span_and_frames();
195-
let span = span.substitute_dummy(our_span);
196-
let mut err = tcx.dcx().struct_span_err(our_span, error.to_string());
188+
let (span, frames) = super::get_span_and_frames(ecx.tcx, ecx.stack());
189+
let mut err = tcx.dcx().struct_span_err(span, error.to_string());
190+
err.code(E0080);
197191
if matches!(
198192
error,
199193
InterpErrorKind::UndefinedBehavior(UndefinedBehaviorInfo::ValidationError {

‎compiler/rustc_const_eval/src/const_eval/eval_queries.rs‎

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::sync::atomic::Ordering::Relaxed;
22

33
use either::{Left, Right};
44
use rustc_abi::{self as abi, BackendRepr};
5-
use rustc_errors::{E0080, msg};
65
use rustc_hir::def::DefKind;
76
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo};
87
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
@@ -11,8 +10,8 @@ use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout};
1110
use rustc_middle::ty::print::with_no_trimmed_paths;
1211
use rustc_middle::ty::{self, Ty, TyCtxt};
1312
use rustc_middle::{bug, throw_inval};
13+
use rustc_span::Span;
1414
use rustc_span::def_id::LocalDefId;
15-
use rustc_span::{DUMMY_SP, Span};
1615
use tracing::{debug, instrument, trace};
1716

1817
use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine};
@@ -458,32 +457,20 @@ fn report_eval_error<'tcx>(
458457
let (error, backtrace) = error.into_parts();
459458
backtrace.print_backtrace();
460459

461-
super::report(
462-
ecx,
463-
error,
464-
DUMMY_SP,
465-
|| super::get_span_and_frames(ecx.tcx, ecx.stack()),
466-
|diag, span, frames| {
467-
let num_frames = frames.len();
468-
// FIXME(oli-obk): figure out how to use structured diagnostics again.
469-
diag.code(E0080);
470-
diag.span_label(
471-
span,
472-
msg!(
473-
"evaluation of `{$instance}` failed {$num_frames ->
474-
[0] here
475-
*[other] inside this call
476-
}"
477-
),
478-
);
479-
for frame in frames {
480-
diag.subdiagnostic(frame);
481-
}
482-
// Add after the frame rendering above, as it adds its own `instance` args.
483-
diag.arg("instance", with_no_trimmed_paths!(cid.instance.to_string()));
484-
diag.arg("num_frames", num_frames);
485-
},
486-
)
460+
super::report(ecx, error, |diag, span, frames| {
461+
let num_frames = frames.len();
462+
diag.span_label(
463+
span,
464+
format!(
465+
"evaluation of `{instance}` failed {where_}",
466+
instance = with_no_trimmed_paths!(cid.instance.to_string()),
467+
where_ = if num_frames == 0 { "here" } else { "inside this call" },
468+
),
469+
);
470+
for frame in frames {
471+
diag.subdiagnostic(frame);
472+
}
473+
})
487474
}
488475

489476
#[inline(never)]
@@ -506,20 +493,10 @@ fn report_validation_error<'tcx>(
506493
let raw_bytes =
507494
errors::RawBytesNote { size: info.size.bytes(), align: info.align.bytes(), bytes };
508495

509-
crate::const_eval::report(
510-
ecx,
511-
error,
512-
DUMMY_SP,
513-
|| crate::const_eval::get_span_and_frames(ecx.tcx, ecx.stack()),
514-
move |diag, span, frames| {
515-
// FIXME(oli-obk): figure out how to use structured diagnostics again.
516-
diag.code(E0080);
517-
diag.span_label(span, "it is undefined behavior to use this value");
518-
diag.note("the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.");
519-
for frame in frames {
520-
diag.subdiagnostic(frame);
521-
}
522-
diag.subdiagnostic(raw_bytes);
523-
},
524-
)
496+
crate::const_eval::report(ecx, error, move |diag, span, frames| {
497+
diag.span_label(span, "it is undefined behavior to use this value");
498+
diag.note("the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.");
499+
assert!(frames.is_empty()); // we just report validation errors for the final const here
500+
diag.subdiagnostic(raw_bytes);
501+
})
525502
}

‎compiler/rustc_const_eval/src/interpret/call.rs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
6060
}
6161

6262
/// Helper function for argument untupling.
63-
pub(super) fn fn_arg_field(
63+
fn fn_arg_project_field(
6464
&self,
6565
arg: &FnArg<'tcx, M::Provenance>,
6666
field: FieldIdx,
@@ -655,12 +655,17 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
655655
if caller_abi == ExternAbi::RustCall && !args.is_empty() {
656656
// Untuple
657657
let (untuple_arg, args) = args.split_last().unwrap();
658+
let ty::Tuple(untuple_fields) = untuple_arg.layout().ty.kind() else {
659+
span_bug!(self.cur_span(), "untuple argument must be a tuple")
660+
};
658661
trace!("init_fn_call: Will pass last argument by untupling");
659662
Cow::from(
660663
args.iter()
664+
// The regular arguments.
661665
.map(|a| interp_ok(a.clone()))
662-
.chain((0..untuple_arg.layout().fields.count()).map(|i| {
663-
self.fn_arg_field(untuple_arg, FieldIdx::from_usize(i))
666+
// The fields of the untupled argument.
667+
.chain((0..untuple_fields.len()).map(|i| {
668+
self.fn_arg_project_field(untuple_arg, FieldIdx::from_usize(i))
664669
}))
665670
.collect::<InterpResult<'_, Vec<_>>>()?,
666671
)

‎compiler/rustc_data_structures/src/obligation_forest/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<O: ForestObligation> ObligationForest<O> {
702702
self.apply_rewrites(&node_rewrites);
703703
}
704704

705-
node_rewrites.truncate(0);
705+
node_rewrites.clear();
706706
self.reused_node_vec = node_rewrites;
707707
}
708708

‎compiler/rustc_hir_typeck/src/method/suggest.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,15 +1177,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11771177
let is_method = mode == Mode::MethodCall;
11781178
let item_kind = if is_method {
11791179
"method"
1180-
} else if rcvr_ty.is_enum() {
1181-
"variant or associated item"
1180+
} else if rcvr_ty.is_enum() || rcvr_ty.is_fresh_ty() {
1181+
"variant, associated function, or constant"
11821182
} else {
1183-
match (item_ident.as_str().chars().next(), rcvr_ty.is_fresh_ty()) {
1184-
(Some(name), false) if name.is_lowercase() => "function or associated item",
1185-
(Some(_), false) => "associated item",
1186-
(Some(_), true) | (None, false) => "variant or associated item",
1187-
(None, true) => "variant",
1188-
}
1183+
"associated function or constant"
11891184
};
11901185

11911186
if let Err(guar) = self.report_failed_method_call_on_numerical_infer_var(

‎compiler/rustc_incremental/src/persist/load.rs‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,8 @@ pub enum LoadResult<T> {
3838
impl<T: Default> LoadResult<T> {
3939
/// Accesses the data returned in [`LoadResult::Ok`].
4040
pub fn open(self, sess: &Session) -> T {
41-
// Check for errors when using `-Zassert-incremental-state`
42-
match (sess.opts.assert_incr_state, &self) {
43-
(Some(IncrementalStateAssertion::NotLoaded), LoadResult::Ok { .. }) => {
44-
sess.dcx().emit_fatal(errors::AssertNotLoaded);
45-
}
46-
(
47-
Some(IncrementalStateAssertion::Loaded),
48-
LoadResult::LoadDepGraph(..) | LoadResult::DataOutOfDate,
49-
) => {
50-
sess.dcx().emit_fatal(errors::AssertLoaded);
51-
}
52-
_ => {}
53-
};
41+
// Emit a fatal error if `-Zassert-incr-state` is present and unsatisfied.
42+
maybe_assert_incr_state(sess, &self);
5443

5544
match self {
5645
LoadResult::LoadDepGraph(path, err) => {
@@ -188,6 +177,32 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache> {
188177
}
189178
}
190179

180+
/// Emits a fatal error if the assertion in `-Zassert-incr-state` doesn't match
181+
/// the outcome of trying to load previous-session state.
182+
fn maybe_assert_incr_state(sess: &Session, load_result: &LoadResult<impl Sized>) {
183+
// Return immediately if there's nothing to assert.
184+
let Some(assertion) = sess.opts.unstable_opts.assert_incr_state else { return };
185+
186+
// Match exhaustively to make sure we don't miss any cases.
187+
let loaded = match load_result {
188+
LoadResult::Ok { .. } => true,
189+
LoadResult::DataOutOfDate | LoadResult::LoadDepGraph(..) => false,
190+
};
191+
192+
match assertion {
193+
IncrementalStateAssertion::Loaded => {
194+
if !loaded {
195+
sess.dcx().emit_fatal(errors::AssertLoaded);
196+
}
197+
}
198+
IncrementalStateAssertion::NotLoaded => {
199+
if loaded {
200+
sess.dcx().emit_fatal(errors::AssertNotLoaded)
201+
}
202+
}
203+
}
204+
}
205+
191206
/// Setups the dependency graph by loading an existing graph from disk and set up streaming of a
192207
/// new graph to an incremental session directory.
193208
pub fn setup_dep_graph(

‎compiler/rustc_interface/src/tests.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use rustc_hir::attrs::{CollapseMacroDebuginfo, NativeLibKind};
1212
use rustc_session::config::{
1313
AnnotateMoves, AutoDiff, BranchProtection, CFGuard, Cfg, CoverageLevel, CoverageOptions,
1414
DebugInfo, DumpMonoStatsFormat, ErrorOutputType, ExternEntry, ExternLocation, Externs,
15-
FmtDebug, FunctionReturn, InliningThreshold, Input, InstrumentCoverage, InstrumentXRay,
16-
LinkSelfContained, LinkerPluginLto, LocationDetail, LtoCli, MirIncludeSpans, NextSolverConfig,
17-
Offload, Options, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet, Passes,
18-
PatchableFunctionEntry, Polonius, ProcMacroExecutionStrategy, Strip, SwitchWithOptPath,
19-
SymbolManglingVersion, WasiExecModel, build_configuration, build_session_options,
20-
rustc_optgroups,
15+
FmtDebug, FunctionReturn, IncrementalStateAssertion, InliningThreshold, Input,
16+
InstrumentCoverage, InstrumentXRay, LinkSelfContained, LinkerPluginLto, LocationDetail, LtoCli,
17+
MirIncludeSpans, NextSolverConfig, Offload, Options, OutFileName, OutputType, OutputTypes,
18+
PAuthKey, PacRet, Passes, PatchableFunctionEntry, Polonius, ProcMacroExecutionStrategy, Strip,
19+
SwitchWithOptPath, SymbolManglingVersion, WasiExecModel, build_configuration,
20+
build_session_options, rustc_optgroups,
2121
};
2222
use rustc_session::lint::Level;
2323
use rustc_session::search_paths::SearchPath;
@@ -686,7 +686,7 @@ fn test_unstable_options_tracking_hash() {
686686

687687
// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
688688
// tidy-alphabetical-start
689-
untracked!(assert_incr_state, Some(String::from("loaded")));
689+
untracked!(assert_incr_state, Some(IncrementalStateAssertion::Loaded));
690690
untracked!(codegen_source_order, true);
691691
untracked!(deduplicate_diagnostics, false);
692692
untracked!(dump_dep_graph, true);

0 commit comments

Comments
 (0)