Skip to content

has_typeck_results doesnt need to be a query #123992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ use rustc_middle::query::Providers;
use rustc_middle::traits;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::config;
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::def_id::LocalDefId;
use rustc_span::Span;

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
@@ -84,21 +84,6 @@ macro_rules! type_error_struct {
})
}

fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
// Closures' typeck results come from their outermost function,
// as they are part of the same "inference environment".
let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
if typeck_root_def_id != def_id {
return tcx.has_typeck_results(typeck_root_def_id);
}

if let Some(def_id) = def_id.as_local() {
tcx.hir_node_by_def_id(def_id).body_id().is_some()
} else {
false
}
}

fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDefId> {
&tcx.typeck(def_id).used_trait_imports
}
@@ -429,11 +414,5 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {

pub fn provide(providers: &mut Providers) {
method::provide(providers);
*providers = Providers {
typeck,
diagnostic_only_typeck,
has_typeck_results,
used_trait_imports,
..*providers
};
*providers = Providers { typeck, diagnostic_only_typeck, used_trait_imports, ..*providers };
}
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
@@ -741,7 +741,7 @@ impl<'tcx> LateContext<'tcx> {
.filter(|typeck_results| typeck_results.hir_owner == id.owner)
.or_else(|| {
self.tcx
.has_typeck_results(id.owner.to_def_id())
.has_typeck_results(id.owner.def_id)
.then(|| self.tcx.typeck(id.owner.def_id))
})
.and_then(|typeck_results| typeck_results.type_dependent_def(id))
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -975,10 +975,6 @@ rustc_queries! {
cache_on_disk_if { true }
}

query has_typeck_results(def_id: DefId) -> bool {
desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
}

query coherent_trait(def_id: DefId) -> Result<(), ErrorGuaranteed> {
desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
ensure_forwards_result_if_red
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
@@ -817,6 +817,17 @@ impl CurrentGcx {
}

impl<'tcx> TyCtxt<'tcx> {
pub fn has_typeck_results(self, def_id: LocalDefId) -> bool {
// Closures' typeck results come from their outermost function,
// as they are part of the same "inference environment".
let typeck_root_def_id = self.typeck_root_def_id(def_id.to_def_id());
if typeck_root_def_id != def_id.to_def_id() {
return self.has_typeck_results(typeck_root_def_id.expect_local());
}

self.hir_node_by_def_id(def_id).body_id().is_some()
}

/// Expects a body and returns its codegen attributes.
///
/// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/functions/must_use.rs
Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
if let hir::PatKind::Wild = pat.kind {
return false; // ignore `_` patterns
}
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
if cx.tcx.has_typeck_results(pat.hir_id.owner.def_id) {
is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), tys)
} else {
false
@@ -233,7 +233,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo
Call(_, args) => {
let mut tys = DefIdSet::default();
for arg in args {
if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
if cx.tcx.has_typeck_results(arg.hir_id.owner.def_id)
&& is_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys)
&& is_mutated_static(arg)
{
@@ -246,7 +246,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo
MethodCall(_, receiver, args, _) => {
let mut tys = DefIdSet::default();
for arg in std::iter::once(receiver).chain(args.iter()) {
if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
if cx.tcx.has_typeck_results(arg.hir_id.owner.def_id)
&& is_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys)
&& is_mutated_static(arg)
{