@@ -23,6 +23,7 @@ fn check_impl(
2323 tcx : TyCtxt < ' _ > ,
2424 impl_def_id : LocalDefId ,
2525 trait_ref : ty:: TraitRef < ' _ > ,
26+ trait_def : & ty:: TraitDef ,
2627) -> Result < ( ) , ErrorGuaranteed > {
2728 debug ! (
2829 "(checking implementation) adding impl for trait '{:?}', item '{}'" ,
@@ -36,19 +37,20 @@ fn check_impl(
3637 return Ok ( ( ) ) ;
3738 }
3839
39- enforce_trait_manually_implementable ( tcx, impl_def_id, trait_ref. def_id )
40- . and ( enforce_empty_impls_for_marker_traits ( tcx, impl_def_id, trait_ref. def_id ) )
40+ enforce_trait_manually_implementable ( tcx, impl_def_id, trait_ref. def_id , trait_def )
41+ . and ( enforce_empty_impls_for_marker_traits ( tcx, impl_def_id, trait_ref. def_id , trait_def ) )
4142}
4243
4344fn enforce_trait_manually_implementable (
4445 tcx : TyCtxt < ' _ > ,
4546 impl_def_id : LocalDefId ,
4647 trait_def_id : DefId ,
48+ trait_def : & ty:: TraitDef ,
4749) -> Result < ( ) , ErrorGuaranteed > {
4850 let impl_header_span = tcx. def_span ( impl_def_id) ;
4951
5052 // Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
51- if tcx . trait_def ( trait_def_id ) . deny_explicit_impl {
53+ if trait_def. deny_explicit_impl {
5254 let trait_name = tcx. item_name ( trait_def_id) ;
5355 let mut err = struct_span_code_err ! (
5456 tcx. dcx( ) ,
@@ -67,8 +69,7 @@ fn enforce_trait_manually_implementable(
6769 return Err ( err. emit ( ) ) ;
6870 }
6971
70- if let ty:: trait_def:: TraitSpecializationKind :: AlwaysApplicable =
71- tcx. trait_def ( trait_def_id) . specialization_kind
72+ if let ty:: trait_def:: TraitSpecializationKind :: AlwaysApplicable = trait_def. specialization_kind
7273 {
7374 if !tcx. features ( ) . specialization
7475 && !tcx. features ( ) . min_specialization
@@ -87,8 +88,9 @@ fn enforce_empty_impls_for_marker_traits(
8788 tcx : TyCtxt < ' _ > ,
8889 impl_def_id : LocalDefId ,
8990 trait_def_id : DefId ,
91+ trait_def : & ty:: TraitDef ,
9092) -> Result < ( ) , ErrorGuaranteed > {
91- if !tcx . trait_def ( trait_def_id ) . is_marker {
93+ if !trait_def. is_marker {
9294 return Ok ( ( ) ) ;
9395 }
9496
@@ -133,11 +135,12 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
133135
134136 for & impl_def_id in impls {
135137 let trait_header = tcx. impl_trait_header ( impl_def_id) . unwrap ( ) . instantiate_identity ( ) ;
138+ let trait_def = tcx. trait_def ( trait_header. trait_ref . def_id ) ;
136139
137- res = res. and ( check_impl ( tcx, impl_def_id, trait_header. trait_ref ) ) ;
140+ res = res. and ( check_impl ( tcx, impl_def_id, trait_header. trait_ref , trait_def ) ) ;
138141 res = res. and ( check_object_overlap ( tcx, impl_def_id, trait_header. trait_ref ) ) ;
139142
140- res = res. and ( unsafety:: check_item ( tcx, impl_def_id, trait_header) ) ;
143+ res = res. and ( unsafety:: check_item ( tcx, impl_def_id, trait_header, trait_def ) ) ;
141144 res = res. and ( tcx. ensure ( ) . orphan_check_impl ( impl_def_id) ) ;
142145 res = res. and ( builtin:: check_trait ( tcx, def_id, impl_def_id) ) ;
143146 }
0 commit comments