mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #123992 - compiler-errors:no-has-typeck-results, r=jackh726
`has_typeck_results` doesnt need to be a query self-explanatory
This commit is contained in:
commit
a77f76e263
@ -66,7 +66,7 @@ use rustc_middle::query::Providers;
|
|||||||
use rustc_middle::traits;
|
use rustc_middle::traits;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_session::config;
|
use rustc_session::config;
|
||||||
use rustc_span::def_id::{DefId, LocalDefId};
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
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> {
|
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDefId> {
|
||||||
&tcx.typeck(def_id).used_trait_imports
|
&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) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
method::provide(providers);
|
method::provide(providers);
|
||||||
*providers = Providers {
|
*providers = Providers { typeck, diagnostic_only_typeck, used_trait_imports, ..*providers };
|
||||||
typeck,
|
|
||||||
diagnostic_only_typeck,
|
|
||||||
has_typeck_results,
|
|
||||||
used_trait_imports,
|
|
||||||
..*providers
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -741,7 +741,7 @@ impl<'tcx> LateContext<'tcx> {
|
|||||||
.filter(|typeck_results| typeck_results.hir_owner == id.owner)
|
.filter(|typeck_results| typeck_results.hir_owner == id.owner)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
self.tcx
|
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))
|
.then(|| self.tcx.typeck(id.owner.def_id))
|
||||||
})
|
})
|
||||||
.and_then(|typeck_results| typeck_results.type_dependent_def(id))
|
.and_then(|typeck_results| typeck_results.type_dependent_def(id))
|
||||||
|
@ -975,10 +975,6 @@ rustc_queries! {
|
|||||||
cache_on_disk_if { true }
|
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> {
|
query coherent_trait(def_id: DefId) -> Result<(), ErrorGuaranteed> {
|
||||||
desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
|
desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
|
||||||
ensure_forwards_result_if_red
|
ensure_forwards_result_if_red
|
||||||
|
@ -817,6 +817,17 @@ impl CurrentGcx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
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.
|
/// Expects a body and returns its codegen attributes.
|
||||||
///
|
///
|
||||||
/// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for
|
/// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for
|
||||||
|
@ -185,7 +185,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
|
|||||||
if let hir::PatKind::Wild = pat.kind {
|
if let hir::PatKind::Wild = pat.kind {
|
||||||
return false; // ignore `_` patterns
|
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)
|
is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), tys)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@ -233,7 +233,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo
|
|||||||
Call(_, args) => {
|
Call(_, args) => {
|
||||||
let mut tys = DefIdSet::default();
|
let mut tys = DefIdSet::default();
|
||||||
for arg in args {
|
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_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys)
|
||||||
&& is_mutated_static(arg)
|
&& is_mutated_static(arg)
|
||||||
{
|
{
|
||||||
@ -246,7 +246,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo
|
|||||||
MethodCall(_, receiver, args, _) => {
|
MethodCall(_, receiver, args, _) => {
|
||||||
let mut tys = DefIdSet::default();
|
let mut tys = DefIdSet::default();
|
||||||
for arg in std::iter::once(receiver).chain(args.iter()) {
|
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_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys)
|
||||||
&& is_mutated_static(arg)
|
&& is_mutated_static(arg)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user