Skip to content

Commit 36aca3d

Browse files
committed
Auto merge of #151687 - JonathanBrouwer:rollup-b6J6AJQ, r=JonathanBrouwer
Rollup of 4 pull requests Successful merges: - #151137 (checksum-freshness: Fix invalid checksum calculation for binary files) - #148187 (Remove uses of `&mut CmResolver`) - #151626 (Remove `Deref<Target = TyCtxt>` from `QueryCtxt`) - #151661 (Suggest changing `iter`/`into_iter` when the other was meant)
2 parents 4742769 + 8e3aece commit 36aca3d

15 files changed

Lines changed: 173 additions & 52 deletions

File tree

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,15 @@ fn load_binary_file(
275275
}
276276
};
277277
match cx.source_map().load_binary_file(&resolved_path) {
278-
Ok(data) => Ok(data),
278+
Ok(data) => {
279+
cx.sess
280+
.psess
281+
.file_depinfo
282+
.borrow_mut()
283+
.insert(Symbol::intern(&resolved_path.to_string_lossy()));
284+
285+
Ok(data)
286+
}
279287
Err(io_err) => {
280288
let mut err = cx.dcx().struct_span_err(
281289
macro_span,

compiler/rustc_interface/src/passes.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_ast::{self as ast, CRATE_NODE_ID};
99
use rustc_attr_parsing::{AttributeParser, Early, ShouldEmit};
1010
use rustc_codegen_ssa::traits::CodegenBackend;
1111
use rustc_codegen_ssa::{CodegenResults, CrateInfo};
12+
use rustc_data_structures::indexmap::IndexMap;
1213
use rustc_data_structures::jobserver::Proxy;
1314
use rustc_data_structures::steal::Steal;
1415
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal};
@@ -584,7 +585,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
584585
let result: io::Result<()> = try {
585586
// Build a list of files used to compile the output and
586587
// write Makefile-compatible dependency rules
587-
let mut files: Vec<(String, u64, Option<SourceFileHash>)> = sess
588+
let mut files: IndexMap<String, (u64, Option<SourceFileHash>)> = sess
588589
.source_map()
589590
.files()
590591
.iter()
@@ -593,10 +594,12 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
593594
.map(|fmap| {
594595
(
595596
escape_dep_filename(&fmap.name.prefer_local_unconditionally().to_string()),
596-
// This needs to be unnormalized,
597-
// as external tools wouldn't know how rustc normalizes them
598-
fmap.unnormalized_source_len as u64,
599-
fmap.checksum_hash,
597+
(
598+
// This needs to be unnormalized,
599+
// as external tools wouldn't know how rustc normalizes them
600+
fmap.unnormalized_source_len as u64,
601+
fmap.checksum_hash,
602+
),
600603
)
601604
})
602605
.collect();
@@ -614,7 +617,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
614617
fn hash_iter_files<P: AsRef<Path>>(
615618
it: impl Iterator<Item = P>,
616619
checksum_hash_algo: Option<SourceFileHashAlgorithm>,
617-
) -> impl Iterator<Item = (P, u64, Option<SourceFileHash>)> {
620+
) -> impl Iterator<Item = (P, (u64, Option<SourceFileHash>))> {
618621
it.map(move |path| {
619622
match checksum_hash_algo.and_then(|algo| {
620623
fs::File::open(path.as_ref())
@@ -630,8 +633,8 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
630633
})
631634
.ok()
632635
}) {
633-
Some((file_len, checksum)) => (path, file_len, Some(checksum)),
634-
None => (path, 0, None),
636+
Some((file_len, checksum)) => (path, (file_len, Some(checksum))),
637+
None => (path, (0, None)),
635638
}
636639
})
637640
}
@@ -705,18 +708,14 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
705708
file,
706709
"{}: {}\n",
707710
path.display(),
708-
files
709-
.iter()
710-
.map(|(path, _file_len, _checksum_hash_algo)| path.as_str())
711-
.intersperse(" ")
712-
.collect::<String>()
711+
files.keys().map(String::as_str).intersperse(" ").collect::<String>()
713712
)?;
714713
}
715714

