1
Fork 0

make query take (LocalDefId, DefId)

This commit is contained in:
Boxy 2022-09-30 18:53:32 +01:00
parent 831f4402aa
commit c1a9cf42b4
5 changed files with 28 additions and 31 deletions

View file

@ -1046,9 +1046,8 @@ fn check_impl_items_against_trait<'tcx>(
hir::ImplItemKind::Const(..) => { hir::ImplItemKind::Const(..) => {
// Find associated const definition. // Find associated const definition.
let _ = tcx.compare_assoc_const_impl_item_with_trait_item(( let _ = tcx.compare_assoc_const_impl_item_with_trait_item((
&ty_impl_item, impl_item.id.def_id.def_id,
&ty_trait_item, ty_impl_item.trait_item_def_id.unwrap(),
impl_trait_ref,
)); ));
} }
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {

View file

@ -1,6 +1,6 @@
use super::potentially_plural_count; use super::potentially_plural_count;
use crate::errors::LifetimesOrBoundsMismatchOnTrait; use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use hir::def_id::DefId; use hir::def_id::{DefId, LocalDefId};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed}; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed};
use rustc_hir as hir; use rustc_hir as hir;
@ -1303,14 +1303,17 @@ fn compare_generic_param_kinds<'tcx>(
/// Use `tcx.compare_assoc_const_impl_item_with_trait_item` instead /// Use `tcx.compare_assoc_const_impl_item_with_trait_item` instead
pub(crate) fn raw_compare_const_impl<'tcx>( pub(crate) fn raw_compare_const_impl<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
(impl_c, trait_c, impl_trait_ref): (&ty::AssocItem, &ty::AssocItem, ty::TraitRef<'tcx>), (impl_const_item_def, trait_const_item_def): (LocalDefId, DefId),
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
let impl_const_item = tcx.associated_item(impl_const_item_def);
let trait_const_item = tcx.associated_item(trait_const_item_def);
let impl_trait_ref = tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap();
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref); debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
let impl_c_span = tcx.def_span(impl_c.def_id); let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id());
tcx.infer_ctxt().enter(|infcx| { tcx.infer_ctxt().enter(|infcx| {
let param_env = tcx.param_env(impl_c.def_id); let param_env = tcx.param_env(impl_const_item_def.to_def_id());
let ocx = ObligationCtxt::new(&infcx); let ocx = ObligationCtxt::new(&infcx);
// The below is for the most part highly similar to the procedure // The below is for the most part highly similar to the procedure
@ -1322,18 +1325,18 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
// Create a parameter environment that represents the implementation's // Create a parameter environment that represents the implementation's
// method. // method.
let impl_c_hir_id = tcx.hir().local_def_id_to_hir_id(impl_c.def_id.expect_local()); let impl_c_hir_id = tcx.hir().local_def_id_to_hir_id(impl_const_item_def);
// Compute placeholder form of impl and trait const tys. // Compute placeholder form of impl and trait const tys.
let impl_ty = tcx.type_of(impl_c.def_id); let impl_ty = tcx.type_of(impl_const_item_def.to_def_id());
let trait_ty = tcx.bound_type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs); let trait_ty = tcx.bound_type_of(trait_const_item_def).subst(tcx, trait_to_impl_substs);
let mut cause = ObligationCause::new( let mut cause = ObligationCause::new(
impl_c_span, impl_c_span,
impl_c_hir_id, impl_c_hir_id,
ObligationCauseCode::CompareImplItemObligation { ObligationCauseCode::CompareImplItemObligation {
impl_item_def_id: impl_c.def_id.expect_local(), impl_item_def_id: impl_const_item_def,
trait_item_def_id: trait_c.def_id, trait_item_def_id: trait_const_item_def,
kind: impl_c.kind, kind: impl_const_item.kind,
}, },
); );
@ -1357,9 +1360,9 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
); );
// Locate the Span containing just the type of the offending impl // Locate the Span containing just the type of the offending impl
match tcx.hir().expect_impl_item(impl_c.def_id.expect_local()).kind { match tcx.hir().expect_impl_item(impl_const_item_def).kind {
ImplItemKind::Const(ref ty, _) => cause.span = ty.span, ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
_ => bug!("{:?} is not a impl const", impl_c), _ => bug!("{:?} is not a impl const", impl_const_item),
} }
let mut diag = struct_span_err!( let mut diag = struct_span_err!(
@ -1367,14 +1370,14 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
cause.span, cause.span,
E0326, E0326,
"implemented const `{}` has an incompatible type for trait", "implemented const `{}` has an incompatible type for trait",
trait_c.name trait_const_item.name
); );
let trait_c_span = trait_c.def_id.as_local().map(|trait_c_def_id| { let trait_c_span = trait_const_item_def.as_local().map(|trait_c_def_id| {
// Add a label to the Span containing just the type of the const // Add a label to the Span containing just the type of the const
match tcx.hir().expect_trait_item(trait_c_def_id).kind { match tcx.hir().expect_trait_item(trait_c_def_id).kind {
TraitItemKind::Const(ref ty, _) => ty.span, TraitItemKind::Const(ref ty, _) => ty.span,
_ => bug!("{:?} is not a trait const", trait_c), _ => bug!("{:?} is not a trait const", trait_const_item),
} }
}); });
@ -1402,10 +1405,8 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
// FIXME return `ErrorReported` if region obligations error? // FIXME return `ErrorReported` if region obligations error?
let outlives_environment = OutlivesEnvironment::new(param_env); let outlives_environment = OutlivesEnvironment::new(param_env);
infcx.check_region_obligations_and_report_errors( infcx
impl_c.def_id.expect_local(), .check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment);
&outlives_environment,
);
maybe_error_reported maybe_error_reported
}) })
} }

View file

@ -2102,8 +2102,8 @@ rustc_queries! {
} }
query compare_assoc_const_impl_item_with_trait_item( query compare_assoc_const_impl_item_with_trait_item(
key: (&'tcx ty::AssocItem, &'tcx ty::AssocItem, ty::TraitRef<'tcx>) key: (LocalDefId, DefId)
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.def_id) } desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
} }
} }

View file

@ -184,15 +184,11 @@ fn resolve_associated_item<'tcx>(
// error has already been/will be emitted elsewhere). // error has already been/will be emitted elsewhere).
if leaf_def.item.kind == ty::AssocKind::Const if leaf_def.item.kind == ty::AssocKind::Const
&& trait_item_id != leaf_def.item.def_id && trait_item_id != leaf_def.item.def_id
&& leaf_def.item.def_id.is_local() && let Some(leaf_def_item) = leaf_def.item.def_id.as_local()
{ {
let impl_item = tcx.associated_item(leaf_def.item.def_id);
let trait_item = tcx.associated_item(trait_item_id);
let impl_trait_ref = tcx.impl_trait_ref(impl_item.container_id(tcx)).unwrap();
tcx.compare_assoc_const_impl_item_with_trait_item(( tcx.compare_assoc_const_impl_item_with_trait_item((
impl_item, leaf_def_item,
trait_item, trait_item_id,
impl_trait_ref,
))?; ))?;
} }

View file

@ -5,6 +5,7 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(let_chains)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(never_type)] #![feature(never_type)]
#![feature(box_patterns)] #![feature(box_patterns)]