Skip to content

Commit e58e32c

Browse files
committedFeb 21, 2024·
Merge check_mod_impl_wf and check_mod_type_wf
1 parent 0987e41 commit e58e32c

File tree

61 files changed

+703
-241
lines changed

Some content is hidden

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

61 files changed

+703
-241
lines changed
 

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

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
248248
let header = tcx.impl_trait_header(def_id);
249249
let is_auto = header
250250
.is_some_and(|header| tcx.trait_is_auto(header.skip_binder().trait_ref.def_id));
251+
252+
crate::impl_wf_check::check_impl_wf(tcx, def_id)?;
251253
let mut res = Ok(());
252254
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
253255
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);

‎compiler/rustc_hir_analysis/src/impl_wf_check.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use min_specialization::check_min_specialization;
1414
use rustc_data_structures::fx::FxHashSet;
1515
use rustc_errors::{codes::*, struct_span_code_err};
1616
use rustc_hir::def::DefKind;
17-
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
18-
use rustc_middle::query::Providers;
17+
use rustc_hir::def_id::LocalDefId;
1918
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
2019
use rustc_span::{ErrorGuaranteed, Span, Symbol};
2120

@@ -51,23 +50,16 @@ mod min_specialization;
5150
/// impl<'a> Trait<Foo> for Bar { type X = &'a i32; }
5251
/// // ^ 'a is unused and appears in assoc type, error
5352
/// ```
54-
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) -> Result<(), ErrorGuaranteed> {
53+
pub fn check_impl_wf(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
5554
let min_specialization = tcx.features().min_specialization;
56-
let module = tcx.hir_module_items(module_def_id);
5755
let mut res = Ok(());
58-
for id in module.items() {
59-
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. }) {
60-
res = res.and(enforce_impl_params_are_constrained(tcx, id.owner_id.def_id));
61-
if min_specialization {
62-
res = res.and(check_min_specialization(tcx, id.owner_id.def_id));
63-
}
64-
}
56+
debug_assert!(matches!(tcx.def_kind(impl_def_id), DefKind::Impl { .. }));
57+
res = res.and(enforce_impl_params_are_constrained(tcx, impl_def_id));
58+
if min_specialization {
59+
res = res.and(check_min_specialization(tcx, impl_def_id));
6560
}
66-
res
67-
}
6861

69-
pub fn provide(providers: &mut Providers) {
70-
*providers = Providers { check_mod_impl_wf, ..*providers };
62+
res
7163
}
7264

7365
fn enforce_impl_params_are_constrained(

0 commit comments

Comments
 (0)