Skip to content

Commit 25baba1

Browse files
committed
Queryify check_trait_item_well_formed
Fixes #46753
1 parent 5dfb4bb commit 25baba1

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ define_dep_nodes!( <'tcx>
576576
[] IsNoBuiltins(CrateNum),
577577
[] ImplDefaultness(DefId),
578578
[] CheckItemWellFormed(DefId),
579+
[] CheckTraitItemWellFormed(DefId),
579580
[] ReachableNonGenerics(CrateNum),
580581
[] NativeLibraries(CrateNum),
581582
[] PluginRegistrarFn(CrateNum),

src/librustc/ty/maps/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ define_maps! { <'tcx>
293293
[] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
294294

295295
[] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
296+
[] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
296297

297298
// The DefIds of all non-generic functions and statics in the given crate
298299
// that can be reached from outside the crate.

src/librustc/ty/maps/plumbing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
870870
DepKind::IsNoBuiltins => { force!(is_no_builtins, krate!()); }
871871
DepKind::ImplDefaultness => { force!(impl_defaultness, def_id!()); }
872872
DepKind::CheckItemWellFormed => { force!(check_item_well_formed, def_id!()); }
873+
DepKind::CheckTraitItemWellFormed => { force!(check_trait_item_well_formed, def_id!()); }
873874
DepKind::ReachableNonGenerics => { force!(reachable_non_generics, krate!()); }
874875
DepKind::NativeLibraries => { force!(native_libraries, krate!()); }
875876
DepKind::PluginRegistrarFn => { force!(plugin_registrar_fn, krate!()); }

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
722722
wfcheck::CheckTypeWellFormed::new(tcx).check_item_well_formed(def_id);
723723
}
724724

725+
fn check_trait_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
726+
wfcheck::CheckTypeWellFormed::new(tcx).check_trait_item(def_id);
727+
}
728+
725729
pub fn provide(providers: &mut Providers) {
726730
*providers = Providers {
727731
typeck_item_bodies,
@@ -730,6 +734,7 @@ pub fn provide(providers: &mut Providers) {
730734
adt_destructor,
731735
used_trait_imports,
732736
check_item_well_formed,
737+
check_trait_item_well_formed,
733738
..*providers
734739
};
735740
}

src/librustc_typeck/check/wfcheck.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ impl<'a, 'gcx> CheckTypeWellFormed<'a, 'gcx> {
159159
}
160160
}
161161

162+
pub fn check_trait_item(&mut self, def_id: DefId) {
163+
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
164+
let trait_item = self.tcx.hir.expect_trait_item(node_id);
165+
166+
let method_sig = match trait_item.node {
167+
hir::TraitItemKind::Method(ref sig, _) => Some(sig),
168+
_ => None
169+
};
170+
CheckTypeWellFormed::new(self.tcx)
171+
.check_associated_item(trait_item.id, trait_item.span, method_sig);
172+
}
173+
162174
fn check_associated_item(&mut self,
163175
item_id: ast::NodeId,
164176
span: Span,
@@ -675,12 +687,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'a, 'tcx> {
675687

676688
fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) {
677689
debug!("visit_trait_item: {:?}", trait_item);
678-
let method_sig = match trait_item.node {
679-
hir::TraitItemKind::Method(ref sig, _) => Some(sig),
680-
_ => None
681-
};
682-
CheckTypeWellFormed::new(self.tcx)
683-
.check_associated_item(trait_item.id, trait_item.span, method_sig);
690+
let def_id = self.tcx.hir.local_def_id(trait_item.id);
691+
ty::maps::queries::check_trait_item_well_formed::ensure(self.tcx, def_id);
684692
intravisit::walk_trait_item(self, trait_item)
685693
}
686694

0 commit comments

Comments
 (0)