Skip to content

Commit 157fa85

Browse files
committed
Auto merge of #153935 - Zalathar:rollup-GAx1kXU, r=Zalathar
Rollup of 7 pull requests Successful merges: - #153639 (Remove `QueryInfo`.) - #153570 (MaybeUninit: mention common mistakes in assume_init docs; link to validity invariant docs) - #153793 (Add overview documentation for `std::mem`.) - #153922 (rustc_mir_build only depends on rustc_lint_defs, not rustc_lint) - #153923 (run_make_support: Print the command and output even if it succeeds) - #153925 (Provide better suggestions for inference errors on `.collect()?`) - #153928 (remove several redundant tests)
2 parents 1e21831 + ace15f2 commit 157fa85

File tree

25 files changed

+385
-194
lines changed

25 files changed

+385
-194
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4344,7 +4344,7 @@ dependencies = [
43444344
"rustc_hir",
43454345
"rustc_index",
43464346
"rustc_infer",
4347-
"rustc_lint",
4347+
"rustc_lint_defs",
43484348
"rustc_macros",
43494349
"rustc_middle",
43504350
"rustc_pattern_analysis",

compiler/rustc_middle/src/query/job.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,8 @@ use parking_lot::{Condvar, Mutex};
77
use rustc_span::Span;
88

99
use crate::query::plumbing::CycleError;
10-
use crate::query::stack::QueryStackFrame;
1110
use crate::ty::TyCtxt;
1211

13-
/// Represents a span and a query key.
14-
#[derive(Clone, Debug)]
15-
pub struct QueryInfo<'tcx> {
16-
/// The span corresponding to the reason for which this query was required.
17-
pub span: Span,
18-
pub frame: QueryStackFrame<'tcx>,
19-
}
20-
2112
/// A value uniquely identifying an active query job.
2213
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
2314
pub struct QueryJobId(pub NonZero<u64>);

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::def_id::LocalDefId;
22

33
pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCache};
4-
pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryWaiter};
4+
pub use self::job::{QueryJob, QueryJobId, QueryLatch, QueryWaiter};
55
pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey};
66
pub use self::plumbing::{
77
ActiveKeyStatus, CycleError, EnsureMode, IntoQueryParam, QueryMode, QueryState, TyCtxtAt,

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
88
use rustc_errors::Diag;
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_hir::hir_id::OwnerId;
11-
use rustc_span::Span;
11+
use rustc_span::{Span, Spanned};
1212
pub use sealed::IntoQueryParam;
1313

1414
use crate::dep_graph::{DepKind, DepNodeIndex, SerializedDepNodeIndex};
1515
use crate::ich::StableHashingContext;
1616
use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables, TaggedQueryKey};
1717
use crate::query::on_disk_cache::OnDiskCache;
1818
use crate::query::stack::QueryStackFrame;
19-
use crate::query::{QueryCache, QueryInfo, QueryJob};
19+
use crate::query::{QueryCache, QueryJob};
2020
use crate::ty::TyCtxt;
2121

2222
/// For a particular query, keeps track of "active" keys, i.e. keys whose
@@ -50,11 +50,13 @@ pub enum ActiveKeyStatus<'tcx> {
5050
Poisoned,
5151
}
5252

53-
#[derive(Clone, Debug)]
53+
#[derive(Debug)]
5454
pub struct CycleError<'tcx> {
5555
/// The query and related span that uses the cycle.
56-
pub usage: Option<(Span, QueryStackFrame<'tcx>)>,
57-
pub cycle: Vec<QueryInfo<'tcx>>,
56+
pub usage: Option<Spanned<QueryStackFrame<'tcx>>>,
57+
58+
/// The span here corresponds to the reason for which this query was required.
59+
pub cycle: Vec<Spanned<QueryStackFrame<'tcx>>>,
5860
}
5961

6062
#[derive(Debug)]

compiler/rustc_mir_build/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rustc_errors = { path = "../rustc_errors" }
1515
rustc_hir = { path = "../rustc_hir" }
1616
rustc_index = { path = "../rustc_index" }
1717
rustc_infer = { path = "../rustc_infer" }
18-
rustc_lint = { path = "../rustc_lint" }
18+
rustc_lint_defs = { path = "../rustc_lint_defs" }
1919
rustc_macros = { path = "../rustc_macros" }
2020
rustc_middle = { path = "../rustc_middle" }
2121
rustc_pattern_analysis = { path = "../rustc_pattern_analysis" }

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::def::*;
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, MatchSource};
1010
use rustc_infer::infer::TyCtxtInferExt;
11-
use rustc_lint::Level;
11+
use rustc_lint_defs::Level;
1212
use rustc_middle::bug;
1313
use rustc_middle::thir::visit::Visitor;
1414
use rustc_middle::thir::*;

