Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae50e36

Browse files
committedMar 7, 2024
Merge collect_mod_item_types query into check_well_formed
1 parent 42ab88d commit ae50e36

File tree

67 files changed

+1033
-1104
lines changed

Some content is hidden

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

67 files changed

+1033
-1104
lines changed
 

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::autoderef::Autoderef;
2+
use crate::collect::CollectItemTypesVisitor;
23
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
34
use crate::errors;
45

6+
use hir::intravisit::Visitor;
57
use rustc_ast as ast;
68
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
79
use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, ErrorGuaranteed};
@@ -225,6 +227,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
225227
?item.owner_id,
226228
item.name = ? tcx.def_path_str(def_id)
227229
);
230+
CollectItemTypesVisitor { tcx }.visit_item(item);
228231

229232
let res = match item.kind {
230233
// Right now we check that every default trait implementation
@@ -336,9 +339,14 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
336339
res
337340
}
338341

339-
fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) -> Result<(), ErrorGuaranteed> {
342+
fn check_foreign_item<'tcx>(
343+
tcx: TyCtxt<'tcx>,
344+
item: &'tcx hir::ForeignItem<'tcx>,
345+
) -> Result<(), ErrorGuaranteed> {
340346
let def_id = item.owner_id.def_id;
341347

348+
CollectItemTypesVisitor { tcx }.visit_foreign_item(item);
349+
342350
debug!(
343351
?item.owner_id,
344352
item.name = ? tcx.def_path_str(def_id)
@@ -355,12 +363,14 @@ fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) -> Result<()
355363
}
356364
}
357365

358-
fn check_trait_item(
359-
tcx: TyCtxt<'_>,
360-
trait_item: &hir::TraitItem<'_>,
366+
fn check_trait_item<'tcx>(
367+
tcx: TyCtxt<'tcx>,
368+
trait_item: &'tcx hir::TraitItem<'tcx>,
361369
) -> Result<(), ErrorGuaranteed> {
362370
let def_id = trait_item.owner_id.def_id;
363371

372+
CollectItemTypesVisitor { tcx }.visit_trait_item(trait_item);
373+
364374
let (method_sig, span) = match trait_item.kind {
365375
hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span),
366376
hir::TraitItemKind::Type(_bounds, Some(ty)) => (None, ty.span),
@@ -895,7 +905,12 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
895905
}
896906
}
897907

898-
fn check_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) -> Result<(), ErrorGuaranteed> {
908+
fn check_impl_item<'tcx>(
909+
tcx: TyCtxt<'tcx>,
910+
impl_item: &'tcx hir::ImplItem<'tcx>,
911+
) -> Result<(), ErrorGuaranteed> {
912+
CollectItemTypesVisitor { tcx }.visit_impl_item(impl_item);
913+
899914
let (method_sig, span) = match impl_item.kind {
900915
hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span),
901916
// Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`.

‎compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_data_structures::unord::UnordMap;
2020
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey};
2121
use rustc_hir as hir;
2222
use rustc_hir::def::DefKind;
23-
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
23+
use rustc_hir::def_id::{DefId, LocalDefId};
2424
use rustc_hir::intravisit::{self, Visitor};
2525
use rustc_hir::{GenericParamKind, Node};
2626
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@@ -52,22 +52,6 @@ mod resolve_bound_vars;
5252
mod type_of;
5353

5454
///////////////////////////////////////////////////////////////////////////
55-
// Main entry point
56-
57-
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
58-
let items = tcx.hir_module_items(module_def_id);
59-
let hir = tcx.hir();
60-
let _ = items.par_items(|item| Ok(CollectItemTypesVisitor { tcx }.visit_item(hir.item(item))));
61-
let _ = items.par_impl_items(|item| {
62-
Ok(CollectItemTypesVisitor { tcx }.visit_impl_item(hir.impl_item(item)))
63-
});
64-
let _ = items.par_trait_items(|item| {
65-
Ok(CollectItemTypesVisitor { tcx }.visit_trait_item(hir.trait_item(item)))
66-
});
67-
let _ = items.par_foreign_items(|item| {
68-
Ok(CollectItemTypesVisitor { tcx }.visit_foreign_item(hir.foreign_item(item)))
69-
});
70-
}
7155

7256
pub fn provide(providers: &mut Providers) {
7357
resolve_bound_vars::provide(providers);
@@ -93,7 +77,6 @@ pub fn provide(providers: &mut Providers) {
9377
impl_trait_header,
9478
coroutine_kind,
9579
coroutine_for_closure,
96-
collect_mod_item_types,
9780
is_type_alias_impl_trait,
9881
find_field,
9982
..*providers
@@ -166,8 +149,8 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector {
166149
}
167150
}
168151

169-
struct CollectItemTypesVisitor<'tcx> {
170-
tcx: TyCtxt<'tcx>,
152+
pub struct CollectItemTypesVisitor<'tcx> {
153+
pub tcx: TyCtxt<'tcx>,
171154
}
172155

173156
/// If there are any placeholder types (`_`), emit an error explaining that this is not allowed

0 commit comments

Comments
 (0)
Please sign in to comment.