Separate collection of crate-local inherent impls from error reporting

This commit is contained in:
Michael Goulet
2024-09-23 18:07:42 -04:00
parent 11e760b7f4
commit cfb8419900
22 changed files with 127 additions and 125 deletions

View File

@@ -22,36 +22,38 @@ use crate::errors;
pub(crate) fn crate_inherent_impls(
tcx: TyCtxt<'_>,
(): (),
) -> Result<&'_ CrateInherentImpls, ErrorGuaranteed> {
) -> (&'_ CrateInherentImpls, Result<(), ErrorGuaranteed>) {
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
let mut res = Ok(());
for id in tcx.hir().items() {
res = res.and(collect.check_item(id));
}
res?;
Ok(tcx.arena.alloc(collect.impls_map))
(tcx.arena.alloc(collect.impls_map), res)
}
pub(crate) fn crate_incoherent_impls(
pub(crate) fn crate_inherent_impls_validity_check(
tcx: TyCtxt<'_>,
simp: SimplifiedType,
) -> Result<&[DefId], ErrorGuaranteed> {
let crate_map = tcx.crate_inherent_impls(())?;
Ok(tcx.arena.alloc_from_iter(
(): (),
) -> Result<(), ErrorGuaranteed> {
tcx.crate_inherent_impls(()).1
}
pub(crate) 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()),
))
)
}
/// On-demand query: yields a vector of the inherent impls for a specific type.
pub(crate) fn inherent_impls(
tcx: TyCtxt<'_>,
ty_def_id: LocalDefId,
) -> Result<&[DefId], ErrorGuaranteed> {
let crate_map = tcx.crate_inherent_impls(())?;
Ok(match crate_map.inherent_impls.get(&ty_def_id) {
pub(crate) 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[..],
None => &[],
})
}
}
struct InherentCollect<'tcx> {

View File

@@ -177,8 +177,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
return Ok(());
}
let impls = self.tcx.inherent_impls(id.owner_id)?;
let impls = self.tcx.inherent_impls(id.owner_id);
let overlap_mode = OverlapMode::get(self.tcx, id.owner_id.to_def_id());
let impls_items = impls

View File

@@ -124,7 +124,10 @@ fn enforce_empty_impls_for_marker_traits(
pub(crate) fn provide(providers: &mut Providers) {
use self::builtin::coerce_unsized_info;
use self::inherent_impls::{crate_incoherent_impls, crate_inherent_impls, inherent_impls};
use self::inherent_impls::{
crate_incoherent_impls, crate_inherent_impls, crate_inherent_impls_validity_check,
inherent_impls,
};
use self::inherent_impls_overlap::crate_inherent_impls_overlap_check;
use self::orphan::orphan_check_impl;
@@ -133,6 +136,7 @@ pub(crate) fn provide(providers: &mut Providers) {
crate_inherent_impls,
crate_incoherent_impls,
inherent_impls,
crate_inherent_impls_validity_check,
crate_inherent_impls_overlap_check,
coerce_unsized_info,
orphan_check_impl,