Skip to content

Commit ac77e35

Browse files
has_typeck_results doesnt need to be a query
1 parent 3493a56 commit ac77e35

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

compiler/rustc_hir_typeck/src/lib.rs

-16
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,6 @@ macro_rules! type_error_struct {
8484
})
8585
}
8686

87-
fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
88-
// Closures' typeck results come from their outermost function,
89-
// as they are part of the same "inference environment".
90-
let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
91-
if typeck_root_def_id != def_id {
92-
return tcx.has_typeck_results(typeck_root_def_id);
93-
}
94-
95-
if let Some(def_id) = def_id.as_local() {
96-
tcx.hir_node_by_def_id(def_id).body_id().is_some()
97-
} else {
98-
false
99-
}
100-
}
101-
10287
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDefId> {
10388
&tcx.typeck(def_id).used_trait_imports
10489
}
@@ -463,7 +448,6 @@ pub fn provide(providers: &mut Providers) {
463448
*providers = Providers {
464449
typeck,
465450
diagnostic_only_typeck,
466-
has_typeck_results,
467451
used_trait_imports,
468452
lookup_method_for_diagnostic: lookup_method_for_diagnostic,
469453
..*providers

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl<'tcx> LateContext<'tcx> {
741741
.filter(|typeck_results| typeck_results.hir_owner == id.owner)
742742
.or_else(|| {
743743
self.tcx
744-
.has_typeck_results(id.owner.to_def_id())
744+
.has_typeck_results(id.owner.def_id)
745745
.then(|| self.tcx.typeck(id.owner.def_id))
746746
})
747747
.and_then(|typeck_results| typeck_results.type_dependent_def(id))

compiler/rustc_middle/src/query/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,6 @@ rustc_queries! {
992992
cache_on_disk_if { true }
993993
}
994994

995-
query has_typeck_results(def_id: DefId) -> bool {
996-
desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
997-
}
998-
999995
query coherent_trait(def_id: DefId) -> Result<(), ErrorGuaranteed> {
1000996
desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
1001997
ensure_forwards_result_if_red

compiler/rustc_middle/src/ty/context.rs

+11
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,17 @@ impl CurrentGcx {
817817
}
818818

819819
impl<'tcx> TyCtxt<'tcx> {
820+
pub fn has_typeck_results(self, def_id: LocalDefId) -> bool {
821+
// Closures' typeck results come from their outermost function,
822+
// as they are part of the same "inference environment".
823+
let typeck_root_def_id = self.typeck_root_def_id(def_id.to_def_id());
824+
if typeck_root_def_id != def_id.to_def_id() {
825+
return self.has_typeck_results(typeck_root_def_id.expect_local());
826+
}
827+
828+
self.hir_node_by_def_id(def_id).body_id().is_some()
829+
}
830+
820831
/// Expects a body and returns its codegen attributes.
821832
///
822833
/// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for

src/tools/clippy/clippy_lints/src/functions/must_use.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
185185
if let hir::PatKind::Wild = pat.kind {
186186
return false; // ignore `_` patterns
187187
}
188-
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
188+
if cx.tcx.has_typeck_results(pat.hir_id.owner.def_id) {
189189
is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), tys)
190190
} else {
191191
false
@@ -233,7 +233,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo
233233
Call(_, args) => {
234234
let mut tys = DefIdSet::default();
235235
for arg in args {
236-
if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
236+
if cx.tcx.has_typeck_results(arg.hir_id.owner.def_id)
237237
&& is_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys)
238238
&& is_mutated_static(arg)
239239
{
@@ -246,7 +246,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo
246246
MethodCall(_, receiver, args, _) => {
247247
let mut tys = DefIdSet::default();
248248
for arg in std::iter::once(receiver).chain(args.iter()) {
249-
if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
249+
if cx.tcx.has_typeck_results(arg.hir_id.owner.def_id)
250250
&& is_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys)
251251
&& is_mutated_static(arg)
252252
{

0 commit comments

Comments
 (0)