Skip to content

Commit a77f76e

Browse files
committed
Auto merge of rust-lang#123992 - compiler-errors:no-has-typeck-results, r=jackh726
`has_typeck_results` doesnt need to be a query self-explanatory
2 parents aca749e + 6abf1aa commit a77f76e

File tree

5 files changed

+17
-31
lines changed

5 files changed

+17
-31
lines changed

compiler/rustc_hir_typeck/src/lib.rs

+2-23
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use rustc_middle::query::Providers;
6666
use rustc_middle::traits;
6767
use rustc_middle::ty::{self, Ty, TyCtxt};
6868
use rustc_session::config;
69-
use rustc_span::def_id::{DefId, LocalDefId};
69+
use rustc_span::def_id::LocalDefId;
7070
use rustc_span::Span;
7171

7272
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
@@ -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
}
@@ -429,11 +414,5 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
429414

430415
pub fn provide(providers: &mut Providers) {
431416
method::provide(providers);
432-
*providers = Providers {
433-
typeck,
434-
diagnostic_only_typeck,
435-
has_typeck_results,
436-
used_trait_imports,
437-
..*providers
438-
};
417+
*providers = Providers { typeck, diagnostic_only_typeck, used_trait_imports, ..*providers };
439418
}

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
@@ -975,10 +975,6 @@ rustc_queries! {
975975
cache_on_disk_if { true }
976976
}
977977

978-
query has_typeck_results(def_id: DefId) -> bool {
979-
desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
980-
}
981-
982978
query coherent_trait(def_id: DefId) -> Result<(), ErrorGuaranteed> {
983979
desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
984980
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)