Auto merge of #109092 - compiler-errors:local-key, r=cjgillot
Make local query providers receive local keys When a query is marked `separate_provide_extern`, we can map a query key to a "local" form of the key, e.g. `DefId` -> `LocalDefId`. This simplifies a ton of code which either has to assert or use something like `expect_local` to assert that the query key is local.
This commit is contained in:
commit
77d50a8870
78 changed files with 446 additions and 640 deletions
|
@ -284,7 +284,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
// hidden type is well formed even without those bounds.
|
||||
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
|
||||
|
||||
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
|
||||
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
|
||||
|
||||
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
|
||||
// the bounds that the function supplies.
|
||||
|
|
|
@ -10,6 +10,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
|||
use rustc_middle::middle::exported_symbols::{
|
||||
metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
|
||||
};
|
||||
use rustc_middle::query::LocalCrate;
|
||||
use rustc_middle::ty::query::{ExternProviders, Providers};
|
||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::Instance;
|
||||
|
@ -41,9 +42,7 @@ pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel {
|
|||
}
|
||||
}
|
||||
|
||||
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<SymbolExportInfo> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<SymbolExportInfo> {
|
||||
if !tcx.sess.opts.output_types.should_codegen() {
|
||||
return Default::default();
|
||||
}
|
||||
|
@ -154,10 +153,10 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
|||
reachable_non_generics
|
||||
}
|
||||
|
||||
fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
let export_threshold = threshold(tcx);
|
||||
|
||||
if let Some(&info) = tcx.reachable_non_generics(def_id.krate).get(&def_id) {
|
||||
if let Some(&info) = tcx.reachable_non_generics(LOCAL_CRATE).get(&def_id.to_def_id()) {
|
||||
info.level.is_below_threshold(export_threshold)
|
||||
} else {
|
||||
false
|
||||
|
@ -170,10 +169,8 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
|
|||
|
||||
fn exported_symbols_provider_local(
|
||||
tcx: TyCtxt<'_>,
|
||||
cnum: CrateNum,
|
||||
_: LocalCrate,
|
||||
) -> &[(ExportedSymbol<'_>, SymbolExportInfo)] {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
if !tcx.sess.opts.output_types.should_codegen() {
|
||||
return &[];
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
|
|||
}
|
||||
}
|
||||
|
||||
fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
|
||||
fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||
if cfg!(debug_assertions) {
|
||||
let def_kind = tcx.def_kind(did);
|
||||
assert!(
|
||||
|
@ -52,7 +52,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
|
|||
);
|
||||
}
|
||||
|
||||
let did = did.expect_local();
|
||||
let attrs = tcx.hir().attrs(tcx.hir().local_def_id_to_hir_id(did));
|
||||
let mut codegen_fn_attrs = CodegenFnAttrs::new();
|
||||
if tcx.should_inherit_track_caller(did) {
|
||||
|
|
|
@ -32,8 +32,7 @@ pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
|||
/// it is a trait impl/function, return if it has a `const` modifier. If it is an intrinsic,
|
||||
/// report whether said intrinsic has a `rustc_const_{un,}stable` attribute. Otherwise, return
|
||||
/// `Constness::NotConst`.
|
||||
fn constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
|
||||
let def_id = def_id.expect_local();
|
||||
fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
|
||||
let node = tcx.hir().get_by_def_id(def_id);
|
||||
|
||||
match node {
|
||||
|
|
|
@ -246,7 +246,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
|
|||
self.check_local_or_return_ty(return_ty.skip_binder(), RETURN_PLACE);
|
||||
}
|
||||
|
||||
if !tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
|
||||
if !tcx.has_attr(def_id, sym::rustc_do_not_const_check) {
|
||||
self.visit_body(&body);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ pub fn check_live_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
|
|||
return;
|
||||
}
|
||||
|
||||
if tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
|
||||
if tcx.has_attr(def_id, sym::rustc_do_not_const_check) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,12 @@ impl From<OwnerId> for HirId {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<OwnerId> for DefId {
|
||||
fn from(value: OwnerId) -> Self {
|
||||
value.to_def_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl OwnerId {
|
||||
#[inline]
|
||||
pub fn to_def_id(self) -> DefId {
|
||||
|
|
|
@ -75,7 +75,7 @@ pub trait AstConv<'tcx> {
|
|||
fn get_type_parameter_bounds(
|
||||
&self,
|
||||
span: Span,
|
||||
def_id: DefId,
|
||||
def_id: LocalDefId,
|
||||
assoc_name: Ident,
|
||||
) -> ty::GenericPredicates<'tcx>;
|
||||
|
||||
|
@ -1773,9 +1773,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
ty_param_def_id, assoc_name, span,
|
||||
);
|
||||
|
||||
let predicates = &self
|
||||
.get_type_parameter_bounds(span, ty_param_def_id.to_def_id(), assoc_name)
|
||||
.predicates;
|
||||
let predicates =
|
||||
&self.get_type_parameter_bounds(span, ty_param_def_id, assoc_name).predicates;
|
||||
|
||||
debug!("find_bound_for_assoc_item: predicates={:#?}", predicates);
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
return;
|
||||
}
|
||||
|
||||
let substs = InternalSubsts::identity_for_item(tcx, item.owner_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, item.owner_id);
|
||||
let span = tcx.def_span(item.owner_id.def_id);
|
||||
|
||||
if !tcx.features().impl_trait_projections {
|
||||
|
@ -304,7 +304,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
|
|||
..
|
||||
}) = item.kind
|
||||
{
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let opaque_identity_ty = if in_trait {
|
||||
tcx.mk_projection(def_id.to_def_id(), substs)
|
||||
} else {
|
||||
|
@ -535,7 +535,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
}
|
||||
ty::AssocKind::Type if assoc_item.defaultness(tcx).has_value() => {
|
||||
let trait_substs =
|
||||
InternalSubsts::identity_for_item(tcx, id.owner_id.to_def_id());
|
||||
InternalSubsts::identity_for_item(tcx, id.owner_id);
|
||||
let _: Result<_, rustc_errors::ErrorGuaranteed> = check_type_bounds(
|
||||
tcx,
|
||||
assoc_item,
|
||||
|
@ -1161,7 +1161,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
def.destructor(tcx); // force the destructor to be evaluated
|
||||
|
||||
if def.variants().is_empty() {
|
||||
if let Some(attr) = tcx.get_attrs(def_id.to_def_id(), sym::repr).next() {
|
||||
if let Some(attr) = tcx.get_attrs(def_id, sym::repr).next() {
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
attr.span,
|
||||
|
|
|
@ -583,13 +583,13 @@ fn compare_asyncness<'tcx>(
|
|||
#[instrument(skip(tcx), level = "debug", ret)]
|
||||
pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
impl_m_def_id: LocalDefId,
|
||||
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
|
||||
let impl_m = tcx.opt_associated_item(def_id).unwrap();
|
||||
let impl_m = tcx.opt_associated_item(impl_m_def_id.to_def_id()).unwrap();
|
||||
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
|
||||
let impl_trait_ref =
|
||||
tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity();
|
||||
let param_env = tcx.param_env(def_id);
|
||||
let param_env = tcx.param_env(impl_m_def_id);
|
||||
|
||||
// First, check a few of the same things as `compare_impl_method`,
|
||||
// just so we don't ICE during substitution later.
|
||||
|
@ -599,7 +599,6 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
|
||||
let trait_to_impl_substs = impl_trait_ref.substs;
|
||||
|
||||
let impl_m_def_id = impl_m.def_id.expect_local();
|
||||
let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m_def_id);
|
||||
let return_span = tcx.hir().fn_decl_by_hir_id(impl_m_hir_id).unwrap().output.span();
|
||||
let cause = ObligationCause::new(
|
||||
|
|
|
@ -109,8 +109,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
};
|
||||
}
|
||||
|
||||
fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
|
||||
tcx.calculate_dtor(def_id, dropck::check_drop_impl)
|
||||
fn adt_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Destructor> {
|
||||
tcx.calculate_dtor(def_id.to_def_id(), dropck::check_drop_impl)
|
||||
}
|
||||
|
||||
/// Given a `DefId` for an opaque type in return position, find its parent item's return
|
||||
|
|
|
@ -1794,7 +1794,7 @@ fn check_variances_for_type_defn<'tcx>(
|
|||
|
||||
// Lazily calculated because it is only needed in case of an error.
|
||||
let explicitly_bounded_params = LazyCell::new(|| {
|
||||
let icx = crate::collect::ItemCtxt::new(tcx, item.owner_id.to_def_id());
|
||||
let icx = crate::collect::ItemCtxt::new(tcx, item.owner_id.def_id);
|
||||
hir_generics
|
||||
.predicates
|
||||
.iter()
|
||||
|
|
|
@ -368,11 +368,8 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
|||
}
|
||||
}
|
||||
|
||||
pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedInfo {
|
||||
pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> CoerceUnsizedInfo {
|
||||
debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did);
|
||||
|
||||
// this provider should only get invoked for local def-ids
|
||||
let impl_did = impl_did.expect_local();
|
||||
let span = tcx.def_span(impl_did);
|
||||
|
||||
let coerce_unsized_trait = tcx.require_lang_item(LangItem::CoerceUnsized, Some(span));
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::ty::fast_reject::{simplify_type, SimplifiedType, TreatParams, TreatProjections};
|
||||
use rustc_middle::ty::{self, CrateInherentImpls, Ty, TyCtxt};
|
||||
use rustc_span::symbol::sym;
|
||||
|
@ -24,7 +24,7 @@ pub fn crate_inherent_impls(tcx: TyCtxt<'_>, (): ()) -> CrateInherentImpls {
|
|||
collect.impls_map
|
||||
}
|
||||
|
||||
pub fn crate_incoherent_impls(tcx: TyCtxt<'_>, (_, simp): (CrateNum, SimplifiedType)) -> &[DefId] {
|
||||
pub fn crate_incoherent_impls(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] {
|
||||
let crate_map = tcx.crate_inherent_impls(());
|
||||
tcx.arena.alloc_from_iter(
|
||||
crate_map.incoherent_impls.get(&simp).unwrap_or(&Vec::new()).iter().map(|d| d.to_def_id()),
|
||||
|
@ -32,9 +32,7 @@ pub fn crate_incoherent_impls(tcx: TyCtxt<'_>, (_, simp): (CrateNum, SimplifiedT
|
|||
}
|
||||
|
||||
/// On-demand query: yields a vector of the inherent impls for a specific type.
|
||||
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: DefId) -> &[DefId] {
|
||||
let ty_def_id = ty_def_id.expect_local();
|
||||
|
||||
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: LocalDefId) -> &[DefId] {
|
||||
let crate_map = tcx.crate_inherent_impls(());
|
||||
match crate_map.inherent_impls.get(&ty_def_id) {
|
||||
Some(v) => &v[..],
|
||||
|
|
|
@ -113,7 +113,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
/// the AST (`hir::Generics`), recursively.
|
||||
pub struct ItemCtxt<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
item_def_id: DefId,
|
||||
item_def_id: LocalDefId,
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -347,7 +347,7 @@ fn bad_placeholder<'tcx>(
|
|||
}
|
||||
|
||||
impl<'tcx> ItemCtxt<'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> ItemCtxt<'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId) -> ItemCtxt<'tcx> {
|
||||
ItemCtxt { tcx, item_def_id }
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ impl<'tcx> ItemCtxt<'tcx> {
|
|||
}
|
||||
|
||||
pub fn hir_id(&self) -> hir::HirId {
|
||||
self.tcx.hir().local_def_id_to_hir_id(self.item_def_id.expect_local())
|
||||
self.tcx.hir().local_def_id_to_hir_id(self.item_def_id)
|
||||
}
|
||||
|
||||
pub fn node(&self) -> hir::Node<'tcx> {
|
||||
|
@ -370,20 +370,16 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
|||
}
|
||||
|
||||
fn item_def_id(&self) -> DefId {
|
||||
self.item_def_id
|
||||
self.item_def_id.to_def_id()
|
||||
}
|
||||
|
||||
fn get_type_parameter_bounds(
|
||||
&self,
|
||||
span: Span,
|
||||
def_id: DefId,
|
||||
def_id: LocalDefId,
|
||||
assoc_name: Ident,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
self.tcx.at(span).type_param_predicates((
|
||||
self.item_def_id,
|
||||
def_id.expect_local(),
|
||||
assoc_name,
|
||||
))
|
||||
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name))
|
||||
}
|
||||
|
||||
fn re_infer(&self, _: Option<&ty::GenericParamDef>, _: Span) -> Option<ty::Region<'tcx>> {
|
||||
|
@ -839,17 +835,15 @@ fn convert_variant(
|
|||
adt_kind,
|
||||
parent_did.to_def_id(),
|
||||
recovered,
|
||||
adt_kind == AdtKind::Struct && tcx.has_attr(parent_did.to_def_id(), sym::non_exhaustive)
|
||||
|| variant_did.map_or(false, |variant_did| {
|
||||
tcx.has_attr(variant_did.to_def_id(), sym::non_exhaustive)
|
||||
}),
|
||||
adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive)
|
||||
|| variant_did
|
||||
.map_or(false, |variant_did| tcx.has_attr(variant_did, sym::non_exhaustive)),
|
||||
)
|
||||
}
|
||||
|
||||
fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> {
|
||||
fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
||||
use rustc_hir::*;
|
||||
|
||||
let def_id = def_id.expect_local();
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let Node::Item(item) = tcx.hir().get(hir_id) else {
|
||||
bug!();
|
||||
|
@ -908,8 +902,8 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> {
|
|||
tcx.mk_adt_def(def_id.to_def_id(), kind, variants, repr)
|
||||
}
|
||||
|
||||
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
|
||||
let item = tcx.hir().expect_item(def_id.expect_local());
|
||||
fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
|
||||
let item = tcx.hir().expect_item(def_id);
|
||||
|
||||
let (is_auto, unsafety, items) = match item.kind {
|
||||
hir::ItemKind::Trait(is_auto, unsafety, .., items) => {
|
||||
|
@ -1036,7 +1030,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
|
|||
});
|
||||
|
||||
ty::TraitDef {
|
||||
def_id,
|
||||
def_id: def_id.to_def_id(),
|
||||
unsafety,
|
||||
paren_sugar,
|
||||
has_auto_impl: is_auto,
|
||||
|
@ -1091,14 +1085,13 @@ pub fn get_infer_ret_ty<'hir>(output: &'hir hir::FnRetTy<'hir>) -> Option<&'hir
|
|||
}
|
||||
|
||||
#[instrument(level = "debug", skip(tcx))]
|
||||
fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<ty::PolyFnSig<'_>> {
|
||||
fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<'_>> {
|
||||
use rustc_hir::Node::*;
|
||||
use rustc_hir::*;
|
||||
|
||||
let def_id = def_id.expect_local();
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
|
||||
let icx = ItemCtxt::new(tcx, def_id.to_def_id());
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
|
||||
let output = match tcx.hir().get(hir_id) {
|
||||
TraitItem(hir::TraitItem {
|
||||
|
@ -1139,7 +1132,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<ty::PolyFnSig<'_>>
|
|||
|
||||
ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
|
||||
let abi = tcx.hir().get_foreign_abi(hir_id);
|
||||
compute_sig_of_foreign_fn_decl(tcx, def_id.to_def_id(), fn_decl, abi)
|
||||
compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi)
|
||||
}
|
||||
|
||||
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => {
|
||||
|
@ -1338,9 +1331,12 @@ fn suggest_impl_trait<'tcx>(
|
|||
None
|
||||
}
|
||||
|
||||
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'_>>> {
|
||||
fn impl_trait_ref(
|
||||
tcx: TyCtxt<'_>,
|
||||
def_id: LocalDefId,
|
||||
) -> Option<ty::EarlyBinder<ty::TraitRef<'_>>> {
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
let impl_ = tcx.hir().expect_item(def_id.expect_local()).expect_impl();
|
||||
let impl_ = tcx.hir().expect_item(def_id).expect_impl();
|
||||
impl_
|
||||
.of_trait
|
||||
.as_ref()
|
||||
|
@ -1380,9 +1376,9 @@ fn check_impl_constness(
|
|||
}
|
||||
}
|
||||
|
||||
fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity {
|
||||
fn impl_polarity(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplPolarity {
|
||||
let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl);
|
||||
let item = tcx.hir().expect_item(def_id.expect_local());
|
||||
let item = tcx.hir().expect_item(def_id);
|
||||
match &item.kind {
|
||||
hir::ItemKind::Impl(hir::Impl {
|
||||
polarity: hir::ImplPolarity::Negative(span),
|
||||
|
@ -1465,16 +1461,16 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
|
|||
|
||||
fn compute_sig_of_foreign_fn_decl<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
def_id: LocalDefId,
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
abi: abi::Abi,
|
||||
) -> ty::PolyFnSig<'tcx> {
|
||||
let unsafety = if abi == abi::Abi::RustIntrinsic {
|
||||
intrinsic_operation_unsafety(tcx, def_id)
|
||||
intrinsic_operation_unsafety(tcx, def_id.to_def_id())
|
||||
} else {
|
||||
hir::Unsafety::Unsafe
|
||||
};
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let fty =
|
||||
ItemCtxt::new(tcx, def_id).astconv().ty_of_fn(hir_id, unsafety, abi, decl, None, None);
|
||||
|
||||
|
@ -1515,31 +1511,28 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
|
|||
fty
|
||||
}
|
||||
|
||||
fn is_foreign_item(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
match tcx.hir().get_if_local(def_id) {
|
||||
Some(Node::ForeignItem(..)) => true,
|
||||
Some(_) => false,
|
||||
_ => bug!("is_foreign_item applied to non-local def-id {:?}", def_id),
|
||||
fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
match tcx.hir().get_by_def_id(def_id) {
|
||||
Node::ForeignItem(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn generator_kind(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::GeneratorKind> {
|
||||
match tcx.hir().get_if_local(def_id) {
|
||||
Some(Node::Expr(&rustc_hir::Expr {
|
||||
fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> {
|
||||
match tcx.hir().get_by_def_id(def_id) {
|
||||
Node::Expr(&rustc_hir::Expr {
|
||||
kind: rustc_hir::ExprKind::Closure(&rustc_hir::Closure { body, .. }),
|
||||
..
|
||||
})) => tcx.hir().body(body).generator_kind(),
|
||||
Some(_) => None,
|
||||
_ => bug!("generator_kind applied to non-local def-id {:?}", def_id),
|
||||
}) => tcx.hir().body(body).generator_kind(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
|
||||
match tcx.hir().get_if_local(def_id) {
|
||||
Some(Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. })) => {
|
||||
fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool {
|
||||
match tcx.hir().get_by_def_id(def_id) {
|
||||
Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. }) => {
|
||||
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias)
|
||||
}
|
||||
Some(_) => bug!("tried getting opaque_ty_origin for non-opaque: {:?}", def_id),
|
||||
_ => bug!("tried getting opaque_ty_origin for non-local def-id {:?}", def_id),
|
||||
_ => bug!("tried getting opaque_ty_origin for non-opaque: {:?}", def_id),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@ use hir::{
|
|||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::symbol::{kw, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
||||
pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
||||
use rustc_hir::*;
|
||||
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
|
||||
let node = tcx.hir().get(hir_id);
|
||||
let parent_def_id = match node {
|
||||
|
@ -121,7 +121,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
Some(parent_def_id.to_def_id())
|
||||
}
|
||||
Node::Expr(&Expr { kind: ExprKind::ConstBlock(_), .. }) => {
|
||||
Some(tcx.typeck_root_def_id(def_id))
|
||||
Some(tcx.typeck_root_def_id(def_id.to_def_id()))
|
||||
}
|
||||
// Exclude `GlobalAsm` here which cannot have generics.
|
||||
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
|
||||
|
@ -140,7 +140,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
}
|
||||
}
|
||||
Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => {
|
||||
Some(tcx.typeck_root_def_id(def_id))
|
||||
Some(tcx.typeck_root_def_id(def_id.to_def_id()))
|
||||
}
|
||||
Node::Item(item) => match item.kind {
|
||||
ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
|
@ -189,7 +189,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
let opt_self = Some(ty::GenericParamDef {
|
||||
index: 0,
|
||||
name: kw::SelfUpper,
|
||||
def_id,
|
||||
def_id: def_id.to_def_id(),
|
||||
pure_wrt_drop: false,
|
||||
kind: ty::GenericParamDefKind::Type {
|
||||
has_default: false,
|
||||
|
@ -326,7 +326,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
params.extend(dummy_args.iter().map(|&arg| ty::GenericParamDef {
|
||||
index: next_index(),
|
||||
name: Symbol::intern(arg),
|
||||
def_id,
|
||||
def_id: def_id.to_def_id(),
|
||||
pure_wrt_drop: false,
|
||||
kind: ty::GenericParamDefKind::Type { has_default: false, synthetic: false },
|
||||
}));
|
||||
|
@ -339,7 +339,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
params.push(ty::GenericParamDef {
|
||||
index: next_index(),
|
||||
name: Symbol::intern("<const_ty>"),
|
||||
def_id,
|
||||
def_id: def_id.to_def_id(),
|
||||
pure_wrt_drop: false,
|
||||
kind: ty::GenericParamDefKind::Type { has_default: false, synthetic: false },
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ use rustc_hir as hir;
|
|||
use rustc_infer::traits::util;
|
||||
use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::Span;
|
||||
|
||||
/// For associated types we include both bounds written on the type
|
||||
|
@ -16,12 +16,12 @@ use rustc_span::Span;
|
|||
/// `hr-associated-type-bound-1.rs`.
|
||||
fn associated_type_bounds<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
assoc_item_def_id: DefId,
|
||||
assoc_item_def_id: LocalDefId,
|
||||
ast_bounds: &'tcx [hir::GenericBound<'tcx>],
|
||||
span: Span,
|
||||
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
||||
let item_ty = tcx.mk_projection(
|
||||
assoc_item_def_id,
|
||||
assoc_item_def_id.to_def_id(),
|
||||
InternalSubsts::identity_for_item(tcx, assoc_item_def_id),
|
||||
);
|
||||
|
||||
|
@ -30,8 +30,8 @@ fn associated_type_bounds<'tcx>(
|
|||
// Associated types are implicitly sized unless a `?Sized` bound is found
|
||||
icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span);
|
||||
|
||||
let trait_def_id = tcx.parent(assoc_item_def_id);
|
||||
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local());
|
||||
let trait_def_id = tcx.local_parent(assoc_item_def_id);
|
||||
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id);
|
||||
|
||||
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
|
||||
match pred.kind().skip_binder() {
|
||||
|
@ -45,7 +45,11 @@ fn associated_type_bounds<'tcx>(
|
|||
});
|
||||
|
||||
let all_bounds = tcx.arena.alloc_from_iter(bounds.predicates().chain(bounds_from_parent));
|
||||
debug!("associated_type_bounds({}) = {:?}", tcx.def_path_str(assoc_item_def_id), all_bounds);
|
||||
debug!(
|
||||
"associated_type_bounds({}) = {:?}",
|
||||
tcx.def_path_str(assoc_item_def_id.to_def_id()),
|
||||
all_bounds
|
||||
);
|
||||
all_bounds
|
||||
}
|
||||
|
||||
|
@ -56,7 +60,7 @@ fn associated_type_bounds<'tcx>(
|
|||
#[instrument(level = "trace", skip(tcx), ret)]
|
||||
fn opaque_type_bounds<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
opaque_def_id: DefId,
|
||||
opaque_def_id: LocalDefId,
|
||||
ast_bounds: &'tcx [hir::GenericBound<'tcx>],
|
||||
item_ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
|
@ -74,9 +78,9 @@ fn opaque_type_bounds<'tcx>(
|
|||
|
||||
pub(super) fn explicit_item_bounds(
|
||||
tcx: TyCtxt<'_>,
|
||||
def_id: DefId,
|
||||
def_id: LocalDefId,
|
||||
) -> &'_ [(ty::Predicate<'_>, Span)] {
|
||||
match tcx.opt_rpitit_info(def_id) {
|
||||
match tcx.opt_rpitit_info(def_id.to_def_id()) {
|
||||
// RPITIT's bounds are the same as opaque type bounds, but with
|
||||
// a projection self type.
|
||||
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
|
||||
|
@ -84,9 +88,12 @@ pub(super) fn explicit_item_bounds(
|
|||
let opaque_ty = item.expect_opaque_ty();
|
||||
return opaque_type_bounds(
|
||||
tcx,
|
||||
opaque_def_id,
|
||||
opaque_def_id.expect_local(),
|
||||
opaque_ty.bounds,
|
||||
tcx.mk_projection(def_id, ty::InternalSubsts::identity_for_item(tcx, def_id)),
|
||||
tcx.mk_projection(
|
||||
def_id.to_def_id(),
|
||||
ty::InternalSubsts::identity_for_item(tcx, def_id),
|
||||
),
|
||||
item.span,
|
||||
);
|
||||
}
|
||||
|
@ -95,7 +102,7 @@ pub(super) fn explicit_item_bounds(
|
|||
None => {}
|
||||
}
|
||||
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
match tcx.hir().get(hir_id) {
|
||||
hir::Node::TraitItem(hir::TraitItem {
|
||||
kind: hir::TraitItemKind::Type(bounds, _),
|
||||
|
@ -109,9 +116,9 @@ pub(super) fn explicit_item_bounds(
|
|||
}) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
tcx.mk_projection(def_id, substs)
|
||||
tcx.mk_projection(def_id.to_def_id(), substs)
|
||||
} else {
|
||||
tcx.mk_opaque(def_id, substs)
|
||||
tcx.mk_opaque(def_id.to_def_id(), substs)
|
||||
};
|
||||
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
|
||||
}
|
||||
|
|
|
@ -62,15 +62,16 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
|
|||
/// Returns a list of user-specified type predicates for the definition with ID `def_id`.
|
||||
/// N.B., this does not include any implied/inferred constraints.
|
||||
#[instrument(level = "trace", skip(tcx), ret)]
|
||||
fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
|
||||
fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::GenericPredicates<'_> {
|
||||
use rustc_hir::*;
|
||||
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let node = tcx.hir().get(hir_id);
|
||||
|
||||
let mut is_trait = None;
|
||||
let mut is_default_impl_trait = None;
|
||||
|
||||
// FIXME: Should ItemCtxt take a LocalDefId?
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
|
||||
const NO_GENERICS: &hir::Generics<'_> = hir::Generics::empty();
|
||||
|
@ -99,7 +100,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
|||
| ItemKind::Union(_, generics) => generics,
|
||||
|
||||
ItemKind::Trait(_, _, generics, ..) | ItemKind::TraitAlias(generics, _) => {
|
||||
is_trait = Some(ty::TraitRef::identity(tcx, def_id));
|
||||
is_trait = Some(ty::TraitRef::identity(tcx, def_id.to_def_id()));
|
||||
generics
|
||||
}
|
||||
ItemKind::OpaqueTy(OpaqueTy { generics, .. }) => generics,
|
||||
|
@ -253,7 +254,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
|||
}
|
||||
|
||||
if tcx.features().generic_const_exprs {
|
||||
predicates.extend(const_evaluatable_predicates_of(tcx, def_id.expect_local()));
|
||||
predicates.extend(const_evaluatable_predicates_of(tcx, def_id));
|
||||
}
|
||||
|
||||
let mut predicates: Vec<_> = predicates.into_iter().collect();
|
||||
|
@ -392,18 +393,18 @@ pub(super) fn trait_explicit_predicates_and_bounds(
|
|||
def_id: LocalDefId,
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
assert_eq!(tcx.def_kind(def_id), DefKind::Trait);
|
||||
gather_explicit_predicates_of(tcx, def_id.to_def_id())
|
||||
gather_explicit_predicates_of(tcx, def_id)
|
||||
}
|
||||
|
||||
pub(super) fn explicit_predicates_of<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
def_id: LocalDefId,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
let def_kind = tcx.def_kind(def_id);
|
||||
if let DefKind::Trait = def_kind {
|
||||
// Remove bounds on associated types from the predicates, they will be
|
||||
// returned by `explicit_item_bounds`.
|
||||
let predicates_and_bounds = tcx.trait_explicit_predicates_and_bounds(def_id.expect_local());
|
||||
let predicates_and_bounds = tcx.trait_explicit_predicates_and_bounds(def_id);
|
||||
let trait_identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
|
||||
let is_assoc_item_ty = |ty: Ty<'tcx>| {
|
||||
|
@ -418,7 +419,8 @@ pub(super) fn explicit_predicates_of<'tcx>(
|
|||
// supertrait).
|
||||
if let ty::Alias(ty::Projection, projection) = ty.kind() {
|
||||
projection.substs == trait_identity_substs
|
||||
&& tcx.associated_item(projection.def_id).container_id(tcx) == def_id
|
||||
&& tcx.associated_item(projection.def_id).container_id(tcx)
|
||||
== def_id.to_def_id()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -449,7 +451,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
|
|||
}
|
||||
} else {
|
||||
if matches!(def_kind, DefKind::AnonConst) && tcx.lazy_normalization() {
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let parent_def_id = tcx.hir().get_parent_item(hir_id);
|
||||
|
||||
if let Some(defaulted_param_def_id) =
|
||||
|
@ -537,9 +539,9 @@ pub(super) fn explicit_predicates_of<'tcx>(
|
|||
/// the transitive super-predicates are converted.
|
||||
pub(super) fn super_predicates_of(
|
||||
tcx: TyCtxt<'_>,
|
||||
trait_def_id: DefId,
|
||||
trait_def_id: LocalDefId,
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
tcx.super_predicates_that_define_assoc_type((trait_def_id, None))
|
||||
tcx.super_predicates_that_define_assoc_type((trait_def_id.to_def_id(), None))
|
||||
}
|
||||
|
||||
/// Ensures that the super-predicates of the trait with a `DefId`
|
||||
|
@ -549,72 +551,70 @@ pub(super) fn super_predicates_that_define_assoc_type(
|
|||
tcx: TyCtxt<'_>,
|
||||
(trait_def_id, assoc_name): (DefId, Option<Ident>),
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
if trait_def_id.is_local() {
|
||||
debug!("local trait");
|
||||
let trait_hir_id = tcx.hir().local_def_id_to_hir_id(trait_def_id.expect_local());
|
||||
|
||||
let Node::Item(item) = tcx.hir().get(trait_hir_id) else {
|
||||
bug!("trait_node_id {} is not an item", trait_hir_id);
|
||||
};
|
||||
|
||||
let (generics, bounds) = match item.kind {
|
||||
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
|
||||
hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits),
|
||||
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
|
||||
};
|
||||
|
||||
let icx = ItemCtxt::new(tcx, trait_def_id);
|
||||
|
||||
// Convert the bounds that follow the colon, e.g., `Bar + Zed` in `trait Foo: Bar + Zed`.
|
||||
let self_param_ty = tcx.types.self_param;
|
||||
let superbounds1 = if let Some(assoc_name) = assoc_name {
|
||||
icx.astconv().compute_bounds_that_match_assoc_type(self_param_ty, bounds, assoc_name)
|
||||
} else {
|
||||
icx.astconv().compute_bounds(self_param_ty, bounds)
|
||||
};
|
||||
|
||||
let superbounds1 = superbounds1.predicates();
|
||||
|
||||
// Convert any explicit superbounds in the where-clause,
|
||||
// e.g., `trait Foo where Self: Bar`.
|
||||
// In the case of trait aliases, however, we include all bounds in the where-clause,
|
||||
// so e.g., `trait Foo = where u32: PartialEq<Self>` would include `u32: PartialEq<Self>`
|
||||
// as one of its "superpredicates".
|
||||
let is_trait_alias = tcx.is_trait_alias(trait_def_id);
|
||||
let superbounds2 = icx.type_parameter_bounds_in_generics(
|
||||
generics,
|
||||
item.owner_id.def_id,
|
||||
self_param_ty,
|
||||
OnlySelfBounds(!is_trait_alias),
|
||||
assoc_name,
|
||||
);
|
||||
|
||||
// Combine the two lists to form the complete set of superbounds:
|
||||
let superbounds = &*tcx.arena.alloc_from_iter(superbounds1.into_iter().chain(superbounds2));
|
||||
debug!(?superbounds);
|
||||
|
||||
// Now require that immediate supertraits are converted,
|
||||
// which will, in turn, reach indirect supertraits.
|
||||
if assoc_name.is_none() {
|
||||
// Now require that immediate supertraits are converted,
|
||||
// which will, in turn, reach indirect supertraits.
|
||||
for &(pred, span) in superbounds {
|
||||
debug!("superbound: {:?}", pred);
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) =
|
||||
pred.kind().skip_binder()
|
||||
{
|
||||
tcx.at(span).super_predicates_of(bound.def_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ty::GenericPredicates { parent: None, predicates: superbounds }
|
||||
} else {
|
||||
let Some(trait_def_id) = trait_def_id.as_local() else {
|
||||
// if `assoc_name` is None, then the query should've been redirected to an
|
||||
// external provider
|
||||
assert!(assoc_name.is_some());
|
||||
tcx.super_predicates_of(trait_def_id)
|
||||
return tcx.super_predicates_of(trait_def_id);
|
||||
};
|
||||
|
||||
debug!("local trait");
|
||||
let trait_hir_id = tcx.hir().local_def_id_to_hir_id(trait_def_id);
|
||||
|
||||
let Node::Item(item) = tcx.hir().get(trait_hir_id) else {
|
||||
bug!("trait_node_id {} is not an item", trait_hir_id);
|
||||
};
|
||||
|
||||
let (generics, bounds) = match item.kind {
|
||||
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
|
||||
hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits),
|
||||
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
|
||||
};
|
||||
|
||||
let icx = ItemCtxt::new(tcx, trait_def_id);
|
||||
|
||||
// Convert the bounds that follow the colon, e.g., `Bar + Zed` in `trait Foo: Bar + Zed`.
|
||||
let self_param_ty = tcx.types.self_param;
|
||||
let superbounds1 = if let Some(assoc_name) = assoc_name {
|
||||
icx.astconv().compute_bounds_that_match_assoc_type(self_param_ty, bounds, assoc_name)
|
||||
} else {
|
||||
icx.astconv().compute_bounds(self_param_ty, bounds)
|
||||
};
|
||||
|
||||
let superbounds1 = superbounds1.predicates();
|
||||
|
||||
// Convert any explicit superbounds in the where-clause,
|
||||
// e.g., `trait Foo where Self: Bar`.
|
||||
// In the case of trait aliases, however, we include all bounds in the where-clause,
|
||||
// so e.g., `trait Foo = where u32: PartialEq<Self>` would include `u32: PartialEq<Self>`
|
||||
// as one of its "superpredicates".
|
||||
let is_trait_alias = tcx.is_trait_alias(trait_def_id.to_def_id());
|
||||
let superbounds2 = icx.type_parameter_bounds_in_generics(
|
||||
generics,
|
||||
item.owner_id.def_id,
|
||||
self_param_ty,
|
||||
OnlySelfBounds(!is_trait_alias),
|
||||
assoc_name,
|
||||
);
|
||||
|
||||
// Combine the two lists to form the complete set of superbounds:
|
||||
let superbounds = &*tcx.arena.alloc_from_iter(superbounds1.into_iter().chain(superbounds2));
|
||||
debug!(?superbounds);
|
||||
|
||||
// Now require that immediate supertraits are converted,
|
||||
// which will, in turn, reach indirect supertraits.
|
||||
if assoc_name.is_none() {
|
||||
// Now require that immediate supertraits are converted,
|
||||
// which will, in turn, reach indirect supertraits.
|
||||
for &(pred, span) in superbounds {
|
||||
debug!("superbound: {:?}", pred);
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) = pred.kind().skip_binder() {
|
||||
tcx.at(span).super_predicates_of(bound.def_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ty::GenericPredicates { parent: None, predicates: superbounds }
|
||||
}
|
||||
|
||||
/// Returns the predicates defined on `item_def_id` of the form
|
||||
|
@ -622,7 +622,7 @@ pub(super) fn super_predicates_that_define_assoc_type(
|
|||
#[instrument(level = "trace", skip(tcx))]
|
||||
pub(super) fn type_param_predicates(
|
||||
tcx: TyCtxt<'_>,
|
||||
(item_def_id, def_id, assoc_name): (DefId, LocalDefId, Ident),
|
||||
(item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident),
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
use rustc_hir::*;
|
||||
|
||||
|
@ -637,21 +637,21 @@ pub(super) fn type_param_predicates(
|
|||
let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id));
|
||||
|
||||
// Don't look for bounds where the type parameter isn't in scope.
|
||||
let parent = if item_def_id == param_owner.to_def_id() {
|
||||
let parent = if item_def_id == param_owner {
|
||||
None
|
||||
} else {
|
||||
tcx.generics_of(item_def_id).parent
|
||||
tcx.generics_of(item_def_id).parent.map(|def_id| def_id.expect_local())
|
||||
};
|
||||
|
||||
let mut result = parent
|
||||
.map(|parent| {
|
||||
let icx = ItemCtxt::new(tcx, parent);
|
||||
icx.get_type_parameter_bounds(DUMMY_SP, def_id.to_def_id(), assoc_name)
|
||||
icx.get_type_parameter_bounds(DUMMY_SP, def_id, assoc_name)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let mut extend = None;
|
||||
|
||||
let item_hir_id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
|
||||
let item_hir_id = tcx.hir().local_def_id_to_hir_id(item_def_id);
|
||||
let ast_generics = match tcx.hir().get(item_hir_id) {
|
||||
Node::TraitItem(item) => &item.generics,
|
||||
|
||||
|
@ -673,7 +673,8 @@ pub(super) fn type_param_predicates(
|
|||
ItemKind::Trait(_, _, generics, ..) => {
|
||||
// Implied `Self: Trait` and supertrait bounds.
|
||||
if param_id == item_hir_id {
|
||||
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id);
|
||||
let identity_trait_ref =
|
||||
ty::TraitRef::identity(tcx, item_def_id.to_def_id());
|
||||
extend =
|
||||
Some((identity_trait_ref.without_const().to_predicate(tcx), item.span));
|
||||
}
|
||||
|
|
|
@ -1051,9 +1051,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: DefId) -> ObjectLifetimeDefault {
|
||||
fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: LocalDefId) -> ObjectLifetimeDefault {
|
||||
debug_assert_eq!(tcx.def_kind(param_def_id), DefKind::TyParam);
|
||||
let param_def_id = param_def_id.expect_local();
|
||||
let hir::Node::GenericParam(param) = tcx.hir().get_by_def_id(param_def_id) else {
|
||||
bug!("expected GenericParam for object_lifetime_default");
|
||||
};
|
||||
|
|
|
@ -63,7 +63,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
.find(|(_, node)| matches!(node, OwnerNode::Item(_)))
|
||||
.unwrap()
|
||||
.0
|
||||
.to_def_id();
|
||||
.def_id;
|
||||
let item_ctxt = &ItemCtxt::new(tcx, item_def_id) as &dyn crate::astconv::AstConv<'_>;
|
||||
let ty = item_ctxt.ast_ty_to_ty(hir_ty);
|
||||
|
||||
|
@ -244,11 +244,13 @@ fn get_path_containing_arg_in_pat<'hir>(
|
|||
arg_path
|
||||
}
|
||||
|
||||
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>> {
|
||||
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty<'_>> {
|
||||
// If we are computing `type_of` the synthesized associated type for an RPITIT in the impl
|
||||
// side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the
|
||||
// associated type in the impl.
|
||||
if let Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
|
||||
if let Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) =
|
||||
tcx.opt_rpitit_info(def_id.to_def_id())
|
||||
{
|
||||
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
|
||||
Ok(map) => {
|
||||
let assoc_item = tcx.associated_item(def_id);
|
||||
|
@ -263,17 +265,16 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
|||
}
|
||||
}
|
||||
|
||||
let def_id = def_id.expect_local();
|
||||
use rustc_hir::*;
|
||||
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
|
||||
let icx = ItemCtxt::new(tcx, def_id.to_def_id());
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
|
||||
let output = match tcx.hir().get(hir_id) {
|
||||
Node::TraitItem(item) => match item.kind {
|
||||
TraitItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
}
|
||||
TraitItemKind::Const(ty, body_id) => body_id
|
||||
|
@ -293,7 +294,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
|||
|
||||
Node::ImplItem(item) => match item.kind {
|
||||
ImplItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
}
|
||||
ImplItemKind::Const(ty, body_id) => {
|
||||
|
@ -349,12 +350,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
|||
_ => icx.to_ty(*self_ty),
|
||||
},
|
||||
ItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
}
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
|
||||
let def = tcx.adt_def(def_id);
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_adt(def, substs)
|
||||
}
|
||||
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => {
|
||||
|
@ -394,7 +395,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
|||
|
||||
Node::ForeignItem(foreign_item) => match foreign_item.kind {
|
||||
ForeignItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
}
|
||||
ForeignItemKind::Static(t, _) => icx.to_ty(t),
|
||||
|
@ -406,7 +407,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
|||
tcx.type_of(tcx.hir().get_parent_item(hir_id)).subst_identity()
|
||||
}
|
||||
VariantData::Tuple(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
}
|
||||
},
|
||||
|
@ -439,7 +440,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
|||
Node::Expr(Expr { kind: ExprKind::ConstBlock(anon_const), .. })
|
||||
if anon_const.hir_id == hir_id =>
|
||||
{
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
substs.as_inline_const().ty()
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ fn diagnostic_hir_wf_check<'tcx>(
|
|||
tcx.sess
|
||||
.delay_span_bug(tcx.def_span(def_id), "Performed HIR wfcheck without an existing error!");
|
||||
|
||||
let icx = ItemCtxt::new(tcx, def_id.to_def_id());
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
|
||||
// To perform HIR-based WF checking, we iterate over all HIR types
|
||||
// that occur 'inside' the item we're checking. For example,
|
||||
|
|
|
@ -168,7 +168,7 @@ fn get_impl_substs(
|
|||
let assumed_wf_types =
|
||||
ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id);
|
||||
|
||||
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id.to_def_id());
|
||||
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id);
|
||||
let impl2_substs =
|
||||
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);
|
||||
|
||||
|
|
|
@ -513,7 +513,7 @@ pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
|
|||
// def-ID that will be used to determine the traits/predicates in
|
||||
// scope. This is derived from the enclosing item-like thing.
|
||||
let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id);
|
||||
let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id.to_def_id());
|
||||
let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id.def_id);
|
||||
item_cx.astconv().ast_ty_to_ty(hir_ty)
|
||||
}
|
||||
|
||||
|
@ -526,7 +526,7 @@ pub fn hir_trait_to_predicates<'tcx>(
|
|||
// def-ID that will be used to determine the traits/predicates in
|
||||
// scope. This is derived from the enclosing item-like thing.
|
||||
let env_def_id = tcx.hir().get_parent_item(hir_trait.hir_ref_id);
|
||||
let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id.to_def_id());
|
||||
let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id.def_id);
|
||||
let mut bounds = Bounds::default();
|
||||
let _ = &item_cx.astconv().instantiate_poly_trait_ref(
|
||||
hir_trait,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use hir::Node;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt};
|
||||
|
@ -17,8 +17,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
*providers = Providers { inferred_outlives_of, inferred_outlives_crate, ..*providers };
|
||||
}
|
||||
|
||||
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Clause<'_>, Span)] {
|
||||
let id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
|
||||
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clause<'_>, Span)] {
|
||||
let id = tcx.hir().local_def_id_to_hir_id(item_def_id);
|
||||
|
||||
if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst) && tcx.lazy_normalization()
|
||||
{
|
||||
|
@ -45,7 +45,8 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Clause<'_
|
|||
hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => {
|
||||
let crate_map = tcx.inferred_outlives_crate(());
|
||||
|
||||
let predicates = crate_map.predicates.get(&item_def_id).copied().unwrap_or(&[]);
|
||||
let predicates =
|
||||
crate_map.predicates.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]);
|
||||
|
||||
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
|
||||
let mut pred: Vec<String> = predicates
|
||||
|
|
|
@ -6,7 +6,7 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
|
|||
for id in tcx.hir().items() {
|
||||
// For unit testing: check for a special "rustc_outlives"
|
||||
// attribute and report an error with various results if found.
|
||||
if tcx.has_attr(id.owner_id.to_def_id(), sym::rustc_outlives) {
|
||||
if tcx.has_attr(id.owner_id, sym::rustc_outlives) {
|
||||
let inferred_outlives_of = tcx.inferred_outlives_of(id.owner_id);
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
|
|
|
@ -38,7 +38,7 @@ fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
|
|||
solve::solve_constraints(constraints_cx)
|
||||
}
|
||||
|
||||
fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
|
||||
fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
|
||||
// Skip items with no generics - there's nothing to infer in them.
|
||||
if tcx.generics_of(item_def_id).count() == 0 {
|
||||
return &[];
|
||||
|
@ -53,7 +53,7 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
|
|||
| DefKind::Variant
|
||||
| DefKind::Ctor(..) => {}
|
||||
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder => {
|
||||
return variance_of_opaque(tcx, item_def_id.expect_local());
|
||||
return variance_of_opaque(tcx, item_def_id);
|
||||
}
|
||||
_ => {
|
||||
// Variance not relevant.
|
||||
|
@ -64,7 +64,7 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
|
|||
// Everything else must be inferred.
|
||||
|
||||
let crate_map = tcx.crate_variances(());
|
||||
crate_map.variances.get(&item_def_id).copied().unwrap_or(&[])
|
||||
crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[])
|
||||
}
|
||||
|
||||
#[instrument(level = "trace", skip(tcx), ret)]
|
||||
|
@ -152,7 +152,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
|||
|
||||
let mut collector =
|
||||
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
|
||||
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id.to_def_id());
|
||||
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id);
|
||||
for pred in tcx.bound_explicit_item_bounds(item_def_id.to_def_id()).transpose_iter() {
|
||||
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
|
||||
debug!(?pred);
|
||||
|
|
|
@ -7,7 +7,7 @@ pub fn test_variance(tcx: TyCtxt<'_>) {
|
|||
// For unit testing: check for a special "rustc_variance"
|
||||
// attribute and report an error with various results if found.
|
||||
for id in tcx.hir().items() {
|
||||
if tcx.has_attr(id.owner_id.to_def_id(), sym::rustc_variance) {
|
||||
if tcx.has_attr(id.owner_id, sym::rustc_variance) {
|
||||
let variances_of = tcx.variances_of(id.owner_id);
|
||||
|
||||
tcx.sess.emit_err(errors::VariancesOf {
|
||||
|
|
|
@ -211,13 +211,13 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
|||
fn get_type_parameter_bounds(
|
||||
&self,
|
||||
_: Span,
|
||||
def_id: DefId,
|
||||
def_id: LocalDefId,
|
||||
_: Ident,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
||||
ty::GenericPredicates {
|
||||
parent: None,
|
||||
predicates: tcx.arena.alloc_from_iter(
|
||||
|
|
|
@ -207,7 +207,7 @@ fn typeck_with_fallback<'tcx>(
|
|||
let body = tcx.hir().body(body_id);
|
||||
|
||||
let param_env = tcx.param_env(def_id);
|
||||
let param_env = if tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
|
||||
let param_env = if tcx.has_attr(def_id, sym::rustc_do_not_const_check) {
|
||||
param_env.without_const()
|
||||
} else {
|
||||
param_env
|
||||
|
|
|
@ -1498,7 +1498,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn should_log_capture_analysis(&self, closure_def_id: LocalDefId) -> bool {
|
||||
self.tcx.has_attr(closure_def_id.to_def_id(), sym::rustc_capture_analysis)
|
||||
self.tcx.has_attr(closure_def_id, sym::rustc_capture_analysis)
|
||||
}
|
||||
|
||||
fn log_capture_analysis_first_pass(
|
||||
|
|
|
@ -44,8 +44,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
// This attribute causes us to dump some writeback information
|
||||
// in the form of errors, which is used for unit tests.
|
||||
let rustc_dump_user_substs =
|
||||
self.tcx.has_attr(item_def_id.to_def_id(), sym::rustc_dump_user_substs);
|
||||
let rustc_dump_user_substs = self.tcx.has_attr(item_def_id, sym::rustc_dump_user_substs);
|
||||
|
||||
let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_substs);
|
||||
for param in body.params {
|
||||
|
|
|
@ -371,7 +371,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
|
|||
fn check_item(&mut self, item_id: LocalDefId) {
|
||||
let item_span = self.tcx.def_span(item_id.to_def_id());
|
||||
let def_path_hash = self.tcx.def_path_hash(item_id.to_def_id());
|
||||
for attr in self.tcx.get_attrs(item_id.to_def_id(), sym::rustc_clean) {
|
||||
for attr in self.tcx.get_attrs(item_id, sym::rustc_clean) {
|
||||
let Some(assertion) = self.assertion_maybe(item_id, attr) else {
|
||||
continue;
|
||||
};
|
||||
|
|
|
@ -306,9 +306,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
// Replace the explicit self type with `Self` for better suggestion rendering
|
||||
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
|
||||
.substs;
|
||||
let trait_item_substs =
|
||||
ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id.to_def_id())
|
||||
.rebase_onto(self.tcx, impl_def_id, trait_substs);
|
||||
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
|
||||
.rebase_onto(self.tcx, impl_def_id, trait_substs);
|
||||
|
||||
let Ok(trait_predicates) = self
|
||||
.tcx
|
||||
|
|
|
@ -356,7 +356,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
if !self.same_type_modulo_infer(*found_sig, *expected_sig)
|
||||
|| !sig.is_suggestable(self.tcx, true)
|
||||
|| ty::util::is_intrinsic(self.tcx, *did)
|
||||
|| self.tcx.is_intrinsic(*did)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -400,8 +400,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
if !self.same_type_modulo_infer(*found_sig, *expected_sig)
|
||||
|| !found_sig.is_suggestable(self.tcx, true)
|
||||
|| !expected_sig.is_suggestable(self.tcx, true)
|
||||
|| ty::util::is_intrinsic(self.tcx, *did1)
|
||||
|| ty::util::is_intrinsic(self.tcx, *did2)
|
||||
|| self.tcx.is_intrinsic(*did1)
|
||||
|| self.tcx.is_intrinsic(*did2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1306,7 +1306,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
|
|||
if fn_kind.asyncness() == IsAsync::Async
|
||||
&& !cx.tcx.features().closure_track_caller
|
||||
// Now, check if the function has the `#[track_caller]` attribute
|
||||
&& let Some(attr) = cx.tcx.get_attr(def_id.to_def_id(), sym::track_caller)
|
||||
&& let Some(attr) = cx.tcx.get_attr(def_id, sym::track_caller)
|
||||
{
|
||||
cx.emit_spanned_lint(UNGATED_ASYNC_FN_TRACK_CALLER, attr.span, BuiltinUngatedAsyncFnTrackCaller {
|
||||
label: span,
|
||||
|
@ -2748,10 +2748,7 @@ impl ClashingExternDeclarations {
|
|||
// information, we could have codegen_fn_attrs also give span information back for
|
||||
// where the attribute was defined. However, until this is found to be a
|
||||
// bottleneck, this does just fine.
|
||||
(
|
||||
overridden_link_name,
|
||||
tcx.get_attr(fi.owner_id.to_def_id(), sym::link_name).unwrap().span,
|
||||
)
|
||||
(overridden_link_name, tcx.get_attr(fi.owner_id, sym::link_name).unwrap().span)
|
||||
})
|
||||
{
|
||||
SymbolName::Link(overridden_link_name, overridden_link_name_span)
|
||||
|
|
|
@ -386,7 +386,7 @@ impl LateLintPass<'_> for Diagnostics {
|
|||
for (hir_id, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
|
||||
if let Some(owner_did) = hir_id.as_owner() {
|
||||
found_parent_with_attr = found_parent_with_attr
|
||||
|| cx.tcx.has_attr(owner_did.to_def_id(), sym::rustc_lint_diagnostics);
|
||||
|| cx.tcx.has_attr(owner_did, sym::rustc_lint_diagnostics);
|
||||
}
|
||||
|
||||
debug!(?parent);
|
||||
|
|
|
@ -384,9 +384,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
|||
match &fk {
|
||||
FnKind::Method(ident, sig, ..) => match method_context(cx, id) {
|
||||
MethodLateContext::PlainImpl => {
|
||||
if sig.header.abi != Abi::Rust
|
||||
&& cx.tcx.has_attr(id.to_def_id(), sym::no_mangle)
|
||||
{
|
||||
if sig.header.abi != Abi::Rust && cx.tcx.has_attr(id, sym::no_mangle) {
|
||||
return;
|
||||
}
|
||||
self.check_snake_case(cx, "method", ident);
|
||||
|
@ -398,7 +396,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
|||
},
|
||||
FnKind::ItemFn(ident, _, header) => {
|
||||
// Skip foreign-ABI #[no_mangle] functions (Issue #31924)
|
||||
if header.abi != Abi::Rust && cx.tcx.has_attr(id.to_def_id(), sym::no_mangle) {
|
||||
if header.abi != Abi::Rust && cx.tcx.has_attr(id, sym::no_mangle) {
|
||||
return;
|
||||
}
|
||||
self.check_snake_case(cx, "function", ident);
|
||||
|
|
|
@ -13,6 +13,7 @@ use rustc_middle::arena::ArenaAllocatable;
|
|||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::exported_symbols::ExportedSymbol;
|
||||
use rustc_middle::middle::stability::DeprecationEntry;
|
||||
use rustc_middle::query::LocalCrate;
|
||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||
use rustc_middle::ty::query::{ExternProviders, Providers};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
|
@ -367,10 +368,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
|||
*providers = Providers {
|
||||
allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(),
|
||||
alloc_error_handler_kind: |tcx, ()| CStore::from_tcx(tcx).alloc_error_handler_kind(),
|
||||
is_private_dep: |_tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
false
|
||||
},
|
||||
is_private_dep: |_tcx, LocalCrate| false,
|
||||
native_library: |tcx, id| {
|
||||
tcx.native_libraries(id.krate)
|
||||
.iter()
|
||||
|
@ -386,12 +384,8 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
|||
.contains(&id)
|
||||
})
|
||||
},
|
||||
native_libraries: |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
native_libs::collect(tcx)
|
||||
},
|
||||
foreign_modules: |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
native_libraries: |tcx, LocalCrate| native_libs::collect(tcx),
|
||||
foreign_modules: |tcx, LocalCrate| {
|
||||
foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect()
|
||||
},
|
||||
|
||||
|
@ -489,14 +483,8 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
|||
},
|
||||
|
||||
dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)),
|
||||
has_global_allocator: |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
CStore::from_tcx(tcx).has_global_allocator()
|
||||
},
|
||||
has_alloc_error_handler: |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
CStore::from_tcx(tcx).has_alloc_error_handler()
|
||||
},
|
||||
has_global_allocator: |tcx, LocalCrate| CStore::from_tcx(tcx).has_global_allocator(),
|
||||
has_alloc_error_handler: |tcx, LocalCrate| CStore::from_tcx(tcx).has_alloc_error_handler(),
|
||||
postorder_cnums: |tcx, ()| {
|
||||
tcx.arena
|
||||
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
|
||||
|
|
|
@ -24,6 +24,7 @@ use rustc_middle::middle::exported_symbols::{
|
|||
metadata_symbol_name, ExportedSymbol, SymbolExportInfo,
|
||||
};
|
||||
use rustc_middle::mir::interpret;
|
||||
use rustc_middle::query::LocalCrate;
|
||||
use rustc_middle::traits::specialization_graph;
|
||||
use rustc_middle::ty::codec::TyEncoder;
|
||||
use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
|
||||
|
@ -2231,18 +2232,16 @@ pub fn provide(providers: &mut Providers) {
|
|||
doc_link_resolutions: |tcx, def_id| {
|
||||
tcx.resolutions(())
|
||||
.doc_link_resolutions
|
||||
.get(&def_id.expect_local())
|
||||
.get(&def_id)
|
||||
.expect("no resolutions for a doc link")
|
||||
},
|
||||
doc_link_traits_in_scope: |tcx, def_id| {
|
||||
tcx.resolutions(())
|
||||
.doc_link_traits_in_scope
|
||||
.get(&def_id.expect_local())
|
||||
.get(&def_id)
|
||||
.expect("no traits in scope for a doc link")
|
||||
},
|
||||
traits_in_crate: |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
traits_in_crate: |tcx, LocalCrate| {
|
||||
let mut traits = Vec::new();
|
||||
for id in tcx.hir().items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
|
||||
|
@ -2254,9 +2253,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
traits.sort_by_cached_key(|&def_id| tcx.def_path_hash(def_id));
|
||||
tcx.arena.alloc_slice(&traits)
|
||||
},
|
||||
trait_impls_in_crate: |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
trait_impls_in_crate: |tcx, LocalCrate| {
|
||||
let mut trait_impls = Vec::new();
|
||||
for id in tcx.hir().items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::hir::{ModuleItems, Owner};
|
||||
use crate::query::LocalCrate;
|
||||
use crate::ty::TyCtxt;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
|
@ -6,7 +7,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
|||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::*;
|
||||
|
@ -1131,8 +1132,7 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||
debug_assert_eq!(crate_num, LOCAL_CRATE);
|
||||
pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
|
||||
let krate = tcx.hir_crate(());
|
||||
let hir_body_hash = krate.opt_hir_hash.expect("HIR hash missing while computing crate hash");
|
||||
|
||||
|
|
|
@ -147,18 +147,18 @@ pub fn provide(providers: &mut Providers) {
|
|||
tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
|
||||
};
|
||||
providers.def_span = |tcx, def_id| {
|
||||
let def_id = def_id.expect_local();
|
||||
let def_id = def_id;
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
tcx.hir().opt_span(hir_id).unwrap_or(DUMMY_SP)
|
||||
};
|
||||
providers.def_ident_span = |tcx, def_id| {
|
||||
let def_id = def_id.expect_local();
|
||||
let def_id = def_id;
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
tcx.hir().opt_ident_span(hir_id)
|
||||
};
|
||||
providers.fn_arg_names = |tcx, id| {
|
||||
let hir = tcx.hir();
|
||||
let def_id = id.expect_local();
|
||||
let def_id = id;
|
||||
let hir_id = hir.local_def_id_to_hir_id(def_id);
|
||||
if let Some(body_id) = hir.maybe_body_owned_by(def_id) {
|
||||
tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
|
||||
|
@ -176,12 +176,10 @@ pub fn provide(providers: &mut Providers) {
|
|||
span_bug!(hir.span(hir_id), "fn_arg_names: unexpected item {:?}", id);
|
||||
}
|
||||
};
|
||||
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
|
||||
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id);
|
||||
providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
|
||||
providers.expn_that_defined = |tcx, id| {
|
||||
let id = id.expect_local();
|
||||
tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root())
|
||||
};
|
||||
providers.expn_that_defined =
|
||||
|tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root());
|
||||
providers.in_scope_traits_map = |tcx, id| {
|
||||
tcx.hir_crate(()).owners[id.def_id].as_owner().map(|owner_info| &owner_info.trait_map)
|
||||
};
|
||||
|
|
|
@ -2525,7 +2525,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id)
|
||||
&& let Some(parent_did) = parent_hir_id.as_owner()
|
||||
{
|
||||
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
|
||||
InternalSubsts::identity_for_item(tcx, parent_did)
|
||||
} else {
|
||||
List::empty()
|
||||
};
|
||||
|
@ -2554,7 +2554,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||
Self::Unevaluated(
|
||||
UnevaluatedConst {
|
||||
def: def.to_global(),
|
||||
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
|
||||
substs: InternalSubsts::identity_for_item(tcx, def.did),
|
||||
promoted: None,
|
||||
},
|
||||
ty,
|
||||
|
|
|
@ -13,6 +13,10 @@ use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCa
|
|||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
/// Placeholder for `CrateNum`'s "local" counterpart
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct LocalCrate;
|
||||
|
||||
/// The `Key` trait controls what types can legally be used as the key
|
||||
/// for a query.
|
||||
pub trait Key: Sized {
|
||||
|
@ -26,10 +30,6 @@ pub trait Key: Sized {
|
|||
// r-a issue: <https://github.com/rust-lang/rust-analyzer/issues/13693>
|
||||
type CacheSelector;
|
||||
|
||||
/// Given an instance of this key, what crate is it referring to?
|
||||
/// This is used to find the provider.
|
||||
fn query_crate_is_local(&self) -> bool;
|
||||
|
||||
/// In the event that a cycle occurs, if no explicit span has been
|
||||
/// given for a query with key `self`, what span should we use?
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span;
|
||||
|
@ -45,14 +45,17 @@ pub trait Key: Sized {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait AsLocalKey: Key {
|
||||
type LocalKey;
|
||||
|
||||
/// Given an instance of this key, what crate is it referring to?
|
||||
/// This is used to find the provider.
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey>;
|
||||
}
|
||||
|
||||
impl Key for () {
|
||||
type CacheSelector = SingleCacheSelector;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -61,23 +64,22 @@ impl Key for () {
|
|||
impl<'tcx> Key for ty::InstanceDef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.def_id().is_local()
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key for ty::Instance<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
impl<'tcx> AsLocalKey for ty::InstanceDef<'tcx> {
|
||||
type LocalKey = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.def_id().is_local()
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.def_id().is_local().then(|| *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key for ty::Instance<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
|
@ -87,11 +89,6 @@ impl<'tcx> Key for ty::Instance<'tcx> {
|
|||
impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.instance.default_span(tcx)
|
||||
}
|
||||
|
@ -100,11 +97,6 @@ impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
|
|||
impl<'tcx> Key for (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -113,11 +105,6 @@ impl<'tcx> Key for (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>) {
|
|||
impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -126,25 +113,27 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
|
|||
impl Key for CrateNum {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
*self == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
}
|
||||
|
||||
impl AsLocalKey for CrateNum {
|
||||
type LocalKey = LocalCrate;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(*self == LOCAL_CRATE).then_some(LocalCrate)
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for OwnerId {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.to_def_id().default_span(tcx)
|
||||
}
|
||||
|
||||
fn key_as_def_id(&self) -> Option<DefId> {
|
||||
Some(self.to_def_id())
|
||||
}
|
||||
|
@ -153,13 +142,10 @@ impl Key for OwnerId {
|
|||
impl Key for LocalDefId {
|
||||
type CacheSelector = VecCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.to_def_id().default_span(tcx)
|
||||
}
|
||||
|
||||
fn key_as_def_id(&self) -> Option<DefId> {
|
||||
Some(self.to_def_id())
|
||||
}
|
||||
|
@ -168,26 +154,28 @@ impl Key for LocalDefId {
|
|||
impl Key for DefId {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(*self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn key_as_def_id(&self) -> Option<DefId> {
|
||||
Some(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsLocalKey for DefId {
|
||||
type LocalKey = LocalDefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
self.as_local()
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for ty::WithOptConstParam<LocalDefId> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.did.default_span(tcx)
|
||||
}
|
||||
|
@ -196,10 +184,6 @@ impl Key for ty::WithOptConstParam<LocalDefId> {
|
|||
impl Key for SimplifiedType {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -208,10 +192,6 @@ impl Key for SimplifiedType {
|
|||
impl Key for (DefId, DefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
}
|
||||
|
@ -220,10 +200,6 @@ impl Key for (DefId, DefId) {
|
|||
impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
}
|
||||
|
@ -232,10 +208,6 @@ impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) {
|
|||
impl Key for (DefId, LocalDefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
}
|
||||
|
@ -244,10 +216,6 @@ impl Key for (DefId, LocalDefId) {
|
|||
impl Key for (LocalDefId, DefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
}
|
||||
|
@ -256,10 +224,6 @@ impl Key for (LocalDefId, DefId) {
|
|||
impl Key for (LocalDefId, LocalDefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
}
|
||||
|
@ -268,26 +232,19 @@ impl Key for (LocalDefId, LocalDefId) {
|
|||
impl Key for (DefId, Option<Ident>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn key_as_def_id(&self) -> Option<DefId> {
|
||||
Some(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for (DefId, LocalDefId, Ident) {
|
||||
impl Key for (LocalDefId, LocalDefId, Ident) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
}
|
||||
|
@ -296,34 +253,40 @@ impl Key for (DefId, LocalDefId, Ident) {
|
|||
impl Key for (CrateNum, DefId) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0 == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.1.default_span(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsLocalKey for (CrateNum, DefId) {
|
||||
type LocalKey = DefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(self.0 == LOCAL_CRATE).then(|| self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for (CrateNum, SimplifiedType) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0 == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
}
|
||||
|
||||
impl AsLocalKey for (CrateNum, SimplifiedType) {
|
||||
type LocalKey = SimplifiedType;
|
||||
|
||||
#[inline(always)]
|
||||
fn as_local_key(&self) -> Option<Self::LocalKey> {
|
||||
(self.0 == LOCAL_CRATE).then(|| self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Key for (DefId, SimplifiedType) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
}
|
||||
|
@ -332,10 +295,6 @@ impl Key for (DefId, SimplifiedType) {
|
|||
impl<'tcx> Key for SubstsRef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -344,10 +303,6 @@ impl<'tcx> Key for SubstsRef<'tcx> {
|
|||
impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
}
|
||||
|
@ -356,10 +311,6 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
|
|||
impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
(self.0).def.did.krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
(self.0).def.did.default_span(tcx)
|
||||
}
|
||||
|
@ -368,10 +319,6 @@ impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) {
|
|||
impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
}
|
||||
|
@ -380,10 +327,6 @@ impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
|
|||
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.1.def_id().krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.1.def_id())
|
||||
}
|
||||
|
@ -392,10 +335,6 @@ impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
|
|||
impl<'tcx> Key for (ty::Const<'tcx>, mir::Field) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -404,10 +343,6 @@ impl<'tcx> Key for (ty::Const<'tcx>, mir::Field) {
|
|||
impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -416,10 +351,6 @@ impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> {
|
|||
impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.def_id().krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
}
|
||||
|
@ -428,10 +359,6 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
|
|||
impl<'tcx> Key for ty::PolyExistentialTraitRef<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.def_id().krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.def_id())
|
||||
}
|
||||
|
@ -440,10 +367,6 @@ impl<'tcx> Key for ty::PolyExistentialTraitRef<'tcx> {
|
|||
impl<'tcx> Key for (ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.0.def_id().krate == LOCAL_CRATE
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.def_span(self.0.def_id())
|
||||
}
|
||||
|
@ -452,10 +375,6 @@ impl<'tcx> Key for (ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>) {
|
|||
impl<'tcx> Key for GenericArg<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -464,10 +383,6 @@ impl<'tcx> Key for GenericArg<'tcx> {
|
|||
impl<'tcx> Key for mir::ConstantKind<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -476,10 +391,6 @@ impl<'tcx> Key for mir::ConstantKind<'tcx> {
|
|||
impl<'tcx> Key for ty::Const<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -488,13 +399,10 @@ impl<'tcx> Key for ty::Const<'tcx> {
|
|||
impl<'tcx> Key for Ty<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
||||
fn ty_adt_id(&self) -> Option<DefId> {
|
||||
match self.kind() {
|
||||
ty::Adt(adt, _) => Some(adt.did()),
|
||||
|
@ -506,10 +414,6 @@ impl<'tcx> Key for Ty<'tcx> {
|
|||
impl<'tcx> Key for TyAndLayout<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -518,10 +422,6 @@ impl<'tcx> Key for TyAndLayout<'tcx> {
|
|||
impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -530,10 +430,6 @@ impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) {
|
|||
impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -542,10 +438,6 @@ impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
|
|||
impl<'tcx> Key for ty::ParamEnv<'tcx> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -554,10 +446,6 @@ impl<'tcx> Key for ty::ParamEnv<'tcx> {
|
|||
impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
self.value.query_crate_is_local()
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.value.default_span(tcx)
|
||||
}
|
||||
|
@ -566,10 +454,6 @@ impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
|
|||
impl Key for Symbol {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -578,10 +462,6 @@ impl Key for Symbol {
|
|||
impl Key for Option<Symbol> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -589,14 +469,9 @@ impl Key for Option<Symbol> {
|
|||
|
||||
/// Canonical query goals correspond to abstract trait operations that
|
||||
/// are not tied to any crate in particular.
|
||||
impl<'tcx, T> Key for Canonical<'tcx, T> {
|
||||
impl<'tcx, T: Clone> Key for Canonical<'tcx, T> {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -605,11 +480,6 @@ impl<'tcx, T> Key for Canonical<'tcx, T> {
|
|||
impl Key for (Symbol, u32, u32) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -618,11 +488,6 @@ impl Key for (Symbol, u32, u32) {
|
|||
impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -631,11 +496,6 @@ impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) {
|
|||
impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -644,11 +504,6 @@ impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) {
|
|||
impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -657,11 +512,6 @@ impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
|
|||
impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
self.0.default_span(tcx)
|
||||
}
|
||||
|
@ -670,11 +520,6 @@ impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
|
|||
impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
@ -683,11 +528,6 @@ impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) {
|
|||
impl Key for HirId {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
tcx.hir().span(*self)
|
||||
}
|
||||
|
@ -702,10 +542,6 @@ impl<'tcx> Key for (ValidityRequirement, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) {
|
|||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
// Just forward to `Ty<'tcx>`
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::ty::{self, print::describe_as_module, TyCtxt};
|
|||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
|
||||
mod keys;
|
||||
pub use keys::Key;
|
||||
pub use keys::{AsLocalKey, Key, LocalCrate};
|
||||
|
||||
// Each of these queries corresponds to a function pointer field in the
|
||||
// `Providers` struct for requesting a value of that type, and a method
|
||||
|
@ -639,7 +639,7 @@ rustc_queries! {
|
|||
|
||||
/// To avoid cycles within the predicates of a single item we compute
|
||||
/// per-type-parameter predicates for resolving `T::AssocTy`.
|
||||
query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
|
||||
query type_param_predicates(key: (LocalDefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
|
||||
desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
|
||||
}
|
||||
|
||||
|
@ -796,7 +796,6 @@ rustc_queries! {
|
|||
query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
|
||||
desc { |tcx| "creates the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
|
||||
cache_on_disk_if { true }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
||||
/// Given an `impl_id`, return the trait it implements.
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::ty::{self, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
|
|||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_macros::HashStable;
|
||||
use std::fmt;
|
||||
|
||||
|
@ -83,7 +83,7 @@ impl<'tcx> Const<'tcx> {
|
|||
None => tcx.mk_const(
|
||||
ty::UnevaluatedConst {
|
||||
def: def.to_global(),
|
||||
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
|
||||
substs: InternalSubsts::identity_for_item(tcx, def.did),
|
||||
},
|
||||
ty,
|
||||
),
|
||||
|
@ -265,8 +265,8 @@ impl<'tcx> Const<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Const<'_>> {
|
||||
let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) {
|
||||
pub fn const_param_default(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Const<'_>> {
|
||||
let default_def_id = match tcx.hir().get_by_def_id(def_id) {
|
||||
hir::Node::GenericParam(hir::GenericParam {
|
||||
kind: hir::GenericParamKind::Const { default: Some(ac), .. },
|
||||
..
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::mir::interpret::{self, Allocation, ConstAllocation};
|
|||
use crate::mir::{
|
||||
Body, BorrowCheckResult, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
|
||||
};
|
||||
use crate::query::LocalCrate;
|
||||
use crate::thir::Thir;
|
||||
use crate::traits;
|
||||
use crate::traits::solve;
|
||||
|
@ -2518,16 +2519,11 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||
|
||||
providers.extern_mod_stmt_cnum =
|
||||
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
|
||||
providers.is_panic_runtime = |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime)
|
||||
};
|
||||
providers.is_compiler_builtins = |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins)
|
||||
};
|
||||
providers.has_panic_handler = |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
providers.is_panic_runtime =
|
||||
|tcx, LocalCrate| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime);
|
||||
providers.is_compiler_builtins =
|
||||
|tcx, LocalCrate| tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins);
|
||||
providers.has_panic_handler = |tcx, LocalCrate| {
|
||||
// We want to check if the panic handler was defined in this crate
|
||||
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
|
||||
};
|
||||
|
|
|
@ -187,7 +187,11 @@ impl<'tcx> InstanceDef<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_attrs(&self, tcx: TyCtxt<'tcx>, attr: Symbol) -> ty::Attributes<'tcx> {
|
||||
pub fn get_attrs(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
attr: Symbol,
|
||||
) -> impl Iterator<Item = &'tcx rustc_ast::Attribute> {
|
||||
tcx.get_attrs(self.def_id(), attr)
|
||||
}
|
||||
|
||||
|
|
|
@ -1385,7 +1385,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
|
|||
// lifetimes with 'static and remapping only those used in the
|
||||
// `impl Trait` return type, resulting in the parameters
|
||||
// shifting.
|
||||
let id_substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let id_substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
debug!(?id_substs);
|
||||
|
||||
// This zip may have several times the same lifetime in `substs` paired with a different
|
||||
|
@ -2027,7 +2027,6 @@ impl<'tcx> FieldDef {
|
|||
}
|
||||
}
|
||||
|
||||
pub type Attributes<'tcx> = impl Iterator<Item = &'tcx ast::Attribute>;
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ImplOverlapKind {
|
||||
/// These impls are always allowed to overlap.
|
||||
|
@ -2375,7 +2374,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
/// Gets all attributes with the given name.
|
||||
pub fn get_attrs(self, did: DefId, attr: Symbol) -> ty::Attributes<'tcx> {
|
||||
pub fn get_attrs(
|
||||
self,
|
||||
did: impl Into<DefId>,
|
||||
attr: Symbol,
|
||||
) -> impl Iterator<Item = &'tcx ast::Attribute> {
|
||||
let did: DefId = did.into();
|
||||
let filter_fn = move |a: &&ast::Attribute| a.has_name(attr);
|
||||
if let Some(did) = did.as_local() {
|
||||
self.hir().attrs(self.hir().local_def_id_to_hir_id(did)).iter().filter(filter_fn)
|
||||
|
@ -2386,8 +2390,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_attr(self, did: DefId, attr: Symbol) -> Option<&'tcx ast::Attribute> {
|
||||
pub fn get_attr(self, did: impl Into<DefId>, attr: Symbol) -> Option<&'tcx ast::Attribute> {
|
||||
if cfg!(debug_assertions) && !rustc_feature::is_valid_for_get_attr(attr) {
|
||||
let did: DefId = did.into();
|
||||
bug!("get_attr: unexpected called with DefId `{:?}`, attr `{:?}`", did, attr);
|
||||
} else {
|
||||
self.get_attrs(did, attr).next()
|
||||
|
@ -2395,7 +2400,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
/// Determines whether an item is annotated with an attribute.
|
||||
pub fn has_attr(self, did: DefId, attr: Symbol) -> bool {
|
||||
pub fn has_attr(self, did: impl Into<DefId>, attr: Symbol) -> bool {
|
||||
let did: DefId = did.into();
|
||||
if cfg!(debug_assertions) && !did.is_local() && rustc_feature::is_builtin_only_local(attr) {
|
||||
bug!("tried to access the `only_local` attribute `{}` from an extern crate", attr);
|
||||
} else {
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::mir::interpret::{
|
|||
};
|
||||
use crate::mir::interpret::{LitToConstError, LitToConstInput};
|
||||
use crate::mir::mono::CodegenUnit;
|
||||
use crate::query::Key;
|
||||
use crate::query::{AsLocalKey, Key};
|
||||
use crate::thir;
|
||||
use crate::traits::query::{
|
||||
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
|
||||
|
@ -151,6 +151,20 @@ macro_rules! query_if_arena {
|
|||
};
|
||||
}
|
||||
|
||||
/// If `separate_provide_if_extern`, then the key can be projected to its
|
||||
/// local key via `<$K as AsLocalKey>::LocalKey`.
|
||||
macro_rules! local_key_if_separate_extern {
|
||||
([] $($K:tt)*) => {
|
||||
$($K)*
|
||||
};
|
||||
([(separate_provide_extern) $($rest:tt)*] $($K:tt)*) => {
|
||||
<$($K)* as AsLocalKey>::LocalKey
|
||||
};
|
||||
([$other:tt $($modifiers:tt)*] $($K:tt)*) => {
|
||||
local_key_if_separate_extern!([$($modifiers)*] $($K)*)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! separate_provide_extern_decl {
|
||||
([][$name:ident]) => {
|
||||
()
|
||||
|
@ -212,6 +226,12 @@ macro_rules! define_callbacks {
|
|||
$(pub type $name<'tcx> = $($K)*;)*
|
||||
}
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_keys_local {
|
||||
use super::*;
|
||||
|
||||
$(pub type $name<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);)*
|
||||
}
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_values {
|
||||
use super::*;
|
||||
|
||||
|
@ -385,7 +405,7 @@ macro_rules! define_callbacks {
|
|||
pub struct Providers {
|
||||
$(pub $name: for<'tcx> fn(
|
||||
TyCtxt<'tcx>,
|
||||
query_keys::$name<'tcx>,
|
||||
query_keys_local::$name<'tcx>,
|
||||
) -> query_provided::$name<'tcx>,)*
|
||||
}
|
||||
|
||||
|
@ -395,17 +415,14 @@ macro_rules! define_callbacks {
|
|||
|
||||
impl Default for Providers {
|
||||
fn default() -> Self {
|
||||
use crate::query::Key;
|
||||
|
||||
Providers {
|
||||
$($name: |_, key| bug!(
|
||||
"`tcx.{}({:?})` is not supported for {} crate;\n\
|
||||
"`tcx.{}({:?})` is not supported for this key;\n\
|
||||
hint: Queries can be either made to the local crate, or the external crate. \
|
||||
This error means you tried to use it for one that's not supported.\n\
|
||||
If that's not the case, {} was likely never assigned to a provider function.\n",
|
||||
stringify!($name),
|
||||
key,
|
||||
if key.query_crate_is_local() { "local" } else { "external" },
|
||||
stringify!($name),
|
||||
),)*
|
||||
}
|
||||
|
|
|
@ -302,8 +302,8 @@ impl<'tcx> InternalSubsts<'tcx> {
|
|||
}
|
||||
|
||||
/// Creates an `InternalSubsts` that maps each generic parameter to itself.
|
||||
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
|
||||
Self::for_item(tcx, def_id, |param, _| tcx.mk_param_from_def(param))
|
||||
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>) -> SubstsRef<'tcx> {
|
||||
Self::for_item(tcx, def_id.into(), |param, _| tcx.mk_param_from_def(param))
|
||||
}
|
||||
|
||||
/// Creates an `InternalSubsts` for generic parameter definitions,
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
|||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_index::bit_set::GrowableBitSet;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_macros::HashStable;
|
||||
|
@ -1439,8 +1439,7 @@ pub fn reveal_opaque_types_in_bounds<'tcx>(
|
|||
}
|
||||
|
||||
/// Determines whether an item is annotated with `doc(hidden)`.
|
||||
fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
assert!(def_id.is_local());
|
||||
fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
tcx.get_attrs(def_id, sym::doc)
|
||||
.filter_map(|attr| attr.meta_item_list())
|
||||
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
|
||||
|
@ -1454,7 +1453,7 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
|||
}
|
||||
|
||||
/// Determines whether an item is an intrinsic by Abi.
|
||||
pub fn is_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
pub fn is_intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic | Abi::PlatformIntrinsic)
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
|||
let trait_substs = match tcx.trait_of_item(def_id.to_def_id()) {
|
||||
Some(trait_def_id) => {
|
||||
let trait_substs_count = tcx.generics_of(trait_def_id).count();
|
||||
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
|
||||
&InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count]
|
||||
}
|
||||
_ => &[],
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! purposes on a best-effort basis. We compute them here and store them into the crate metadata so
|
||||
//! dependent crates can use them.
|
||||
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::{Body, Local, Location, Operand, Terminator, TerminatorKind, RETURN_PLACE};
|
||||
|
@ -149,7 +149,10 @@ fn type_will_always_be_passed_directly(ty: Ty<'_>) -> bool {
|
|||
/// body of the function instead of just the signature. These can be useful for optimization
|
||||
/// purposes on a best-effort basis. We compute them here and store them into the crate metadata so
|
||||
/// dependent crates can use them.
|
||||
pub fn deduced_param_attrs<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [DeducedParamAttrs] {
|
||||
pub fn deduced_param_attrs<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: LocalDefId,
|
||||
) -> &'tcx [DeducedParamAttrs] {
|
||||
// This computation is unfortunately rather expensive, so don't do it unless we're optimizing.
|
||||
// Also skip it in incremental mode.
|
||||
if tcx.sess.opts.optimize == OptLevel::No || tcx.sess.opts.incremental.is_some() {
|
||||
|
@ -182,10 +185,6 @@ pub fn deduced_param_attrs<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [Ded
|
|||
return &[];
|
||||
}
|
||||
|
||||
// Deduced attributes for other crates should be read from the metadata instead of via this
|
||||
// function.
|
||||
debug_assert!(def_id.is_local());
|
||||
|
||||
// Grab the optimized MIR. Analyze it to determine which arguments have been mutated.
|
||||
let body: &Body<'tcx> = tcx.optimized_mir(def_id);
|
||||
let mut deduce_read_only = DeduceReadOnly::new(body.arg_count);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use rustc_hir::def_id::{CrateNum, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::query::LocalCrate;
|
||||
use rustc_middle::ty::layout;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
|
@ -121,9 +122,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
|
|||
tainted
|
||||
}
|
||||
|
||||
fn required_panic_strategy(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<PanicStrategy> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrategy> {
|
||||
if tcx.is_panic_runtime(LOCAL_CRATE) {
|
||||
return Some(tcx.sess.panic_strategy());
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ use rustc_mir_dataflow::impls::{
|
|||
};
|
||||
use rustc_mir_dataflow::storage::always_storage_live_locals;
|
||||
use rustc_mir_dataflow::{self, Analysis};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
@ -1386,10 +1386,9 @@ fn create_cases<'tcx>(
|
|||
#[instrument(level = "debug", skip(tcx), ret)]
|
||||
pub(crate) fn mir_generator_witnesses<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
def_id: LocalDefId,
|
||||
) -> GeneratorLayout<'tcx> {
|
||||
assert!(tcx.sess.opts.unstable_opts.drop_tracking_mir);
|
||||
let def_id = def_id.expect_local();
|
||||
|
||||
let (body, _) = tcx.mir_promoted(ty::WithOptConstParam::unknown(def_id));
|
||||
let body = body.borrow();
|
||||
|
|
|
@ -112,7 +112,6 @@ pub fn provide(providers: &mut Providers) {
|
|||
mir_keys,
|
||||
mir_const,
|
||||
mir_const_qualif: |tcx, def_id| {
|
||||
let def_id = def_id.expect_local();
|
||||
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
||||
tcx.mir_const_qualif_const_arg(def)
|
||||
} else {
|
||||
|
@ -133,7 +132,6 @@ pub fn provide(providers: &mut Providers) {
|
|||
mir_callgraph_reachable: inline::cycle::mir_callgraph_reachable,
|
||||
mir_inliner_callees: inline::cycle::mir_inliner_callees,
|
||||
promoted_mir: |tcx, def_id| {
|
||||
let def_id = def_id.expect_local();
|
||||
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
||||
tcx.promoted_mir_of_const_arg(def)
|
||||
} else {
|
||||
|
@ -206,8 +204,7 @@ fn remap_mir_for_const_eval_select<'tcx>(
|
|||
body
|
||||
}
|
||||
|
||||
fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
let def_id = def_id.expect_local();
|
||||
fn is_mir_available(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
tcx.mir_keys(()).contains(&def_id)
|
||||
}
|
||||
|
||||
|
@ -350,12 +347,11 @@ fn mir_promoted(
|
|||
}
|
||||
|
||||
/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
|
||||
fn mir_for_ctfe(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> {
|
||||
let did = def_id.expect_local();
|
||||
if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
|
||||
fn mir_for_ctfe(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &Body<'_> {
|
||||
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
||||
tcx.mir_for_ctfe_of_const_arg(def)
|
||||
} else {
|
||||
tcx.arena.alloc(inner_mir_for_ctfe(tcx, ty::WithOptConstParam::unknown(did)))
|
||||
tcx.arena.alloc(inner_mir_for_ctfe(tcx, ty::WithOptConstParam::unknown(def_id)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -599,8 +595,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
}
|
||||
|
||||
/// Optimize the MIR and prepare it for codegen.
|
||||
fn optimized_mir(tcx: TyCtxt<'_>, did: DefId) -> &Body<'_> {
|
||||
let did = did.expect_local();
|
||||
fn optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> &Body<'_> {
|
||||
assert_eq!(ty::WithOptConstParam::try_lookup(did, tcx), None);
|
||||
tcx.arena.alloc(inner_optimized_mir(tcx, did))
|
||||
}
|
||||
|
|
|
@ -104,9 +104,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
|
|||
|
||||
// If this crate is not using stability attributes, or this function is not claiming to be a
|
||||
// stable `const fn`, that is all that is required.
|
||||
if !tcx.features().staged_api
|
||||
|| tcx.has_attr(def_id.to_def_id(), sym::rustc_const_unstable)
|
||||
{
|
||||
if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -469,9 +469,9 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
|||
|
||||
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
fn has_lang_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
tcx.has_attr(def_id.to_def_id(), sym::lang)
|
||||
tcx.has_attr(def_id, sym::lang)
|
||||
// Stable attribute for #[lang = "panic_impl"]
|
||||
|| tcx.has_attr(def_id.to_def_id(), sym::panic_handler)
|
||||
|| tcx.has_attr(def_id, sym::panic_handler)
|
||||
}
|
||||
|
||||
fn has_allow_dead_code(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
|
|
|
@ -4,11 +4,9 @@ use hir::CRATE_HIR_ID;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_expand::base::resolve_path;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::CrateNum;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_middle::{query::LocalCrate, ty::query::Providers};
|
||||
use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
@ -69,9 +67,7 @@ fn check_for_debugger_visualizer(
|
|||
}
|
||||
|
||||
/// Traverses and collects the debugger visualizers for a specific crate.
|
||||
fn debugger_visualizers(tcx: TyCtxt<'_>, cnum: CrateNum) -> Vec<DebuggerVisualizerFile> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec<DebuggerVisualizerFile> {
|
||||
// Initialize the collector.
|
||||
let mut debugger_visualizers = FxHashSet::default();
|
||||
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
use rustc_ast as ast;
|
||||
use rustc_hir::diagnostic_items::DiagnosticItems;
|
||||
use rustc_hir::OwnerId;
|
||||
use rustc_middle::query::LocalCrate;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc_span::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
|
||||
use crate::errors::DuplicateDiagnosticItemInCrate;
|
||||
|
@ -62,9 +63,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
|
|||
}
|
||||
|
||||
/// Traverse and collect the diagnostic items in the current
|
||||
fn diagnostic_items(tcx: TyCtxt<'_>, cnum: CrateNum) -> DiagnosticItems {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
fn diagnostic_items(tcx: TyCtxt<'_>, _: LocalCrate) -> DiagnosticItems {
|
||||
// Initialize the collector.
|
||||
let mut diagnostic_items = DiagnosticItems::default();
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ pub fn test_layout(tcx: TyCtxt<'_>) {
|
|||
tcx.def_kind(id.owner_id),
|
||||
DefKind::TyAlias | DefKind::Enum | DefKind::Struct | DefKind::Union
|
||||
) {
|
||||
for attr in tcx.get_attrs(id.owner_id.to_def_id(), sym::rustc_layout) {
|
||||
for attr in tcx.get_attrs(id.owner_id, sym::rustc_layout) {
|
||||
dump_layout_of(tcx, id.owner_id.def_id, attr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: DefId) {
|
|||
// Don't run unused pass for #[derive()]
|
||||
let parent = tcx.local_parent(local_def_id);
|
||||
if let DefKind::Impl { .. } = tcx.def_kind(parent)
|
||||
&& tcx.has_attr(parent.to_def_id(), sym::automatically_derived)
|
||||
&& tcx.has_attr(parent, sym::automatically_derived)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
|||
continue;
|
||||
}
|
||||
|
||||
let naked = tcx.has_attr(def_id.to_def_id(), sym::naked);
|
||||
let naked = tcx.has_attr(def_id, sym::naked);
|
||||
if !naked {
|
||||
continue;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
|||
|
||||
/// Check that the function isn't inlined.
|
||||
fn check_inline(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
let attrs = tcx.get_attrs(def_id.to_def_id(), sym::inline);
|
||||
let attrs = tcx.get_attrs(def_id, sym::inline);
|
||||
for attr in attrs {
|
||||
tcx.sess.emit_err(CannotInlineNakedFunction { span: attr.span });
|
||||
}
|
||||
|
|
|
@ -691,14 +691,10 @@ pub(crate) fn provide(providers: &mut Providers) {
|
|||
check_mod_unstable_api_usage,
|
||||
stability_index,
|
||||
stability_implications: |tcx, _| tcx.stability().implications.clone(),
|
||||
lookup_stability: |tcx, id| tcx.stability().local_stability(id.expect_local()),
|
||||
lookup_const_stability: |tcx, id| tcx.stability().local_const_stability(id.expect_local()),
|
||||
lookup_default_body_stability: |tcx, id| {
|
||||
tcx.stability().local_default_body_stability(id.expect_local())
|
||||
},
|
||||
lookup_deprecation_entry: |tcx, id| {
|
||||
tcx.stability().local_deprecation_entry(id.expect_local())
|
||||
},
|
||||
lookup_stability: |tcx, id| tcx.stability().local_stability(id),
|
||||
lookup_const_stability: |tcx, id| tcx.stability().local_const_stability(id),
|
||||
lookup_default_body_stability: |tcx, id| tcx.stability().local_default_body_stability(id),
|
||||
lookup_deprecation_entry: |tcx, id| tcx.stability().local_deprecation_entry(id),
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
|
@ -920,7 +920,7 @@ pub struct TestReachabilityVisitor<'tcx, 'a> {
|
|||
|
||||
impl<'tcx, 'a> TestReachabilityVisitor<'tcx, 'a> {
|
||||
fn effective_visibility_diagnostic(&mut self, def_id: LocalDefId) {
|
||||
if self.tcx.has_attr(def_id.to_def_id(), sym::rustc_effective_visibility) {
|
||||
if self.tcx.has_attr(def_id, sym::rustc_effective_visibility) {
|
||||
let mut error_msg = String::new();
|
||||
let span = self.tcx.def_span(def_id.to_def_id());
|
||||
if let Some(effective_vis) = self.effective_visibilities.effective_vis(def_id) {
|
||||
|
@ -2060,8 +2060,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
};
|
||||
}
|
||||
|
||||
fn visibility(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Visibility<DefId> {
|
||||
local_visibility(tcx, def_id.expect_local()).to_def_id()
|
||||
fn visibility(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Visibility<DefId> {
|
||||
local_visibility(tcx, def_id).to_def_id()
|
||||
}
|
||||
|
||||
fn local_visibility(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Visibility {
|
||||
|
|
|
@ -20,7 +20,7 @@ extern crate rustc_middle;
|
|||
use rustc_data_structures::sync::AtomicU64;
|
||||
use rustc_middle::arena::Arena;
|
||||
use rustc_middle::dep_graph::{self, DepKindStruct};
|
||||
use rustc_middle::query::Key;
|
||||
use rustc_middle::query::AsLocalKey;
|
||||
use rustc_middle::ty::query::{
|
||||
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
|
||||
};
|
||||
|
|
|
@ -274,19 +274,19 @@ macro_rules! hash_result {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! get_provider {
|
||||
([][$tcx:expr, $name:ident, $key:expr]) => {{
|
||||
$tcx.queries.local_providers.$name
|
||||
macro_rules! call_provider {
|
||||
([][$qcx:expr, $name:ident, $key:expr]) => {{
|
||||
($qcx.queries.local_providers.$name)($qcx.tcx, $key)
|
||||
}};
|
||||
([(separate_provide_extern) $($rest:tt)*][$tcx:expr, $name:ident, $key:expr]) => {{
|
||||
if $key.query_crate_is_local() {
|
||||
$tcx.queries.local_providers.$name
|
||||
([(separate_provide_extern) $($rest:tt)*][$qcx:expr, $name:ident, $key:expr]) => {{
|
||||
if let Some(key) = $key.as_local_key() {
|
||||
($qcx.queries.local_providers.$name)($qcx.tcx, key)
|
||||
} else {
|
||||
$tcx.queries.extern_providers.$name
|
||||
($qcx.queries.extern_providers.$name)($qcx.tcx, $key)
|
||||
}
|
||||
}};
|
||||
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
|
||||
get_provider!([$($modifiers)*][$($args)*])
|
||||
call_provider!([$($modifiers)*][$($args)*])
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -516,7 +516,7 @@ macro_rules! define_queries {
|
|||
fn compute(self, qcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
|
||||
query_provided_to_value::$name(
|
||||
qcx.tcx,
|
||||
get_provider!([$($modifiers)*][qcx, $name, key])(qcx.tcx, key)
|
||||
call_provider!([$($modifiers)*][qcx, $name, key])
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ impl SymbolNamesTest<'_> {
|
|||
// The formatting of `tag({})` is chosen so that tests can elect
|
||||
// to test the entirety of the string, if they choose, or else just
|
||||
// some subset.
|
||||
for attr in tcx.get_attrs(def_id.to_def_id(), SYMBOL_NAME) {
|
||||
for attr in tcx.get_attrs(def_id, SYMBOL_NAME) {
|
||||
let def_id = def_id.to_def_id();
|
||||
let instance = Instance::new(
|
||||
def_id,
|
||||
|
@ -79,7 +79,7 @@ impl SymbolNamesTest<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
for attr in tcx.get_attrs(def_id.to_def_id(), DEF_PATH) {
|
||||
for attr in tcx.get_attrs(def_id, DEF_PATH) {
|
||||
tcx.sess.emit_err(TestOutput {
|
||||
span: attr.span,
|
||||
kind: Kind::DefPath,
|
||||
|
|
|
@ -18,8 +18,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||
};
|
||||
}
|
||||
|
||||
fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
|
||||
let item = tcx.hir().expect_item(def_id.expect_local());
|
||||
fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
|
||||
let item = tcx.hir().expect_item(def_id);
|
||||
match item.kind {
|
||||
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
||||
if tcx.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
|
@ -107,27 +107,26 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> DefIdMap<DefId>
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
|
||||
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
fn associated_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AssocItem {
|
||||
let id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let parent_def_id = tcx.hir().get_parent_item(id);
|
||||
let parent_item = tcx.hir().expect_item(parent_def_id.def_id);
|
||||
match parent_item.kind {
|
||||
hir::ItemKind::Impl(ref impl_) => {
|
||||
if let Some(impl_item_ref) =
|
||||
impl_.items.iter().find(|i| i.id.owner_id.to_def_id() == def_id)
|
||||
if let Some(impl_item_ref) = impl_.items.iter().find(|i| i.id.owner_id.def_id == def_id)
|
||||
{
|
||||
let assoc_item = associated_item_from_impl_item_ref(impl_item_ref);
|
||||
debug_assert_eq!(assoc_item.def_id, def_id);
|
||||
debug_assert_eq!(assoc_item.def_id.expect_local(), def_id);
|
||||
return assoc_item;
|
||||
}
|
||||
}
|
||||
|
||||
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
||||
if let Some(trait_item_ref) =
|
||||
trait_item_refs.iter().find(|i| i.id.owner_id.to_def_id() == def_id)
|
||||
trait_item_refs.iter().find(|i| i.id.owner_id.def_id == def_id)
|
||||
{
|
||||
let assoc_item = associated_item_from_trait_item_ref(trait_item_ref);
|
||||
debug_assert_eq!(assoc_item.def_id, def_id);
|
||||
debug_assert_eq!(assoc_item.def_id.expect_local(), def_id);
|
||||
return assoc_item;
|
||||
}
|
||||
}
|
||||
|
@ -191,9 +190,9 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
|
|||
/// above, synthesize a corresponding associated type in the impl.
|
||||
fn associated_types_for_impl_traits_in_associated_fn(
|
||||
tcx: TyCtxt<'_>,
|
||||
fn_def_id: DefId,
|
||||
fn_def_id: LocalDefId,
|
||||
) -> &'_ [DefId] {
|
||||
let parent_def_id = tcx.parent(fn_def_id);
|
||||
let parent_def_id = tcx.local_parent(fn_def_id);
|
||||
|
||||
match tcx.def_kind(parent_def_id) {
|
||||
DefKind::Trait => {
|
||||
|
@ -212,7 +211,7 @@ fn associated_types_for_impl_traits_in_associated_fn(
|
|||
|
||||
let mut visitor = RPITVisitor { rpits: Vec::new() };
|
||||
|
||||
if let Some(output) = tcx.hir().get_fn_output(fn_def_id.expect_local()) {
|
||||
if let Some(output) = tcx.hir().get_fn_output(fn_def_id) {
|
||||
visitor.visit_fn_ret_ty(output);
|
||||
|
||||
tcx.arena.alloc_from_iter(visitor.rpits.iter().map(|opaque_ty_def_id| {
|
||||
|
@ -232,7 +231,7 @@ fn associated_types_for_impl_traits_in_associated_fn(
|
|||
associated_type_for_impl_trait_in_impl(
|
||||
tcx,
|
||||
trait_assoc_def_id.expect_local(),
|
||||
fn_def_id.expect_local(),
|
||||
fn_def_id,
|
||||
)
|
||||
.to_def_id()
|
||||
},
|
||||
|
@ -297,7 +296,7 @@ fn associated_type_for_impl_trait_in_trait(
|
|||
// Copy type_of of the opaque.
|
||||
trait_assoc_ty.type_of(ty::EarlyBinder(tcx.mk_opaque(
|
||||
opaque_ty_def_id.to_def_id(),
|
||||
InternalSubsts::identity_for_item(tcx, opaque_ty_def_id.to_def_id()),
|
||||
InternalSubsts::identity_for_item(tcx, opaque_ty_def_id),
|
||||
)));
|
||||
|
||||
trait_assoc_ty.is_type_alias_impl_trait(false);
|
||||
|
|
|
@ -425,7 +425,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||
*providers = ty::query::Providers {
|
||||
destructure_const,
|
||||
thir_abstract_const: |tcx, def_id| {
|
||||
let def_id = def_id.expect_local();
|
||||
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
||||
tcx.thir_abstract_const_of_const_arg(def)
|
||||
} else {
|
||||
|
|
|
@ -4,7 +4,7 @@ use rustc_hir::def::DefKind;
|
|||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, Representability, Ty, TyCtxt};
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers =
|
||||
|
@ -85,7 +85,7 @@ fn representability_adt_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Representab
|
|||
Representability::Representable
|
||||
}
|
||||
|
||||
fn params_in_repr(tcx: TyCtxt<'_>, def_id: DefId) -> BitSet<u32> {
|
||||
fn params_in_repr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BitSet<u32> {
|
||||
let adt_def = tcx.adt_def(def_id);
|
||||
let generics = tcx.generics_of(def_id);
|
||||
let mut params_in_repr = BitSet::new_empty(generics.params.len());
|
||||
|
|
|
@ -7,10 +7,8 @@ use rustc_middle::ty::{
|
|||
TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
|
||||
};
|
||||
use rustc_session::config::TraitSolver;
|
||||
use rustc_span::{
|
||||
def_id::{DefId, CRATE_DEF_ID},
|
||||
DUMMY_SP,
|
||||
};
|
||||
use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_trait_selection::traits;
|
||||
|
||||
fn sized_constraint_for_ty<'tcx>(
|
||||
|
@ -79,8 +77,8 @@ fn sized_constraint_for_ty<'tcx>(
|
|||
result
|
||||
}
|
||||
|
||||
fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness {
|
||||
match tcx.hir().get_by_def_id(def_id.expect_local()) {
|
||||
fn impl_defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness {
|
||||
match tcx.hir().get_by_def_id(def_id) {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.defaultness,
|
||||
hir::Node::ImplItem(hir::ImplItem { defaultness, .. })
|
||||
| hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness,
|
||||
|
@ -516,8 +514,8 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'
|
|||
}
|
||||
|
||||
/// Check if a function is async.
|
||||
fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
|
||||
let node = tcx.hir().get_by_def_id(def_id.expect_local());
|
||||
fn asyncness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::IsAsync {
|
||||
let node = tcx.hir().get_by_def_id(def_id);
|
||||
node.fn_sig().map_or(hir::IsAsync::NotAsync, |sig| sig.header.asyncness)
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
|
|||
span: Span,
|
||||
def_id: LocalDefId,
|
||||
) {
|
||||
if !cx.tcx.has_attr(def_id.to_def_id(), sym::test) {
|
||||
if !cx.tcx.has_attr(def_id, sym::test) {
|
||||
let expr = if is_async_fn(kind) {
|
||||
match get_async_fn_body(cx.tcx, body) {
|
||||
Some(b) => b,
|
||||
|
|
|
@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
|
|||
self_ty,
|
||||
..
|
||||
}) = item.kind;
|
||||
if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived);
|
||||
if !cx.tcx.has_attr(item.owner_id, sym::automatically_derived);
|
||||
if !item.span.from_expansion();
|
||||
if let Some(def_id) = trait_ref.trait_def_id();
|
||||
if cx.tcx.is_diagnostic_item(sym::Default, def_id);
|
||||
|
|
|
@ -212,7 +212,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
|
|||
}) = item.kind
|
||||
{
|
||||
let ty = cx.tcx.type_of(item.owner_id).subst_identity();
|
||||
let is_automatically_derived = cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived);
|
||||
let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived);
|
||||
|
||||
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
|
||||
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);
|
||||
|
|
|
@ -22,7 +22,7 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
|
|||
|
||||
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
|
||||
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
|
||||
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind {
|
||||
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
|
@ -47,7 +47,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
|
|||
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
|
||||
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
|
||||
} else if is_public
|
||||
|
@ -73,7 +73,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
|
|||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
|
||||
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
|
||||
} else if let hir::TraitFn::Provided(eid) = *eid {
|
||||
|
|
|
@ -36,7 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
|
|||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if_chain! {
|
||||
if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind;
|
||||
if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived);
|
||||
if !cx.tcx.has_attr(item.owner_id, sym::automatically_derived);
|
||||
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
|
||||
if trait_ref.path.res.def_id() == eq_trait;
|
||||
then {
|
||||
|
|
|
@ -22,13 +22,14 @@ use log::debug;
|
|||
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_driver::Compilation;
|
||||
use rustc_hir::{self as hir, def_id::LOCAL_CRATE, Node};
|
||||
use rustc_hir::{self as hir, Node};
|
||||
use rustc_interface::interface::Config;
|
||||
use rustc_middle::{
|
||||
middle::exported_symbols::{
|
||||
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
|
||||
},
|
||||
ty::{query::ExternProviders, TyCtxt},
|
||||
query::LocalCrate,
|
||||
};
|
||||
use rustc_session::{config::CrateType, search_paths::PathKind, CtfeBacktrace};
|
||||
|
||||
|
@ -107,8 +108,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
|
|||
config.override_queries = Some(|_, local_providers, _| {
|
||||
// `exported_symbols` and `reachable_non_generics` provided by rustc always returns
|
||||
// an empty result if `tcx.sess.opts.output_types.should_codegen()` is false.
|
||||
local_providers.exported_symbols = |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
local_providers.exported_symbols = |tcx, LocalCrate| {
|
||||
let reachable_set = tcx.with_stable_hashing_context(|hcx| {
|
||||
tcx.reachable_set(()).to_sorted(&hcx, true)
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue