commit
d8795fab18
208 changed files with 3132 additions and 1799 deletions
3
.mailmap
3
.mailmap
|
|
@ -29,6 +29,8 @@ Alexander Ronald Altman <alexanderaltman@me.com>
|
|||
Alexandre Martin <martin.alex32@hotmail.fr>
|
||||
Alexis Beingessner <a.beingessner@gmail.com>
|
||||
Alfie John <alfie@alfie.wtf> Alfie John <alfiej@fastmail.fm>
|
||||
Alona Enraght-Moony <code@alona.page> <nixon.emoony@gmail.com>
|
||||
Alona Enraght-Moony <code@alona.page> <nixon@caminus.local>
|
||||
Amos Onn <amosonn@gmail.com>
|
||||
Ana-Maria Mihalache <mihalacheana.maria@yahoo.com>
|
||||
Anatoly Ikorsky <aikorsky@gmail.com>
|
||||
|
|
@ -415,7 +417,6 @@ Nicolas Abram <abramlujan@gmail.com>
|
|||
Nicole Mazzuca <npmazzuca@gmail.com>
|
||||
Nif Ward <nif.ward@gmail.com>
|
||||
Nika Layzell <nika@thelayzells.com> <michael@thelayzells.com>
|
||||
Nixon Enraght-Moony <nixon.emoony@gmail.com>
|
||||
NODA Kai <nodakai@gmail.com>
|
||||
oliver <16816606+o752d@users.noreply.github.com>
|
||||
Oliver Middleton <olliemail27@gmail.com> <ollie27@users.noreply.github.com>
|
||||
|
|
|
|||
|
|
@ -1128,9 +1128,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "curl-sys"
|
||||
version = "0.4.59+curl-7.86.0"
|
||||
version = "0.4.61+curl-8.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6cfce34829f448b08f55b7db6d0009e23e2e86a34e8c2b366269bf5799b4a407"
|
||||
checksum = "14d05c10f541ae6f3bc5b3d923c20001f47db7d5f0b2bc6ad16490133842db79"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use rustc_span::hygiene::DesugaringKind;
|
|||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_span::{BytePos, Span, Symbol};
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
|
||||
use crate::borrow_set::TwoPhaseActivation;
|
||||
use crate::borrowck_errors;
|
||||
|
|
@ -760,20 +761,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
else { return; };
|
||||
// Try to find predicates on *generic params* that would allow copying `ty`
|
||||
let infcx = tcx.infer_ctxt().build();
|
||||
let copy_did = infcx.tcx.require_lang_item(LangItem::Copy, Some(span));
|
||||
let cause = ObligationCause::new(
|
||||
span,
|
||||
self.mir_def_id(),
|
||||
rustc_infer::traits::ObligationCauseCode::MiscObligation,
|
||||
);
|
||||
let errors = rustc_trait_selection::traits::fully_solve_bound(
|
||||
&infcx,
|
||||
cause,
|
||||
self.param_env,
|
||||
// Erase any region vids from the type, which may not be resolved
|
||||
infcx.tcx.erase_regions(ty),
|
||||
copy_did,
|
||||
);
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let copy_did = tcx.require_lang_item(LangItem::Copy, Some(span));
|
||||
let cause = ObligationCause::misc(span, self.mir_def_id());
|
||||
|
||||
ocx.register_bound(cause, self.param_env, infcx.tcx.erase_regions(ty), copy_did);
|
||||
let errors = ocx.select_all_or_error();
|
||||
|
||||
// Only emit suggestion if all required predicates are on generic
|
||||
let predicates: Result<Vec<_>, _> = errors
|
||||
|
|
|
|||
|
|
@ -1078,7 +1078,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self.param_env,
|
||||
tcx.mk_imm_ref(tcx.lifetimes.re_erased, tcx.erase_regions(ty)),
|
||||
def_id,
|
||||
DUMMY_SP,
|
||||
)
|
||||
}
|
||||
_ => false,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -176,15 +176,14 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
|
|||
|
||||
return_if_di_node_created_in_meantime!(cx, unique_type_id);
|
||||
|
||||
let (thin_pointer_size, thin_pointer_align) =
|
||||
cx.size_and_align_of(cx.tcx.mk_imm_ptr(cx.tcx.types.unit));
|
||||
let data_layout = &cx.tcx.data_layout;
|
||||
let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true);
|
||||
|
||||
match fat_pointer_kind(cx, pointee_type) {
|
||||
None => {
|
||||
// This is a thin pointer. Create a regular pointer type and give it the correct name.
|
||||
debug_assert_eq!(
|
||||
(thin_pointer_size, thin_pointer_align),
|
||||
(data_layout.pointer_size, data_layout.pointer_align.abi),
|
||||
cx.size_and_align_of(ptr_type),
|
||||
"ptr_type={}, pointee_type={}",
|
||||
ptr_type,
|
||||
|
|
@ -195,8 +194,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
|
|||
llvm::LLVMRustDIBuilderCreatePointerType(
|
||||
DIB(cx),
|
||||
pointee_type_di_node,
|
||||
thin_pointer_size.bits(),
|
||||
thin_pointer_align.bits() as u32,
|
||||
data_layout.pointer_size.bits(),
|
||||
data_layout.pointer_align.abi.bits() as u32,
|
||||
0, // Ignore DWARF address space.
|
||||
ptr_type_debuginfo_name.as_ptr().cast(),
|
||||
ptr_type_debuginfo_name.len(),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use rustc_middle::mir;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
|
||||
use rustc_trait_selection::traits::{
|
||||
self, ImplSource, Obligation, ObligationCause, SelectionContext,
|
||||
self, ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext,
|
||||
};
|
||||
|
||||
use super::ConstCx;
|
||||
|
|
@ -184,7 +184,10 @@ impl Qualif for NeedsNonConstDrop {
|
|||
}
|
||||
|
||||
// If we had any errors, then it's bad
|
||||
!traits::fully_solve_obligations(&infcx, impl_src.nested_obligations()).is_empty()
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
ocx.register_obligations(impl_src.nested_obligations());
|
||||
let errors = ocx.select_all_or_error();
|
||||
!errors.is_empty()
|
||||
}
|
||||
|
||||
fn in_adt_inherently<'tcx>(
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ impl CodeSuggestion {
|
|||
});
|
||||
buf.push_str(&part.snippet);
|
||||
let cur_hi = sm.lookup_char_pos(part.span.hi());
|
||||
if cur_hi.line == cur_lo.line {
|
||||
if cur_hi.line == cur_lo.line && !part.snippet.is_empty() {
|
||||
// Account for the difference between the width of the current code and the
|
||||
// snippet being suggested, so that the *later* suggestions are correctly
|
||||
// aligned on the screen.
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ fn equate_intrinsic_type<'tcx>(
|
|||
require_same_types(
|
||||
tcx,
|
||||
&cause,
|
||||
ty::ParamEnv::empty(), // FIXME: do all intrinsics have an empty param env?
|
||||
tcx.mk_fn_ptr(tcx.fn_sig(it.owner_id).subst_identity()),
|
||||
fty,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -11,13 +11,14 @@ use rustc_hir::ItemKind;
|
|||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
use rustc_infer::infer::{self, RegionResolutionError};
|
||||
use rustc_infer::infer::{DefineOpaqueTypes, TyCtxtInferExt};
|
||||
use rustc_infer::traits::Obligation;
|
||||
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
|
||||
use rustc_middle::ty::{self, suggest_constraining_type_params, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
|
||||
use rustc_trait_selection::traits::misc::{
|
||||
type_allowed_to_implement_copy, CopyImplementationError, InfringingFieldsReason,
|
||||
};
|
||||
use rustc_trait_selection::traits::predicate_for_trait_def;
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
use rustc_trait_selection::traits::{self, ObligationCause};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
|
|
@ -334,19 +335,19 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
|||
))
|
||||
.emit();
|
||||
} else {
|
||||
let errors = traits::fully_solve_obligations(
|
||||
&infcx,
|
||||
coerced_fields.into_iter().map(|field| {
|
||||
predicate_for_trait_def(
|
||||
tcx,
|
||||
param_env,
|
||||
cause.clone(),
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
for field in coerced_fields {
|
||||
ocx.register_obligation(Obligation::new(
|
||||
tcx,
|
||||
cause.clone(),
|
||||
param_env,
|
||||
ty::Binder::dummy(tcx.mk_trait_ref(
|
||||
dispatch_from_dyn_trait,
|
||||
0,
|
||||
[field.ty(tcx, substs_a), field.ty(tcx, substs_b)],
|
||||
)
|
||||
}),
|
||||
);
|
||||
)),
|
||||
));
|
||||
}
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
}
|
||||
|
|
@ -368,11 +369,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));
|
||||
|
|
@ -583,10 +581,12 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
|
|||
};
|
||||
|
||||
// Register an obligation for `A: Trait<B>`.
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let cause = traits::ObligationCause::misc(span, impl_did);
|
||||
let predicate =
|
||||
predicate_for_trait_def(tcx, param_env, cause, trait_def_id, 0, [source, target]);
|
||||
let errors = traits::fully_solve_obligation(&infcx, predicate);
|
||||
let obligation =
|
||||
Obligation::new(tcx, cause, param_env, tcx.mk_trait_ref(trait_def_id, [source, target]));
|
||||
ocx.register_obligation(obligation);
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
@ -605,7 +606,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
|
|||
found: Option<ty::OpaqueHiddenType<'tcx>>,
|
||||
|
||||
/// In the presence of dead code, typeck may figure out a hidden type
|
||||
/// while borrowck will now. We collect these cases here and check at
|
||||
/// while borrowck will not. We collect these cases here and check at
|
||||
/// the end that we actually found a type that matches (modulo regions).
|
||||
typeck_types: Vec<ty::OpaqueHiddenType<'tcx>>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use rustc_infer::traits::{ObligationCause, WellFormedLoc};
|
|||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, Region, TyCtxt, TypeFoldable, TypeFolder};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_trait_selection::traits;
|
||||
use rustc_trait_selection::traits::{self, ObligationCtxt};
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { diagnostic_hir_wf_check, ..*providers };
|
||||
|
|
@ -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,
|
||||
|
|
@ -66,35 +66,35 @@ fn diagnostic_hir_wf_check<'tcx>(
|
|||
impl<'tcx> Visitor<'tcx> for HirWfCheck<'tcx> {
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
|
||||
let infcx = self.tcx.infer_ctxt().build();
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
|
||||
let tcx_ty = self.icx.to_ty(ty).fold_with(&mut EraseAllBoundRegions { tcx: self.tcx });
|
||||
let cause = traits::ObligationCause::new(
|
||||
ty.span,
|
||||
self.def_id,
|
||||
traits::ObligationCauseCode::WellFormed(None),
|
||||
);
|
||||
let errors = traits::fully_solve_obligation(
|
||||
&infcx,
|
||||
traits::Obligation::new(
|
||||
self.tcx,
|
||||
cause,
|
||||
self.param_env,
|
||||
ty::Binder::dummy(ty::PredicateKind::WellFormed(tcx_ty.into())),
|
||||
),
|
||||
);
|
||||
if !errors.is_empty() {
|
||||
debug!("Wf-check got errors for {:?}: {:?}", ty, errors);
|
||||
for error in errors {
|
||||
if error.obligation.predicate == self.predicate {
|
||||
// Save the cause from the greatest depth - this corresponds
|
||||
// to picking more-specific types (e.g. `MyStruct<u8>`)
|
||||
// over less-specific types (e.g. `Option<MyStruct<u8>>`)
|
||||
if self.depth >= self.cause_depth {
|
||||
self.cause = Some(error.obligation.cause);
|
||||
self.cause_depth = self.depth
|
||||
}
|
||||
|
||||
ocx.register_obligation(traits::Obligation::new(
|
||||
self.tcx,
|
||||
cause,
|
||||
self.param_env,
|
||||
ty::PredicateKind::WellFormed(tcx_ty.into()),
|
||||
));
|
||||
|
||||
for error in ocx.select_all_or_error() {
|
||||
debug!("Wf-check got error for {:?}: {:?}", ty, error);
|
||||
if error.obligation.predicate == self.predicate {
|
||||
// Save the cause from the greatest depth - this corresponds
|
||||
// to picking more-specific types (e.g. `MyStruct<u8>`)
|
||||
// over less-specific types (e.g. `Option<MyStruct<u8>>`)
|
||||
if self.depth >= self.cause_depth {
|
||||
self.cause = Some(error.obligation.cause);
|
||||
self.cause_depth = self.depth
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.depth += 1;
|
||||
intravisit::walk_ty(self, ty);
|
||||
self.depth -= 1;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ use rustc_errors::ErrorGuaranteed;
|
|||
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::Node;
|
||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TyCtxtInferExt};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_macros::fluent_messages;
|
||||
use rustc_middle::middle;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
|
|
@ -113,7 +113,7 @@ use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
|||
use rustc_span::{symbol::sym, Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
|
||||
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
|
||||
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode, ObligationCtxt};
|
||||
|
||||
use std::ops::Not;
|
||||
|
||||
|
|
@ -160,24 +160,21 @@ fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi
|
|||
fn require_same_types<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
) -> bool {
|
||||
) {
|
||||
let infcx = &tcx.infer_ctxt().build();
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
let errors = match infcx.at(cause, param_env).eq(DefineOpaqueTypes::No, expected, actual) {
|
||||
Ok(InferOk { obligations, .. }) => traits::fully_solve_obligations(infcx, obligations),
|
||||
let ocx = ObligationCtxt::new(infcx);
|
||||
match ocx.eq(cause, param_env, expected, actual) {
|
||||
Ok(()) => {
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
infcx.err_ctxt().report_mismatched_types(cause, expected, actual, err).emit();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
match &errors[..] {
|
||||
[] => true,
|
||||
errors => {
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -296,6 +293,8 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Main should have no WC, so empty param env is OK here.
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
let expected_return_type;
|
||||
if let Some(term_did) = tcx.lang_items().termination() {
|
||||
let return_ty = main_fnsig.output();
|
||||
|
|
@ -306,8 +305,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
|
|||
}
|
||||
let return_ty = return_ty.skip_binder();
|
||||
let infcx = tcx.infer_ctxt().build();
|
||||
// Main should have no WC, so empty param env is OK here.
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
let cause = traits::ObligationCause::new(
|
||||
return_ty_span,
|
||||
main_diagnostics_def_id,
|
||||
|
|
@ -343,6 +340,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
|
|||
main_diagnostics_def_id,
|
||||
ObligationCauseCode::MainFunctionType,
|
||||
),
|
||||
param_env,
|
||||
se_ty,
|
||||
tcx.mk_fn_ptr(main_fnsig),
|
||||
);
|
||||
|
|
@ -417,6 +415,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
|||
start_def_id,
|
||||
ObligationCauseCode::StartFunctionType,
|
||||
),
|
||||
ty::ParamEnv::empty(), // start should not have any where bounds.
|
||||
se_ty,
|
||||
tcx.mk_fn_ptr(tcx.fn_sig(start_def_id).subst_identity()),
|
||||
);
|
||||
|
|
@ -513,7 +512,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 +525,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 {
|
||||
|
|
|
|||
|
|
@ -668,7 +668,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
if !self.maybe_suggest_bad_array_definition(&mut err, call_expr, callee_expr) {
|
||||
if let Some((maybe_def, output_ty, _)) = self.extract_callable_info(callee_ty)
|
||||
&& !self.type_is_sized_modulo_regions(self.param_env, output_ty, callee_expr.span)
|
||||
&& !self.type_is_sized_modulo_regions(self.param_env, output_ty)
|
||||
{
|
||||
let descr = match maybe_def {
|
||||
DefIdOrName::DefId(def_id) => self.tcx.def_descr(def_id),
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let t = self.resolve_vars_if_possible(t);
|
||||
t.error_reported()?;
|
||||
|
||||
if self.type_is_sized_modulo_regions(self.param_env, t, span) {
|
||||
if self.type_is_sized_modulo_regions(self.param_env, t) {
|
||||
return Ok(Some(PointerKind::Thin));
|
||||
}
|
||||
|
||||
|
|
@ -722,7 +722,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||
|
||||
debug!("check_cast({}, {:?} as {:?})", self.expr.hir_id, self.expr_ty, self.cast_ty);
|
||||
|
||||
if !fcx.type_is_sized_modulo_regions(fcx.param_env, self.cast_ty, self.span)
|
||||
if !fcx.type_is_sized_modulo_regions(fcx.param_env, self.cast_ty)
|
||||
&& !self.cast_ty.has_infer_types()
|
||||
{
|
||||
self.report_cast_to_unsized_type(fcx);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ use rustc_hir::Expr;
|
|||
use rustc_hir_analysis::astconv::AstConv;
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
|
||||
use rustc_infer::traits::Obligation;
|
||||
use rustc_infer::traits::{Obligation, PredicateObligation};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::adjustment::{
|
||||
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCast,
|
||||
|
|
@ -597,13 +597,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
// and almost never more than 3. By using a SmallVec we avoid an
|
||||
// allocation, at the (very small) cost of (occasionally) having to
|
||||
// shift subsequent elements down when removing the front element.
|
||||
let mut queue: SmallVec<[_; 4]> = smallvec![traits::predicate_for_trait_def(
|
||||
let mut queue: SmallVec<[PredicateObligation<'tcx>; 4]> = smallvec![Obligation::new(
|
||||
self.tcx,
|
||||
self.fcx.param_env,
|
||||
cause,
|
||||
coerce_unsized_did,
|
||||
0,
|
||||
[coerce_source, coerce_target]
|
||||
self.fcx.param_env,
|
||||
self.tcx.mk_trait_ref(coerce_unsized_did, [coerce_source, coerce_target])
|
||||
)];
|
||||
|
||||
let mut has_unsized_tuple_coercion = false;
|
||||
|
|
@ -651,9 +649,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||
let self_ty = trait_pred.skip_binder().self_ty();
|
||||
let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty();
|
||||
debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_pred);
|
||||
match (&self_ty.kind(), &unsize_ty.kind()) {
|
||||
(ty::Infer(ty::TyVar(v)), ty::Dynamic(..))
|
||||
if self.type_var_is_sized(*v) =>
|
||||
match (self_ty.kind(), unsize_ty.kind()) {
|
||||
(&ty::Infer(ty::TyVar(v)), ty::Dynamic(..))
|
||||
if self.type_var_is_sized(v) =>
|
||||
{
|
||||
debug!("coerce_unsized: have sized infer {:?}", v);
|
||||
coercion.obligations.push(obligation);
|
||||
|
|
|
|||
|
|
@ -1480,7 +1480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
// For this suggestion to make sense, the type would need to be `Copy`,
|
||||
// or we have to be moving out of a `Box<T>`
|
||||
if self.type_is_copy_modulo_regions(self.param_env, expected, sp)
|
||||
if self.type_is_copy_modulo_regions(self.param_env, expected)
|
||||
// FIXME(compiler-errors): We can actually do this if the checked_ty is
|
||||
// `steps` layers of boxes, not just one, but this is easier and most likely.
|
||||
|| (checked_ty.is_box() && steps == 1)
|
||||
|
|
|
|||
|
|
@ -867,10 +867,7 @@ fn copy_or_move<'a, 'tcx>(
|
|||
mc: &mc::MemCategorizationContext<'a, 'tcx>,
|
||||
place_with_id: &PlaceWithHirId<'tcx>,
|
||||
) -> ConsumeMode {
|
||||
if !mc.type_is_copy_modulo_regions(
|
||||
place_with_id.place.ty(),
|
||||
mc.tcx().hir().span(place_with_id.hir_id),
|
||||
) {
|
||||
if !mc.type_is_copy_modulo_regions(place_with_id.place.ty()) {
|
||||
ConsumeMode::Move
|
||||
} else {
|
||||
ConsumeMode::Copy
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -1011,11 +1011,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let mut suggest_copied_or_cloned = || {
|
||||
let expr_inner_ty = substs.type_at(0);
|
||||
let expected_inner_ty = expected_substs.type_at(0);
|
||||
if let ty::Ref(_, ty, hir::Mutability::Not) = expr_inner_ty.kind()
|
||||
&& self.can_eq(self.param_env, *ty, expected_inner_ty)
|
||||
if let &ty::Ref(_, ty, hir::Mutability::Not) = expr_inner_ty.kind()
|
||||
&& self.can_eq(self.param_env, ty, expected_inner_ty)
|
||||
{
|
||||
let def_path = self.tcx.def_path_str(adt_def.did());
|
||||
if self.type_is_copy_modulo_regions(self.param_env, *ty, expr.span) {
|
||||
if self.type_is_copy_modulo_regions(self.param_env, ty) {
|
||||
diag.span_suggestion_verbose(
|
||||
expr.span.shrink_to_hi(),
|
||||
format!(
|
||||
|
|
@ -1029,9 +1029,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
&& rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions(
|
||||
self,
|
||||
self.param_env,
|
||||
*ty,
|
||||
ty,
|
||||
clone_did,
|
||||
expr.span
|
||||
)
|
||||
{
|
||||
diag.span_suggestion_verbose(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||
self.infcx.tcx
|
||||
}
|
||||
|
||||
pub(crate) fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
||||
self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span)
|
||||
pub(crate) fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>) -> bool {
|
||||
self.infcx.type_is_copy_modulo_regions(self.param_env, ty)
|
||||
}
|
||||
|
||||
fn resolve_vars_if_possible<T>(&self, value: T) -> T
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use rustc_span::symbol::{sym, Ident};
|
|||
use rustc_span::Span;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _;
|
||||
use rustc_trait_selection::traits::{self, FulfillmentError};
|
||||
use rustc_trait_selection::traits::{self, FulfillmentError, ObligationCtxt};
|
||||
use rustc_type_ir::sty::TyKind::*;
|
||||
|
||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
|
@ -434,7 +434,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
if self.type_is_copy_modulo_regions(
|
||||
self.param_env,
|
||||
*lhs_deref_ty,
|
||||
lhs_expr.span,
|
||||
) {
|
||||
suggest_deref_binop(*lhs_deref_ty);
|
||||
}
|
||||
|
|
@ -776,7 +775,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
(None, Some(trait_did)) => {
|
||||
let (obligation, _) =
|
||||
self.obligation_for_method(cause, trait_did, lhs_ty, Some(input_types));
|
||||
Err(rustc_trait_selection::traits::fully_solve_obligation(self, obligation))
|
||||
// FIXME: This should potentially just add the obligation to the `FnCtxt`
|
||||
let ocx = ObligationCtxt::new(&self.infcx);
|
||||
ocx.register_obligation(obligation);
|
||||
Err(ocx.select_all_or_error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -424,7 +424,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// closures. We want to make sure any adjustment that might make us move the place into
|
||||
// the closure gets handled.
|
||||
let (place, capture_kind) =
|
||||
restrict_precision_for_drop_types(self, place, capture_kind, usage_span);
|
||||
restrict_precision_for_drop_types(self, place, capture_kind);
|
||||
|
||||
capture_info.capture_kind = capture_kind;
|
||||
(place, capture_info)
|
||||
|
|
@ -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(
|
||||
|
|
@ -1822,9 +1822,8 @@ fn restrict_precision_for_drop_types<'a, 'tcx>(
|
|||
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||
mut place: Place<'tcx>,
|
||||
mut curr_mode: ty::UpvarCapture,
|
||||
span: Span,
|
||||
) -> (Place<'tcx>, ty::UpvarCapture) {
|
||||
let is_copy_type = fcx.infcx.type_is_copy_modulo_regions(fcx.param_env, place.ty(), span);
|
||||
let is_copy_type = fcx.infcx.type_is_copy_modulo_regions(fcx.param_env, place.ty());
|
||||
|
||||
if let (false, UpvarCapture::ByValue) = (is_copy_type, curr_mode) {
|
||||
for i in 0..place.projections.len() {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -189,10 +189,19 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
// the expected const's type. Specifically, we don't want const infer vars
|
||||
// to do any type shapeshifting before and after resolution.
|
||||
if let Err(guar) = compatible_types {
|
||||
return Ok(self.tcx.const_error_with_guaranteed(
|
||||
if relation.a_is_expected() { a.ty() } else { b.ty() },
|
||||
guar,
|
||||
));
|
||||
// HACK: equating both sides with `[const error]` eagerly prevents us
|
||||
// from leaving unconstrained inference vars during things like impl
|
||||
// matching in the solver.
|
||||
let a_error = self.tcx.const_error_with_guaranteed(a.ty(), guar);
|
||||
if let ty::ConstKind::Infer(InferConst::Var(vid)) = a.kind() {
|
||||
return self.unify_const_variable(vid, a_error);
|
||||
}
|
||||
let b_error = self.tcx.const_error_with_guaranteed(b.ty(), guar);
|
||||
if let ty::ConstKind::Infer(InferConst::Var(vid)) = b.kind() {
|
||||
return self.unify_const_variable(vid, b_error);
|
||||
}
|
||||
|
||||
return Ok(if relation.a_is_expected() { a_error } else { b_error });
|
||||
}
|
||||
|
||||
match (a.kind(), b.kind()) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ mod project;
|
|||
mod structural_impls;
|
||||
pub mod util;
|
||||
|
||||
use std::cmp;
|
||||
|
||||
use hir::def_id::LocalDefId;
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
|
|
@ -139,6 +141,14 @@ impl<'tcx, O> Obligation<'tcx, O> {
|
|||
Self::with_depth(tcx, cause, 0, param_env, predicate)
|
||||
}
|
||||
|
||||
/// We often create nested obligations without setting the correct depth.
|
||||
///
|
||||
/// To deal with this evaluate and fulfill explicitly update the depth
|
||||
/// of nested obligations using this function.
|
||||
pub fn set_depth_from_parent(&mut self, parent_depth: usize) {
|
||||
self.recursion_depth = cmp::max(parent_depth + 1, self.recursion_depth);
|
||||
}
|
||||
|
||||
pub fn with_depth(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use rustc_hir as hir;
|
|||
use rustc_infer::{infer::TyCtxtInferExt, traits::ObligationCause};
|
||||
use rustc_middle::ty::{self, List};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
|
||||
declare_lint! {
|
||||
/// The `for_loops_over_fallibles` lint checks for `for` loops over `Option` or `Result` values.
|
||||
|
|
@ -136,20 +137,22 @@ fn suggest_question_mark<'tcx>(
|
|||
|
||||
let ty = substs.type_at(0);
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
|
||||
let body_def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
||||
let cause = ObligationCause::new(
|
||||
span,
|
||||
body_def_id,
|
||||
rustc_infer::traits::ObligationCauseCode::MiscObligation,
|
||||
);
|
||||
let errors = rustc_trait_selection::traits::fully_solve_bound(
|
||||
&infcx,
|
||||
|
||||
ocx.register_bound(
|
||||
cause,
|
||||
ty::ParamEnv::empty(),
|
||||
cx.param_env,
|
||||
// Erase any region vids from the type, which may not be resolved
|
||||
infcx.tcx.erase_regions(ty),
|
||||
into_iterator_did,
|
||||
);
|
||||
|
||||
errors.is_empty()
|
||||
ocx.select_all_or_error().is_empty()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ pub enum MirPhase {
|
|||
/// MIR, this is UB.
|
||||
/// - Retags: If `-Zmir-emit-retag` is enabled, analysis MIR has "implicit" retags in the same way
|
||||
/// that Rust itself has them. Where exactly these are is generally subject to change, and so we
|
||||
/// don't document this here. Runtime MIR has all retags explicit.
|
||||
/// don't document this here. Runtime MIR has most retags explicit (though implicit retags
|
||||
/// can still occur at `Rvalue::{Ref,AddrOf}`).
|
||||
/// - Generator bodies: In analysis MIR, locals may actually be behind a pointer that user code has
|
||||
/// access to. This occurs in generator bodies. Such locals do not behave like other locals,
|
||||
/// because they eg may be aliased in surprising ways. Runtime MIR has no such special locals -
|
||||
|
|
@ -1165,7 +1166,7 @@ pub enum AggregateKind<'tcx> {
|
|||
Tuple,
|
||||
|
||||
/// The second field is the variant index. It's equal to 0 for struct
|
||||
/// and union expressions. The fourth field is
|
||||
/// and union expressions. The last field is the
|
||||
/// active field number and is present only for union expressions
|
||||
/// -- e.g., for a union expression `SomeUnion { c: .. }`, the
|
||||
/// active field index would identity the field `c`
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -897,6 +897,9 @@ pub enum ObjectSafetyViolation {
|
|||
/// (e.g., `trait Foo : Bar<Self>`).
|
||||
SupertraitSelf(SmallVec<[Span; 1]>),
|
||||
|
||||
// Supertrait has a non-lifetime `for<T>` binder.
|
||||
SupertraitNonLifetimeBinder(SmallVec<[Span; 1]>),
|
||||
|
||||
/// Method has something illegal.
|
||||
Method(Symbol, MethodViolationCode, Span),
|
||||
|
||||
|
|
@ -919,6 +922,9 @@ impl ObjectSafetyViolation {
|
|||
.into()
|
||||
}
|
||||
}
|
||||
ObjectSafetyViolation::SupertraitNonLifetimeBinder(_) => {
|
||||
format!("where clause cannot reference non-lifetime `for<...>` variables").into()
|
||||
}
|
||||
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => {
|
||||
format!("associated function `{}` has no `self` parameter", name).into()
|
||||
}
|
||||
|
|
@ -969,7 +975,9 @@ impl ObjectSafetyViolation {
|
|||
|
||||
pub fn solution(&self, err: &mut Diagnostic) {
|
||||
match self {
|
||||
ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {}
|
||||
ObjectSafetyViolation::SizedSelf(_)
|
||||
| ObjectSafetyViolation::SupertraitSelf(_)
|
||||
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(..) => {}
|
||||
ObjectSafetyViolation::Method(
|
||||
name,
|
||||
MethodViolationCode::StaticMethod(Some((add_self_sugg, make_sized_sugg))),
|
||||
|
|
@ -1023,7 +1031,8 @@ impl ObjectSafetyViolation {
|
|||
// diagnostics use a `note` instead of a `span_label`.
|
||||
match self {
|
||||
ObjectSafetyViolation::SupertraitSelf(spans)
|
||||
| ObjectSafetyViolation::SizedSelf(spans) => spans.clone(),
|
||||
| ObjectSafetyViolation::SizedSelf(spans)
|
||||
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(spans) => spans.clone(),
|
||||
ObjectSafetyViolation::AssocConst(_, span)
|
||||
| ObjectSafetyViolation::GAT(_, span)
|
||||
| ObjectSafetyViolation::Method(_, _, span)
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
};
|
||||
|
|
|
|||
|
|
@ -51,9 +51,7 @@ where
|
|||
// Region folder
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Folds the escaping and free regions in `value` using `f`, and
|
||||
/// sets `skipped_regions` to true if any late-bound region was found
|
||||
/// and skipped.
|
||||
/// Folds the escaping and free regions in `value` using `f`.
|
||||
pub fn fold_regions<T>(
|
||||
self,
|
||||
value: T,
|
||||
|
|
@ -64,17 +62,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
{
|
||||
value.fold_with(&mut RegionFolder::new(self, &mut f))
|
||||
}
|
||||
|
||||
pub fn super_fold_regions<T>(
|
||||
self,
|
||||
value: T,
|
||||
mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
|
||||
) -> T
|
||||
where
|
||||
T: TypeSuperFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
value.super_fold_with(&mut RegionFolder::new(self, &mut f))
|
||||
}
|
||||
}
|
||||
|
||||
/// Folds over the substructure of a type, visiting its component
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1128,6 +1128,13 @@ impl<'tcx, T> ToPredicate<'tcx, T> for T {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PredicateKind<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(self).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
|
|
@ -1142,6 +1149,13 @@ impl<'tcx> ToPredicate<'tcx> for Clause<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for TraitRef<'tcx> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(self).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
|
|
@ -1385,7 +1399,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 +2041,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 +2388,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 +2404,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 +2414,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),
|
||||
),)*
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use rustc_macros::HashStable;
|
|||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::spec::abi;
|
||||
use rustc_target::spec::abi::{self, Abi};
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
|
|
@ -1403,6 +1403,18 @@ impl<'tcx> PolyFnSig<'tcx> {
|
|||
pub fn abi(&self) -> abi::Abi {
|
||||
self.skip_binder().abi
|
||||
}
|
||||
|
||||
pub fn is_fn_trait_compatible(&self) -> bool {
|
||||
matches!(
|
||||
self.skip_binder(),
|
||||
ty::FnSig {
|
||||
unsafety: rustc_hir::Unsafety::Normal,
|
||||
abi: Abi::Rust,
|
||||
c_variadic: false,
|
||||
..
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<'tcx, FnSig<'tcx>>>;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,6 +166,28 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
|||
let cast_kind = mir_cast_kind(source_ty, expr.ty);
|
||||
Ok(Rvalue::Cast(cast_kind, source, expr.ty))
|
||||
},
|
||||
ExprKind::Tuple { fields } => Ok(
|
||||
Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Tuple),
|
||||
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
|
||||
)
|
||||
),
|
||||
ExprKind::Array { fields } => {
|
||||
let elem_ty = expr.ty.builtin_index().expect("ty must be an array");
|
||||
Ok(Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Array(elem_ty)),
|
||||
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
|
||||
))
|
||||
},
|
||||
ExprKind::Adt(box AdtExpr{ adt_def, variant_index, substs, fields, .. }) => {
|
||||
let is_union = adt_def.is_union();
|
||||
let active_field_index = is_union.then(|| fields[0].name.index());
|
||||
|
||||
Ok(Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Adt(adt_def.did(), *variant_index, substs, None, active_field_index)),
|
||||
fields.iter().map(|f| self.parse_operand(f.expr)).collect::<Result<_, _>>()?
|
||||
))
|
||||
},
|
||||
_ => self.parse_operand(expr_id).map(Rvalue::Use),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::build::Builder;
|
|||
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
|
@ -66,7 +66,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
pub(crate) fn consume_by_copy_or_move(&self, place: Place<'tcx>) -> Operand<'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let ty = place.ty(&self.local_decls, tcx).ty;
|
||||
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, DUMMY_SP) {
|
||||
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty) {
|
||||
Operand::Move(place)
|
||||
} else {
|
||||
Operand::Copy(place)
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
}
|
||||
_ => &[],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use rustc_hir as hir;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||
use rustc_infer::traits::Obligation;
|
||||
use rustc_middle::mir::{self, Field};
|
||||
use rustc_middle::thir::{FieldPat, Pat, PatKind};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits::predicate_for_trait_def;
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligation};
|
||||
use rustc_trait_selection::traits::{self, ObligationCause};
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
|
|
@ -189,17 +189,15 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
// using `PartialEq::eq` in this scenario in the past.)
|
||||
let partial_eq_trait_id =
|
||||
self.tcx().require_lang_item(hir::LangItem::PartialEq, Some(self.span));
|
||||
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
|
||||
let partial_eq_obligation = Obligation::new(
|
||||
self.tcx(),
|
||||
ObligationCause::dummy(),
|
||||
self.param_env,
|
||||
ObligationCause::misc(self.span, self.id.owner.def_id),
|
||||
partial_eq_trait_id,
|
||||
0,
|
||||
[ty, ty],
|
||||
self.tcx().mk_trait_ref(partial_eq_trait_id, [ty, ty]),
|
||||
);
|
||||
// FIXME: should this call a `predicate_must_hold` variant instead?
|
||||
|
||||
let has_impl = self.infcx.predicate_may_hold(&obligation);
|
||||
// FIXME: should this call a `predicate_must_hold` variant instead?
|
||||
let has_impl = self.infcx.predicate_may_hold(&partial_eq_obligation);
|
||||
|
||||
// Note: To fix rust-lang/rust#65466, we could just remove this type
|
||||
// walk hack for function pointers, and unconditionally error
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
use either::Right;
|
||||
|
||||
use rustc_const_eval::const_eval::CheckAlignment;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
|
|
@ -151,12 +152,17 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
|||
pub struct ConstPropMachine<'mir, 'tcx> {
|
||||
/// The virtual call stack.
|
||||
stack: Vec<Frame<'mir, 'tcx>>,
|
||||
pub written_only_inside_own_block_locals: FxHashSet<Local>,
|
||||
pub can_const_prop: IndexVec<Local, ConstPropMode>,
|
||||
}
|
||||
|
||||
impl ConstPropMachine<'_, '_> {
|
||||
pub fn new(can_const_prop: IndexVec<Local, ConstPropMode>) -> Self {
|
||||
Self { stack: Vec::new(), can_const_prop }
|
||||
Self {
|
||||
stack: Vec::new(),
|
||||
written_only_inside_own_block_locals: Default::default(),
|
||||
can_const_prop,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +255,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
|
|||
"tried to write to a local that is marked as not propagatable"
|
||||
)
|
||||
}
|
||||
ConstPropMode::OnlyInsideOwnBlock | ConstPropMode::FullConstProp => {}
|
||||
ConstPropMode::OnlyInsideOwnBlock => {
|
||||
ecx.machine.written_only_inside_own_block_locals.insert(local);
|
||||
}
|
||||
ConstPropMode::FullConstProp => {}
|
||||
}
|
||||
ecx.machine.stack[frame].locals[local].access_mut()
|
||||
}
|
||||
|
|
@ -416,6 +425,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, local: Local) {
|
||||
ecx.frame_mut().locals[local].value =
|
||||
LocalValue::Live(interpret::Operand::Immediate(interpret::Immediate::Uninit));
|
||||
ecx.machine.written_only_inside_own_block_locals.remove(&local);
|
||||
}
|
||||
|
||||
/// Returns the value, if any, of evaluating `c`.
|
||||
|
|
@ -693,7 +703,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn ensure_not_propagated(&mut self, local: Local) {
|
||||
fn ensure_not_propagated(&self, local: Local) {
|
||||
if cfg!(debug_assertions) {
|
||||
assert!(
|
||||
self.get_const(local.into()).is_none()
|
||||
|
|
@ -963,17 +973,31 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||
// We remove all Locals which are restricted in propagation to their containing blocks and
|
||||
// which were modified in the current block.
|
||||
// Take it out of the ecx so we can get a mutable reference to the ecx for `remove_const`.
|
||||
let can_const_prop = std::mem::take(&mut self.ecx.machine.can_const_prop);
|
||||
for (local, &mode) in can_const_prop.iter_enumerated() {
|
||||
match mode {
|
||||
ConstPropMode::FullConstProp => {}
|
||||
ConstPropMode::NoPropagation => self.ensure_not_propagated(local),
|
||||
ConstPropMode::OnlyInsideOwnBlock => {
|
||||
Self::remove_const(&mut self.ecx, local);
|
||||
self.ensure_not_propagated(local);
|
||||
let mut written_only_inside_own_block_locals =
|
||||
std::mem::take(&mut self.ecx.machine.written_only_inside_own_block_locals);
|
||||
|
||||
// This loop can get very hot for some bodies: it check each local in each bb.
|
||||
// To avoid this quadratic behaviour, we only clear the locals that were modified inside
|
||||
// the current block.
|
||||
for local in written_only_inside_own_block_locals.drain() {
|
||||
debug_assert_eq!(
|
||||
self.ecx.machine.can_const_prop[local],
|
||||
ConstPropMode::OnlyInsideOwnBlock
|
||||
);
|
||||
Self::remove_const(&mut self.ecx, local);
|
||||
}
|
||||
self.ecx.machine.written_only_inside_own_block_locals =
|
||||
written_only_inside_own_block_locals;
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
for (local, &mode) in self.ecx.machine.can_const_prop.iter_enumerated() {
|
||||
match mode {
|
||||
ConstPropMode::FullConstProp => {}
|
||||
ConstPropMode::NoPropagation | ConstPropMode::OnlyInsideOwnBlock => {
|
||||
self.ensure_not_propagated(local);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.ecx.machine.can_const_prop = can_const_prop;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, local: Local) {
|
||||
ecx.frame_mut().locals[local].value =
|
||||
LocalValue::Live(interpret::Operand::Immediate(interpret::Immediate::Uninit));
|
||||
ecx.machine.written_only_inside_own_block_locals.remove(&local);
|
||||
}
|
||||
|
||||
fn lint_root(&self, source_info: SourceInfo) -> Option<HirId> {
|
||||
|
|
@ -484,7 +485,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
Some(())
|
||||
}
|
||||
|
||||
fn ensure_not_propagated(&mut self, local: Local) {
|
||||
fn ensure_not_propagated(&self, local: Local) {
|
||||
if cfg!(debug_assertions) {
|
||||
assert!(
|
||||
self.get_const(local.into()).is_none()
|
||||
|
|
@ -691,17 +692,31 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||
// We remove all Locals which are restricted in propagation to their containing blocks and
|
||||
// which were modified in the current block.
|
||||
// Take it out of the ecx so we can get a mutable reference to the ecx for `remove_const`.
|
||||
let can_const_prop = std::mem::take(&mut self.ecx.machine.can_const_prop);
|
||||
for (local, &mode) in can_const_prop.iter_enumerated() {
|
||||
match mode {
|
||||
ConstPropMode::FullConstProp => {}
|
||||
ConstPropMode::NoPropagation => self.ensure_not_propagated(local),
|
||||
ConstPropMode::OnlyInsideOwnBlock => {
|
||||
Self::remove_const(&mut self.ecx, local);
|
||||
self.ensure_not_propagated(local);
|
||||
let mut written_only_inside_own_block_locals =
|
||||
std::mem::take(&mut self.ecx.machine.written_only_inside_own_block_locals);
|
||||
|
||||
// This loop can get very hot for some bodies: it check each local in each bb.
|
||||
// To avoid this quadratic behaviour, we only clear the locals that were modified inside
|
||||
// the current block.
|
||||
for local in written_only_inside_own_block_locals.drain() {
|
||||
debug_assert_eq!(
|
||||
self.ecx.machine.can_const_prop[local],
|
||||
ConstPropMode::OnlyInsideOwnBlock
|
||||
);
|
||||
Self::remove_const(&mut self.ecx, local);
|
||||
}
|
||||
self.ecx.machine.written_only_inside_own_block_locals =
|
||||
written_only_inside_own_block_locals;
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
for (local, &mode) in self.ecx.machine.can_const_prop.iter_enumerated() {
|
||||
match mode {
|
||||
ConstPropMode::FullConstProp => {}
|
||||
ConstPropMode::NoPropagation | ConstPropMode::OnlyInsideOwnBlock => {
|
||||
self.ensure_not_propagated(local);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.ecx.machine.can_const_prop = can_const_prop;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1843,20 +1843,14 @@ impl<'a> Parser<'a> {
|
|||
&mut self,
|
||||
mk_lit_char: impl FnOnce(Symbol, Span) -> L,
|
||||
) -> PResult<'a, L> {
|
||||
if let token::Interpolated(inner) = &self.token.kind {
|
||||
let expr = match inner.as_ref() {
|
||||
token::NtExpr(expr) => Some(expr),
|
||||
token::NtLiteral(expr) => Some(expr),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(expr) = expr {
|
||||
if matches!(expr.kind, ExprKind::Err) {
|
||||
let mut err = errors::InvalidInterpolatedExpression { span: self.token.span }
|
||||
.into_diagnostic(&self.sess.span_diagnostic);
|
||||
err.downgrade_to_delayed_bug();
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
if let token::Interpolated(nt) = &self.token.kind
|
||||
&& let token::NtExpr(e) | token::NtLiteral(e) = &**nt
|
||||
&& matches!(e.kind, ExprKind::Err)
|
||||
{
|
||||
let mut err = errors::InvalidInterpolatedExpression { span: self.token.span }
|
||||
.into_diagnostic(&self.sess.span_diagnostic);
|
||||
err.downgrade_to_delayed_bug();
|
||||
return Err(err);
|
||||
}
|
||||
let token = self.token.clone();
|
||||
let err = |self_: &Self| {
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -423,13 +423,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
/// Resolves all imports for the crate. This method performs the fixed-
|
||||
/// point iteration.
|
||||
pub(crate) fn resolve_imports(&mut self) {
|
||||
let mut prev_num_indeterminates = self.indeterminate_imports.len() + 1;
|
||||
while self.indeterminate_imports.len() < prev_num_indeterminates {
|
||||
prev_num_indeterminates = self.indeterminate_imports.len();
|
||||
let mut prev_indeterminate_count = usize::MAX;
|
||||
let mut indeterminate_count = self.indeterminate_imports.len() * 3;
|
||||
while indeterminate_count < prev_indeterminate_count {
|
||||
prev_indeterminate_count = indeterminate_count;
|
||||
indeterminate_count = 0;
|
||||
for import in mem::take(&mut self.indeterminate_imports) {
|
||||
match self.resolve_import(&import) {
|
||||
true => self.determined_imports.push(import),
|
||||
false => self.indeterminate_imports.push(import),
|
||||
let import_indeterminate_count = self.resolve_import(&import);
|
||||
indeterminate_count += import_indeterminate_count;
|
||||
match import_indeterminate_count {
|
||||
0 => self.determined_imports.push(import),
|
||||
_ => self.indeterminate_imports.push(import),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -581,9 +585,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
diag.emit();
|
||||
}
|
||||
|
||||
/// Attempts to resolve the given import, returning true if its resolution is determined.
|
||||
/// If successful, the resolved bindings are written into the module.
|
||||
fn resolve_import(&mut self, import: &'a Import<'a>) -> bool {
|
||||
/// Attempts to resolve the given import, returning:
|
||||
/// - `0` means its resolution is determined.
|
||||
/// - Other values mean that indeterminate exists under certain namespaces.
|
||||
///
|
||||
/// Meanwhile, if resolve successful, the resolved bindings are written
|
||||
/// into the module.
|
||||
fn resolve_import(&mut self, import: &'a Import<'a>) -> usize {
|
||||
debug!(
|
||||
"(resolving import for module) resolving import `{}::...` in `{}`",
|
||||
Segment::names_to_string(&import.module_path),
|
||||
|
|
@ -601,8 +609,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
match path_res {
|
||||
PathResult::Module(module) => module,
|
||||
PathResult::Indeterminate => return false,
|
||||
PathResult::NonModule(..) | PathResult::Failed { .. } => return true,
|
||||
PathResult::Indeterminate => return 3,
|
||||
PathResult::NonModule(..) | PathResult::Failed { .. } => return 0,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -618,12 +626,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
} => (source, target, source_bindings, target_bindings, type_ns_only),
|
||||
ImportKind::Glob { .. } => {
|
||||
self.resolve_glob_import(import);
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let mut indeterminate = false;
|
||||
let mut indeterminate_count = 0;
|
||||
self.per_ns(|this, ns| {
|
||||
if !type_ns_only || ns == TypeNS {
|
||||
if let Err(Undetermined) = source_bindings[ns].get() {
|
||||
|
|
@ -646,7 +654,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
let parent = import.parent_scope.module;
|
||||
match source_bindings[ns].get() {
|
||||
Err(Undetermined) => indeterminate = true,
|
||||
Err(Undetermined) => indeterminate_count += 1,
|
||||
// Don't update the resolution, because it was never added.
|
||||
Err(Determined) if target.name == kw::Underscore => {}
|
||||
Ok(binding) if binding.is_importable() => {
|
||||
|
|
@ -670,7 +678,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
});
|
||||
|
||||
!indeterminate
|
||||
indeterminate_count
|
||||
}
|
||||
|
||||
/// Performs final import resolution, consistency checks and error reporting.
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -8,26 +8,16 @@ use rustc_middle::infer::canonical::{Canonical, CanonicalQueryResponse, QueryRes
|
|||
use rustc_middle::traits::query::Fallible;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
|
||||
use rustc_middle::ty::{GenericArg, ToPredicate};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub use rustc_infer::infer::*;
|
||||
|
||||
pub trait InferCtxtExt<'tcx> {
|
||||
fn type_is_copy_modulo_regions(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) -> bool;
|
||||
fn type_is_copy_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool;
|
||||
|
||||
fn type_is_sized_modulo_regions(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) -> bool;
|
||||
fn type_is_sized_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool;
|
||||
|
||||
/// Check whether a `ty` implements given trait(trait_def_id).
|
||||
/// The inputs are:
|
||||
|
|
@ -46,13 +36,9 @@ pub trait InferCtxtExt<'tcx> {
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> traits::EvaluationResult;
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||
fn type_is_copy_modulo_regions(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) -> bool {
|
||||
fn type_is_copy_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
|
||||
if !(param_env, ty).needs_infer() {
|
||||
|
|
@ -65,17 +51,12 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
// rightly refuses to work with inference variables, but
|
||||
// moves_by_default has a cache, which we want to use in other
|
||||
// cases.
|
||||
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, copy_def_id, span)
|
||||
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, copy_def_id)
|
||||
}
|
||||
|
||||
fn type_is_sized_modulo_regions(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) -> bool {
|
||||
fn type_is_sized_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
let lang_item = self.tcx.require_lang_item(LangItem::Sized, None);
|
||||
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, lang_item, span)
|
||||
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, lang_item)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self, params), ret)]
|
||||
|
|
|
|||
|
|
@ -224,7 +224,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
if goal.predicate.self_ty().is_ty_var() {
|
||||
return vec![Candidate {
|
||||
source: CandidateSource::BuiltinImpl,
|
||||
result: self.make_canonical_response(Certainty::AMBIGUOUS).unwrap(),
|
||||
result: self
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
|
||||
.unwrap(),
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
@ -261,8 +263,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
let &ty::Alias(ty::Projection, projection_ty) = goal.predicate.self_ty().kind() else {
|
||||
return
|
||||
};
|
||||
self.probe(|this| {
|
||||
let normalized_ty = this.next_ty_infer();
|
||||
|
||||
self.probe(|ecx| {
|
||||
let normalized_ty = ecx.next_ty_infer();
|
||||
let normalizes_to_goal = goal.with(
|
||||
tcx,
|
||||
ty::Binder::dummy(ty::ProjectionPredicate {
|
||||
|
|
@ -270,28 +273,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
term: normalized_ty.into(),
|
||||
}),
|
||||
);
|
||||
let normalization_certainty = match this.evaluate_goal(normalizes_to_goal) {
|
||||
Ok((_, certainty)) => certainty,
|
||||
Err(NoSolution) => return,
|
||||
};
|
||||
let normalized_ty = this.resolve_vars_if_possible(normalized_ty);
|
||||
ecx.add_goal(normalizes_to_goal);
|
||||
if let Ok(_) = ecx.try_evaluate_added_goals() {
|
||||
let normalized_ty = ecx.resolve_vars_if_possible(normalized_ty);
|
||||
|
||||
// NOTE: Alternatively we could call `evaluate_goal` here and only have a `Normalized` candidate.
|
||||
// This doesn't work as long as we use `CandidateSource` in winnowing.
|
||||
let goal = goal.with(tcx, goal.predicate.with_self_ty(tcx, normalized_ty));
|
||||
let normalized_candidates = this.assemble_and_evaluate_candidates(goal);
|
||||
for mut normalized_candidate in normalized_candidates {
|
||||
normalized_candidate.result =
|
||||
normalized_candidate.result.unchecked_map(|mut response| {
|
||||
// FIXME: This currently hides overflow in the normalization step of the self type
|
||||
// which is probably wrong. Maybe `unify_and` should actually keep overflow as
|
||||
// we treat it as non-fatal anyways.
|
||||
response.certainty = response.certainty.unify_and(normalization_certainty);
|
||||
response
|
||||
});
|
||||
candidates.push(normalized_candidate);
|
||||
// NOTE: Alternatively we could call `evaluate_goal` here and only have a `Normalized` candidate.
|
||||
// This doesn't work as long as we use `CandidateSource` in winnowing.
|
||||
let goal = goal.with(tcx, goal.predicate.with_self_ty(tcx, normalized_ty));
|
||||
candidates.extend(ecx.assemble_and_evaluate_candidates(goal));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn assemble_impl_candidates<G: GoalKind<'tcx>>(
|
||||
|
|
@ -516,7 +507,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
} else {
|
||||
Certainty::AMBIGUOUS
|
||||
};
|
||||
return self.make_canonical_response(certainty);
|
||||
return self.evaluate_added_goals_and_make_canonical_response(certainty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -538,14 +529,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn discard_reservation_impl(&self, mut candidate: Candidate<'tcx>) -> Candidate<'tcx> {
|
||||
fn discard_reservation_impl(&mut self, mut candidate: Candidate<'tcx>) -> Candidate<'tcx> {
|
||||
if let CandidateSource::Impl(def_id) = candidate.source {
|
||||
if let ty::ImplPolarity::Reservation = self.tcx().impl_polarity(def_id) {
|
||||
debug!("Selected reservation impl");
|
||||
// We assemble all candidates inside of a probe so by
|
||||
// making a new canonical response here our result will
|
||||
// have no constraints.
|
||||
candidate.result = self.make_canonical_response(Certainty::AMBIGUOUS).unwrap();
|
||||
candidate.result = self
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue