Invoke trait_def
query only once
This may be a small performance boost as we have to hash less to lookup the value
This commit is contained in:
parent
11a73f6d4d
commit
55bbb054c9
2 changed files with 13 additions and 10 deletions
|
@ -23,6 +23,7 @@ fn check_impl(
|
|||
tcx: TyCtxt<'_>,
|
||||
impl_def_id: LocalDefId,
|
||||
trait_ref: ty::TraitRef<'_>,
|
||||
trait_def: &ty::TraitDef,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
debug!(
|
||||
"(checking implementation) adding impl for trait '{:?}', item '{}'",
|
||||
|
@ -36,19 +37,20 @@ fn check_impl(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
enforce_trait_manually_implementable(tcx, impl_def_id, trait_ref.def_id)
|
||||
.and(enforce_empty_impls_for_marker_traits(tcx, impl_def_id, trait_ref.def_id))
|
||||
enforce_trait_manually_implementable(tcx, impl_def_id, trait_ref.def_id, trait_def)
|
||||
.and(enforce_empty_impls_for_marker_traits(tcx, impl_def_id, trait_ref.def_id, trait_def))
|
||||
}
|
||||
|
||||
fn enforce_trait_manually_implementable(
|
||||
tcx: TyCtxt<'_>,
|
||||
impl_def_id: LocalDefId,
|
||||
trait_def_id: DefId,
|
||||
trait_def: &ty::TraitDef,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let impl_header_span = tcx.def_span(impl_def_id);
|
||||
|
||||
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
|
||||
if tcx.trait_def(trait_def_id).deny_explicit_impl {
|
||||
if trait_def.deny_explicit_impl {
|
||||
let trait_name = tcx.item_name(trait_def_id);
|
||||
let mut err = struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
|
@ -67,8 +69,7 @@ fn enforce_trait_manually_implementable(
|
|||
return Err(err.emit());
|
||||
}
|
||||
|
||||
if let ty::trait_def::TraitSpecializationKind::AlwaysApplicable =
|
||||
tcx.trait_def(trait_def_id).specialization_kind
|
||||
if let ty::trait_def::TraitSpecializationKind::AlwaysApplicable = trait_def.specialization_kind
|
||||
{
|
||||
if !tcx.features().specialization
|
||||
&& !tcx.features().min_specialization
|
||||
|
@ -87,8 +88,9 @@ fn enforce_empty_impls_for_marker_traits(
|
|||
tcx: TyCtxt<'_>,
|
||||
impl_def_id: LocalDefId,
|
||||
trait_def_id: DefId,
|
||||
trait_def: &ty::TraitDef,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
if !tcx.trait_def(trait_def_id).is_marker {
|
||||
if !trait_def.is_marker {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -133,11 +135,12 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
|
|||
|
||||
for &impl_def_id in impls {
|
||||
let trait_header = tcx.impl_trait_header(impl_def_id).unwrap().instantiate_identity();
|
||||
let trait_def = tcx.trait_def(trait_header.trait_ref.def_id);
|
||||
|
||||
res = res.and(check_impl(tcx, impl_def_id, trait_header.trait_ref));
|
||||
res = res.and(check_impl(tcx, impl_def_id, trait_header.trait_ref, trait_def));
|
||||
res = res.and(check_object_overlap(tcx, impl_def_id, trait_header.trait_ref));
|
||||
|
||||
res = res.and(unsafety::check_item(tcx, impl_def_id, trait_header));
|
||||
res = res.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def));
|
||||
res = res.and(tcx.ensure().orphan_check_impl(impl_def_id));
|
||||
res = res.and(builtin::check_trait(tcx, def_id, impl_def_id));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use rustc_errors::{codes::*, struct_span_code_err};
|
||||
use rustc_hir::Unsafety;
|
||||
use rustc_middle::ty::{ImplPolarity::*, ImplTraitHeader, TyCtxt};
|
||||
use rustc_middle::ty::{ImplPolarity::*, ImplTraitHeader, TraitDef, TyCtxt};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::ErrorGuaranteed;
|
||||
|
||||
|
@ -11,9 +11,9 @@ pub(super) fn check_item(
|
|||
tcx: TyCtxt<'_>,
|
||||
def_id: LocalDefId,
|
||||
trait_header: ImplTraitHeader<'_>,
|
||||
trait_def: &TraitDef,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let trait_ref = trait_header.trait_ref;
|
||||
let trait_def = tcx.trait_def(trait_ref.def_id);
|
||||
let unsafe_attr =
|
||||
tcx.generics_of(def_id).params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
|
||||
match (trait_def.unsafety, unsafe_attr, trait_header.unsafety, trait_header.polarity) {
|
||||
|
|
Loading…
Add table
Reference in a new issue