716715
// Emit a fake target for each input file to the compilation. This
717716
// prevents `make` from spitting out an error if a file is later
718717
// deleted. For more info see #28735
719-
for (path, _file_len, _checksum_hash_algo) in &files {
718+
for path in files.keys() {
720719
writeln!(file, "{path}:")?;
721720
}
722721

@@ -745,7 +744,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
745744
if sess.opts.unstable_opts.checksum_hash_algorithm().is_some() {
746745
files
747746
.iter()
748-
.filter_map(|(path, file_len, hash_algo)| {
747+
.filter_map(|(path, (file_len, hash_algo))| {
749748
hash_algo.map(|hash_algo| (path, file_len, hash_algo))
750749
})
751750
.try_for_each(|(path, file_len, checksum_hash)| {

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use rustc_span::def_id::LOCAL_CRATE;
3535

3636
use crate::QueryConfigRestored;
3737

38+
/// Implements [`QueryContext`] for use by [`rustc_query_system`], since that
39+
/// crate does not have direct access to [`TyCtxt`].
3840
#[derive(Copy, Clone)]
3941
pub struct QueryCtxt<'tcx> {
4042
pub tcx: TyCtxt<'tcx>,
@@ -47,15 +49,6 @@ impl<'tcx> QueryCtxt<'tcx> {
4749
}
4850
}
4951

50-
impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
51-
type Target = TyCtxt<'tcx>;
52-
53-
#[inline]
54-
fn deref(&self) -> &Self::Target {
55-
&self.tcx
56-
}
57-
}
58-
5952
impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
6053
type Deps = rustc_middle::dep_graph::DepsType;
6154
type DepContext = TyCtxt<'tcx>;
@@ -69,14 +62,16 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
6962
impl QueryContext for QueryCtxt<'_> {
7063
#[inline]
7164
fn jobserver_proxy(&self) -> &Proxy {
72-
&*self.jobserver_proxy
65+
&self.tcx.jobserver_proxy
7366
}
7467

7568
#[inline]
7669
fn next_job_id(self) -> QueryJobId {
7770
QueryJobId(
78-
NonZero::new(self.query_system.jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
79-
.unwrap(),
71+
NonZero::new(
72+
self.tcx.query_system.jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
73+
)
74+
.unwrap(),
8075
)
8176
}
8277

@@ -113,7 +108,8 @@ impl QueryContext for QueryCtxt<'_> {
113108
self,
114109
prev_dep_node_index: SerializedDepNodeIndex,
115110
) -> Option<QuerySideEffect> {
116-
self.query_system
111+
self.tcx
112+
.query_system
117113
.on_disk_cache
118114
.as_ref()
119115
.and_then(|c| c.load_side_effect(self.tcx, prev_dep_node_index))
@@ -122,7 +118,7 @@ impl QueryContext for QueryCtxt<'_> {
122118
#[inline(never)]
123119
#[cold]
124120
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect) {
125-
if let Some(c) = self.query_system.on_disk_cache.as_ref() {
121+
if let Some(c) = self.tcx.query_system.on_disk_cache.as_ref() {
126122
c.store_side_effect(dep_node_index, side_effect)
127123
}
128124
}
@@ -140,7 +136,9 @@ impl QueryContext for QueryCtxt<'_> {
140136
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
141137
// when accessing the `ImplicitCtxt`.
142138
tls::with_related_context(self.tcx, move |current_icx| {
143-
if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) {
139+
if depth_limit
140+
&& !self.tcx.recursion_limit().value_within_limit(current_icx.query_depth)
141+
{
144142
self.depth_limit_error(token);
145143
}
146144

@@ -161,16 +159,16 @@ impl QueryContext for QueryCtxt<'_> {
161159
let query_map = self.collect_active_jobs(true).expect("failed to collect active queries");
162160
let (info, depth) = job.find_dep_kind_root(query_map);
163161

164-
let suggested_limit = match self.recursion_limit() {
162+
let suggested_limit = match self.tcx.recursion_limit() {
165163
Limit(0) => Limit(2),
166164
limit => limit * 2,
167165
};
168166

169-
self.sess.dcx().emit_fatal(QueryOverflow {
167+
self.tcx.sess.dcx().emit_fatal(QueryOverflow {
170168
span: info.job.span,
171169
note: QueryOverflowNote { desc: info.query.description, depth },
172170
suggested_limit,
173-
crate_name: self.crate_name(LOCAL_CRATE),
171+
crate_name: self.tcx.crate_name(LOCAL_CRATE),
174172
});
175173
}
176174
}
@@ -367,7 +365,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
367365
Q: super::QueryConfigRestored<'tcx>,
368366
Q::RestoredValue: Encodable<CacheEncoder<'a, 'tcx>>,
369367
{
370-
let _timer = qcx.profiler().generic_activity_with_arg("encode_query_results_for", query.name());
368+
let _timer = qcx.tcx.prof.generic_activity_with_arg("encode_query_results_for", query.name());
371369

372370
assert!(query.query_state(qcx).all_inactive());
373371
let cache = query.query_cache(qcx);
@@ -389,8 +387,7 @@ pub(crate) fn query_key_hash_verify<'tcx>(
389387
query: impl QueryConfig<QueryCtxt<'tcx>>,
390388
qcx: QueryCtxt<'tcx>,
391389
) {
392-
let _timer =
393-
qcx.profiler().generic_activity_with_arg("query_key_hash_verify_for", query.name());
390+
let _timer = qcx.tcx.prof.generic_activity_with_arg("query_key_hash_verify_for", query.name());
394391

395392
let mut map = UnordMap::default();
396393

compiler/rustc_resolve/src/ident.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
5858
orig_ctxt: Span,
5959
derive_fallback_lint_id: Option<NodeId>,
6060
mut visitor: impl FnMut(
61-
&mut CmResolver<'r, 'ra, 'tcx>,
61+
CmResolver<'_, 'ra, 'tcx>,
6262
Scope<'ra>,
6363
UsePrelude,
6464
Span,
@@ -165,7 +165,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
165165
if visit {
166166
let use_prelude = if use_prelude { UsePrelude::Yes } else { UsePrelude::No };
167167
if let ControlFlow::Break(break_result) =
168-
visitor(&mut self, scope, use_prelude, ctxt)
168+
visitor(self.reborrow(), scope, use_prelude, ctxt)
169169
{
170170
return Some(break_result);
171171
}
@@ -438,7 +438,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
438438
parent_scope,
439439
orig_ident.span,
440440
derive_fallback_lint_id,
441-
|this, scope, use_prelude, ctxt| {
441+
|mut this, scope, use_prelude, ctxt| {
442442
let ident = Ident::new(orig_ident.name, ctxt);
443443
// The passed `ctxt` is already normalized, so avoid expensive double normalization.
444444
let ident = Macros20NormalizedIdent(ident);

compiler/rustc_resolve/src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
893893
};
894894

895895
let mut indeterminate_count = 0;
896-
self.per_ns_cm(|this, ns| {
896+
self.per_ns_cm(|mut this, ns| {
897897
if !type_ns_only || ns == TypeNS {
898898
if bindings[ns].get() != PendingDecl::Pending {
899899
return;

compiler/rustc_resolve/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,13 +1831,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18311831
f(self, MacroNS);
18321832
}
18331833

1834-
fn per_ns_cm<'r, F: FnMut(&mut CmResolver<'r, 'ra, 'tcx>, Namespace)>(
1834+
fn per_ns_cm<'r, F: FnMut(CmResolver<'_, 'ra, 'tcx>, Namespace)>(
18351835
mut self: CmResolver<'r, 'ra, 'tcx>,
18361836
mut f: F,
18371837
) {
1838-
f(&mut self, TypeNS);
1839-
f(&mut self, ValueNS);
1840-
f(&mut self, MacroNS);
1838+
f(self.reborrow(), TypeNS);
1839+
f(self.reborrow(), ValueNS);
1840+
f(self, MacroNS);
18411841
}
18421842

18431843
fn is_builtin_macro(&self, res: Res) -> bool {
@@ -1902,7 +1902,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19021902
}
19031903

19041904
let scope_set = ScopeSet::All(TypeNS);
1905-
self.cm().visit_scopes(scope_set, parent_scope, ctxt, None, |this, scope, _, _| {
1905+
self.cm().visit_scopes(scope_set, parent_scope, ctxt, None, |mut this, scope, _, _| {
19061906
match scope {
19071907
Scope::ModuleNonGlobs(module, _) => {
19081908
this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ symbols! {
270270
Into,
271271
IntoFuture,
272272
IntoIterator,
273+
IntoIteratorItem,
273274
IoBufRead,
274275
IoLines,
275276
IoRead,

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4390,6 +4390,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
43904390
param_env: ty::ParamEnv<'tcx>,
43914391
path_segment: &hir::PathSegment<'_>,
43924392
args: &[hir::Expr<'_>],
4393+
prev_ty: Ty<'_>,
43934394
err: &mut Diag<'_, G>,
43944395
) {
43954396
let tcx = self.tcx;
@@ -4403,6 +4404,47 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44034404
let TypeError::Sorts(expected_found) = diff else {
44044405
continue;
44054406
};
4407+
if tcx.is_diagnostic_item(sym::IntoIteratorItem, *def_id)
4408+
&& path_segment.ident.name == sym::iter
4409+
&& self.can_eq(
4410+
param_env,
4411+
Ty::new_ref(
4412+
tcx,
4413+
tcx.lifetimes.re_erased,
4414+
expected_found.found,
4415+
ty::Mutability::Not,
4416+
),
4417+
*ty,
4418+
)
4419+
&& let [] = args
4420+
{
4421+
// Used `.iter()` when `.into_iter()` was likely meant.
4422+
err.span_suggestion_verbose(
4423+
path_segment.ident.span,
4424+
format!("consider consuming the `{prev_ty}` to construct the `Iterator`"),
4425+
"into_iter".to_string(),
4426+
Applicability::MachineApplicable,
4427+
);
4428+
}
4429+
if tcx.is_diagnostic_item(sym::IntoIteratorItem, *def_id)
4430+
&& path_segment.ident.name == sym::into_iter
4431+
&& self.can_eq(
4432+
param_env,
4433+
expected_found.found,
4434+
Ty::new_ref(tcx, tcx.lifetimes.re_erased, *ty, ty::Mutability::Not),
4435+
)
4436+
&& let [] = args
4437+
{
4438+
// Used `.into_iter()` when `.iter()` was likely meant.
4439+
err.span_suggestion_verbose(
4440+
path_segment.ident.span,
4441+
format!(
4442+
"consider not consuming the `{prev_ty}` to construct the `Iterator`"
4443+
),
4444+
"iter".to_string(),
4445+
Applicability::MachineApplicable,
4446+
);
4447+
}
44064448
if tcx.is_diagnostic_item(sym::IteratorItem, *def_id)
44074449
&& path_segment.ident.name == sym::map
44084450
&& self.can_eq(param_env, expected_found.found, *ty)
@@ -4515,19 +4557,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
45154557
expr = rcvr_expr;
45164558
let assocs_in_this_method =
45174559
self.probe_assoc_types_at_expr(&type_diffs, span, prev_ty, expr.hir_id, param_env);
4560+
prev_ty = self.resolve_vars_if_possible(
4561+
typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(Ty::new_misc_error(tcx)),
4562+
);
45184563
self.look_for_iterator_item_mistakes(
45194564
&assocs_in_this_method,
45204565
typeck_results,
45214566
&type_diffs,
45224567
param_env,
45234568
path_segment,
45244569
args,
4570+
prev_ty,
45254571
err,
45264572
);
45274573
assocs.push(assocs_in_this_method);
4528-
prev_ty = self.resolve_vars_if_possible(
4529-
typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(Ty::new_misc_error(tcx)),
4530-
);
45314574

45324575
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
45334576
&& let hir::Path { res: Res::Local(hir_id), .. } = path

library/core/src/iter/traits/collect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ pub trait FromIterator<A>: Sized {
281281
#[stable(feature = "rust1", since = "1.0.0")]
282282
pub trait IntoIterator {
283283
/// The type of the elements being iterated over.
284+
#[rustc_diagnostic_item = "IntoIteratorItem"]
284285
#[stable(feature = "rust1", since = "1.0.0")]
285286
type Item;
286287

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
binary�

0 commit comments

Comments
 (0)