compiler/rustc_mir_build/src/thir/pattern/migration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, pluralize};
55
use rustc_hir::{BindingMode, ByRef, HirId, Mutability};
6-
use rustc_lint as lint;
6+
use rustc_lint_defs::builtin::RUST_2024_INCOMPATIBLE_PAT;
77
use rustc_middle::ty::{self, Rust2024IncompatiblePatInfo, TyCtxt};
88
use rustc_span::{Ident, Span};
99

@@ -56,7 +56,7 @@ impl<'a> PatMigration<'a> {
5656
err.emit();
5757
} else {
5858
tcx.emit_node_span_lint(
59-
lint::builtin::RUST_2024_INCOMPATIBLE_PAT,
59+
RUST_2024_INCOMPATIBLE_PAT,
6060
pat_id,
6161
spans,
6262
rustc_errors::DiagDecorator(|diag| {

compiler/rustc_query_impl/src/from_cycle_error.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ fn fn_sig<'tcx>(
7676
fn check_representability<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError<'tcx>) -> ! {
7777
let mut item_and_field_ids = Vec::new();
7878
let mut representable_ids = FxHashSet::default();
79-
for info in &cycle_error.cycle {
80-
if info.frame.dep_kind == DepKind::check_representability
81-
&& let Some(field_id) = info.frame.def_id
79+
for frame in &cycle_error.cycle {
80+
if frame.node.dep_kind == DepKind::check_representability
81+
&& let Some(field_id) = frame.node.def_id
8282
&& let Some(field_id) = field_id.as_local()
83-
&& let Some(DefKind::Field) = info.frame.tagged_key.def_kind(tcx)
83+
&& let Some(DefKind::Field) = frame.node.tagged_key.def_kind(tcx)
8484
{
8585
let parent_id = tcx.parent(field_id.to_def_id());
8686
let item_id = match tcx.def_kind(parent_id) {
@@ -90,8 +90,8 @@ fn check_representability<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError<'tcx>
9090
item_and_field_ids.push((item_id.expect_local(), field_id));
9191
}
9292
}
93-
for info in &cycle_error.cycle {
94-
if let TaggedQueryKey::check_representability_adt_ty(key) = info.frame.tagged_key
93+
for frame in &cycle_error.cycle {
94+
if let TaggedQueryKey::check_representability_adt_ty(key) = frame.node.tagged_key
9595
&& let Some(adt) = key.ty_adt_def()
9696
&& let Some(def_id) = adt.did().as_local()
9797
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
@@ -109,9 +109,9 @@ fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError<'tcx>) -> &'tcx
109109
search_for_cycle_permutation(
110110
&cycle_error.cycle,
111111
|cycle| {
112-
if let Some(info) = cycle.get(0)
113-
&& info.frame.dep_kind == DepKind::variances_of
114-
&& let Some(def_id) = info.frame.def_id
112+
if let Some(frame) = cycle.get(0)
113+
&& frame.node.dep_kind == DepKind::variances_of
114+
&& let Some(def_id) = frame.node.def_id
115115
{
116116
let n = tcx.generics_of(def_id).own_params.len();
117117
ControlFlow::Break(tcx.arena.alloc_from_iter(iter::repeat_n(ty::Bivariant, n)))
@@ -121,7 +121,7 @@ fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError<'tcx>) -> &'tcx
121121
},
122122
|| {
123123
span_bug!(
124-
cycle_error.usage.as_ref().unwrap().0,
124+
cycle_error.usage.as_ref().unwrap().span,
125125
"only `variances_of` returns `&[ty::Variance]`"
126126
)
127127
},
@@ -154,7 +154,7 @@ fn layout_of<'tcx>(
154154
let diag = search_for_cycle_permutation(
155155
&cycle_error.cycle,
156156
|cycle| {
157-
if let TaggedQueryKey::layout_of(key) = cycle[0].frame.tagged_key
157+
if let TaggedQueryKey::layout_of(key) = cycle[0].node.tagged_key
158158
&& let ty::Coroutine(def_id, _) = key.value.kind()
159159
&& let Some(def_id) = def_id.as_local()
160160
&& let def_kind = tcx.def_kind(def_id)
@@ -178,8 +178,8 @@ fn layout_of<'tcx>(
178178
tcx.def_kind_descr_article(def_kind, def_id.to_def_id()),
179179
tcx.def_kind_descr(def_kind, def_id.to_def_id()),
180180
);
181-
for (i, info) in cycle.iter().enumerate() {
182-
let TaggedQueryKey::layout_of(frame_key) = info.frame.tagged_key else {
181+
for (i, frame) in cycle.iter().enumerate() {
182+
let TaggedQueryKey::layout_of(frame_key) = frame.node.tagged_key else {
183183
continue;
184184
};
185185
let &ty::Coroutine(frame_def_id, _) = frame_key.value.kind() else {
@@ -189,7 +189,7 @@ fn layout_of<'tcx>(
189189
continue;
190190
};
191191
let frame_span =
192-
info.frame.tagged_key.default_span(tcx, cycle[(i + 1) % cycle.len()].span);
192+
frame.node.tagged_key.default_span(tcx, cycle[(i + 1) % cycle.len()].span);
193193
if frame_span.is_dummy() {
194194
continue;
195195
}

compiler/rustc_query_impl/src/job.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_errors::{Diag, DiagCtxtHandle};
88
use rustc_hir::def::DefKind;
99
use rustc_middle::query::{
10-
CycleError, QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryStackFrame, QueryWaiter,
10+
CycleError, QueryJob, QueryJobId, QueryLatch, QueryStackFrame, QueryWaiter,
1111
};
1212
use rustc_middle::ty::TyCtxt;
13-
use rustc_span::{DUMMY_SP, Span};
13+
use rustc_span::{DUMMY_SP, Span, respan};
1414

1515
use crate::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
1616

@@ -64,7 +64,7 @@ pub(crate) fn find_cycle_in_stack<'tcx>(
6464

6565
while let Some(job) = current_job {
6666
let info = &job_map.map[&job];
67-
cycle.push(QueryInfo { span: info.job.span, frame: info.frame.clone() });
67+
cycle.push(respan(info.job.span, info.frame.clone()));
6868

6969
if job == id {
7070
cycle.reverse();
@@ -77,7 +77,7 @@ pub(crate) fn find_cycle_in_stack<'tcx>(
7777
// Find out why the cycle itself was used
7878
let usage = try {
7979
let parent = info.job.parent?;
80-
(info.job.span, job_map.frame_of(parent).clone())
80+
respan(info.job.span, job_map.frame_of(parent).clone())
8181
};
8282
return CycleError { usage, cycle };
8383
}
@@ -313,14 +313,14 @@ fn remove_cycle<'tcx>(
313313

314314
let usage = entry_point
315315
.query_waiting_on_cycle
316-
.map(|(span, job)| (span, job_map.frame_of(job).clone()));
316+
.map(|(span, job)| respan(span, job_map.frame_of(job).clone()));
317317

318318
// Create the cycle error
319319
let error = CycleError {
320320
usage,
321321
cycle: stack
322322
.iter()
323-
.map(|&(span, job)| QueryInfo { span, frame: job_map.frame_of(job).clone() })
323+
.map(|&(span, job)| respan(span, job_map.frame_of(job).clone()))
324324
.collect(),
325325
};
326326

@@ -454,41 +454,40 @@ pub(crate) fn report_cycle<'tcx>(
454454
) -> Diag<'tcx> {
455455
assert!(!stack.is_empty());
456456

457-
let span = stack[0].frame.tagged_key.default_span(tcx, stack[1 % stack.len()].span);
457+
let span = stack[0].node.tagged_key.default_span(tcx, stack[1 % stack.len()].span);
458458

459459
let mut cycle_stack = Vec::new();
460460

461461
use crate::error::StackCount;
462-
let stack_bottom = stack[0].frame.tagged_key.description(tcx);
462+
let stack_bottom = stack[0].node.tagged_key.description(tcx);
463463
let stack_count = if stack.len() == 1 {
464464
StackCount::Single { stack_bottom: stack_bottom.clone() }
465465
} else {
466466
StackCount::Multiple { stack_bottom: stack_bottom.clone() }
467467
};
468468

469469
for i in 1..stack.len() {
470-
let frame = &stack[i].frame;
471-
let span = frame.tagged_key.default_span(tcx, stack[(i + 1) % stack.len()].span);
472-
cycle_stack
473-
.push(crate::error::CycleStack { span, desc: frame.tagged_key.description(tcx) });
470+
let node = &stack[i].node;
471+
let span = node.tagged_key.default_span(tcx, stack[(i + 1) % stack.len()].span);
472+
cycle_stack.push(crate::error::CycleStack { span, desc: node.tagged_key.description(tcx) });
474473
}
475474

476475
let mut cycle_usage = None;
477-
if let Some((span, ref query)) = *usage {
476+
if let Some(usage) = usage {
478477
cycle_usage = Some(crate::error::CycleUsage {
479-
span: query.tagged_key.default_span(tcx, span),
480-
usage: query.tagged_key.description(tcx),
478+
span: usage.node.tagged_key.default_span(tcx, usage.span),
479+
usage: usage.node.tagged_key.description(tcx),
481480
});
482481
}
483482

484483
let alias = if stack
485484
.iter()
486-
.all(|entry| matches!(entry.frame.tagged_key.def_kind(tcx), Some(DefKind::TyAlias)))
485+
.all(|entry| matches!(entry.node.tagged_key.def_kind(tcx), Some(DefKind::TyAlias)))
487486
{
488487
Some(crate::error::Alias::Ty)
489488
} else if stack
490489
.iter()
491-
.all(|entry| entry.frame.tagged_key.def_kind(tcx) == Some(DefKind::TraitAlias))
490+
.all(|entry| entry.node.tagged_key.def_kind(tcx) == Some(DefKind::TraitAlias))
492491
{
493492
Some(crate::error::Alias::Trait)
494493
} else {

0 commit comments

Comments
 (0)