@@ -23,6 +23,7 @@ fn check_impl(
23
23
tcx : TyCtxt < ' _ > ,
24
24
impl_def_id : LocalDefId ,
25
25
trait_ref : ty:: TraitRef < ' _ > ,
26
+ trait_def : & ty:: TraitDef ,
26
27
) -> Result < ( ) , ErrorGuaranteed > {
27
28
debug ! (
28
29
"(checking implementation) adding impl for trait '{:?}', item '{}'" ,
@@ -36,19 +37,20 @@ fn check_impl(
36
37
return Ok ( ( ) ) ;
37
38
}
38
39
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 ) )
41
42
}
42
43
43
44
fn enforce_trait_manually_implementable (
44
45
tcx : TyCtxt < ' _ > ,
45
46
impl_def_id : LocalDefId ,
46
47
trait_def_id : DefId ,
48
+ trait_def : & ty:: TraitDef ,
47
49
) -> Result < ( ) , ErrorGuaranteed > {
48
50
let impl_header_span = tcx. def_span ( impl_def_id) ;
49
51
50
52
// 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 {
52
54
let trait_name = tcx. item_name ( trait_def_id) ;
53
55
let mut err = struct_span_code_err ! (
54
56
tcx. dcx( ) ,
@@ -67,8 +69,7 @@ fn enforce_trait_manually_implementable(
67
69
return Err ( err. emit ( ) ) ;
68
70
}
69
71
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
72
73
{
73
74
if !tcx. features ( ) . specialization
74
75
&& !tcx. features ( ) . min_specialization
@@ -87,8 +88,9 @@ fn enforce_empty_impls_for_marker_traits(
87
88
tcx : TyCtxt < ' _ > ,
88
89
impl_def_id : LocalDefId ,
89
90
trait_def_id : DefId ,
91
+ trait_def : & ty:: TraitDef ,
90
92
) -> Result < ( ) , ErrorGuaranteed > {
91
- if !tcx . trait_def ( trait_def_id ) . is_marker {
93
+ if !trait_def. is_marker {
92
94
return Ok ( ( ) ) ;
93
95
}
94
96
@@ -133,11 +135,12 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
133
135
134
136
for & impl_def_id in impls {
135
137
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 ) ;
136
139
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 ) ) ;
138
141
res = res. and ( check_object_overlap ( tcx, impl_def_id, trait_header. trait_ref ) ) ;
139
142
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 ) ) ;
141
144
res = res. and ( tcx. ensure ( ) . orphan_check_impl ( impl_def_id) ) ;
142
145
res = res. and ( builtin:: check_trait ( tcx, def_id, impl_def_id) ) ;
143
146
}
0 commit comments