Even less HIR.

This commit is contained in:
Camille GILLOT
2023-02-12 21:08:14 +00:00
parent 68fb752035
commit 40cb4d1bc7
4 changed files with 28 additions and 33 deletions

View File

@@ -202,8 +202,7 @@ fn visit_implementation_of_coerce_unsized(tcx: TyCtxt<'_>, impl_did: LocalDefId)
fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did);
let span = tcx.hir().span(impl_hir_id);
let span = tcx.def_span(impl_did);
let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span));

View File

@@ -38,26 +38,28 @@ fn do_orphan_check_impl<'tcx>(
def_id: LocalDefId,
) -> Result<(), ErrorGuaranteed> {
let trait_def_id = trait_ref.def_id;
let item = tcx.hir().expect_item(def_id);
let hir::ItemKind::Impl(impl_) = item.kind else {
bug!("{:?} is not an impl: {:?}", def_id, item);
};
let sp = tcx.def_span(def_id);
let tr = impl_.of_trait.as_ref().unwrap();
match traits::orphan_check(tcx, item.owner_id.to_def_id()) {
match traits::orphan_check(tcx, def_id.to_def_id()) {
Ok(()) => {}
Err(err) => emit_orphan_check_error(
tcx,
sp,
item.span,
tr.path.span,
trait_ref,
impl_.self_ty.span,
&impl_.generics,
err,
)?,
Err(err) => {
let item = tcx.hir().expect_item(def_id);
let hir::ItemKind::Impl(impl_) = item.kind else {
bug!("{:?} is not an impl: {:?}", def_id, item);
};
let tr = impl_.of_trait.as_ref().unwrap();
emit_orphan_check_error(
tcx,
sp,
item.span,
tr.path.span,
trait_ref,
impl_.self_ty.span,
&impl_.generics,
err,
)?
}
}
// In addition to the above rules, we restrict impls of auto traits