Skip to content

Commit

Permalink
Auto merge of #123992 - compiler-errors:no-has-typeck-results, r=jack…
Browse files Browse the repository at this point in the history
…h726

`has_typeck_results` doesnt need to be a query

self-explanatory
  • Loading branch information
bors committed Apr 23, 2024
2 parents aca749e + 6abf1aa commit a77f76e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
25 changes: 2 additions & 23 deletions compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Up @@ -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))
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit a77f76e

Please sign in to comment.