Skip to content

Commit edbd02f

Browse files
committed
Queryify check_trait_item_well_formed
Fixes #46753
1 parent 86a123c commit edbd02f

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
@@ -580,6 +580,7 @@ define_dep_nodes!( <'tcx>
580580
[] IsNoBuiltins(CrateNum),
581581
[] ImplDefaultness(DefId),
582582
[] CheckItemWellFormed(DefId),
583+
[] CheckTraitItemWellFormed(DefId),
583584
[] ReachableNonGenerics(CrateNum),
584585
[] NativeLibraries(CrateNum),
585586
[] PluginRegistrarFn(CrateNum),

src/librustc/ty/maps/mod.rs

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

301301
[] fn check_item_well_formed: CheckItemWellFormed(DefId) -> (),
302+
[] fn check_trait_item_well_formed: CheckTraitItemWellFormed(DefId) -> (),
302303

303304
// The DefIds of all non-generic functions and statics in the given crate
304305
// 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
@@ -872,6 +872,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
872872
DepKind::IsNoBuiltins => { force!(is_no_builtins, krate!()); }
873873
DepKind::ImplDefaultness => { force!(impl_defaultness, def_id!()); }
874874
DepKind::CheckItemWellFormed => { force!(check_item_well_formed, def_id!()); }
875+
DepKind::CheckTraitItemWellFormed => { force!(check_trait_item_well_formed, def_id!()); }
875876
DepKind::ReachableNonGenerics => { force!(reachable_non_generics, krate!()); }
876877
DepKind::NativeLibraries => { force!(native_libraries, krate!()); }
877878
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)