@@ -108,54 +108,52 @@ pub enum MethodViolationCode {
108108 UndispatchableReceiver ,
109109}
110110
111- impl < ' tcx > TyCtxt < ' tcx > {
112- /// Returns the object safety violations that affect
113- /// astconv -- currently, `Self` in supertraits. This is needed
114- /// because `object_safety_violations` can't be used during
115- /// type collection.
116- pub fn astconv_object_safety_violations (
117- self ,
118- trait_def_id : DefId ,
119- ) -> Vec < ObjectSafetyViolation > {
120- debug_assert ! ( self . generics_of( trait_def_id) . has_self) ;
121- let violations = traits:: supertrait_def_ids ( self , trait_def_id)
122- . filter ( |& def_id| predicates_reference_self ( self , def_id, true ) )
123- . map ( |_| ObjectSafetyViolation :: SupertraitSelf )
124- . collect ( ) ;
111+ /// Returns the object safety violations that affect
112+ /// astconv -- currently, `Self` in supertraits. This is needed
113+ /// because `object_safety_violations` can't be used during
114+ /// type collection.
115+ pub fn astconv_object_safety_violations (
116+ tcx : TyCtxt < ' _ > ,
117+ trait_def_id : DefId ,
118+ ) -> Vec < ObjectSafetyViolation > {
119+ debug_assert ! ( tcx. generics_of( trait_def_id) . has_self) ;
120+ let violations = traits:: supertrait_def_ids ( tcx, trait_def_id)
121+ . filter ( |& def_id| predicates_reference_self ( tcx, def_id, true ) )
122+ . map ( |_| ObjectSafetyViolation :: SupertraitSelf )
123+ . collect ( ) ;
125124
126- debug ! (
127- "astconv_object_safety_violations(trait_def_id={:?}) = {:?}" ,
128- trait_def_id, violations
129- ) ;
125+ debug ! ( "astconv_object_safety_violations(trait_def_id={:?}) = {:?}" , trait_def_id, violations) ;
130126
131- violations
132- }
127+ violations
128+ }
129+
130+ pub fn object_safety_violations (
131+ tcx : TyCtxt < ' _ > ,
132+ trait_def_id : DefId ,
133+ ) -> Vec < ObjectSafetyViolation > {
134+ debug_assert ! ( tcx. generics_of( trait_def_id) . has_self) ;
135+ debug ! ( "object_safety_violations: {:?}" , trait_def_id) ;
133136
134- pub fn object_safety_violations ( self , trait_def_id : DefId ) -> Vec < ObjectSafetyViolation > {
135- debug_assert ! ( self . generics_of( trait_def_id) . has_self) ;
136- debug ! ( "object_safety_violations: {:?}" , trait_def_id) ;
137+ traits:: supertrait_def_ids ( tcx, trait_def_id)
138+ . flat_map ( |def_id| object_safety_violations_for_trait ( tcx, def_id) )
139+ . collect ( )
140+ }
137141
138- traits:: supertrait_def_ids ( self , trait_def_id)
139- . flat_map ( |def_id| object_safety_violations_for_trait ( self , def_id) )
140- . collect ( )
142+ /// We say a method is *vtable safe* if it can be invoked on a trait
143+ /// object. Note that object-safe traits can have some
144+ /// non-vtable-safe methods, so long as they require `Self: Sized` or
145+ /// otherwise ensure that they cannot be used when `Self = Trait`.
146+ pub fn is_vtable_safe_method ( tcx : TyCtxt < ' _ > , trait_def_id : DefId , method : & ty:: AssocItem ) -> bool {
147+ debug_assert ! ( tcx. generics_of( trait_def_id) . has_self) ;
148+ debug ! ( "is_vtable_safe_method({:?}, {:?})" , trait_def_id, method) ;
149+ // Any method that has a `Self: Sized` bound cannot be called.
150+ if generics_require_sized_self ( tcx, method. def_id ) {
151+ return false ;
141152 }
142153
143- /// We say a method is *vtable safe* if it can be invoked on a trait
144- /// object. Note that object-safe traits can have some
145- /// non-vtable-safe methods, so long as they require `Self: Sized` or
146- /// otherwise ensure that they cannot be used when `Self = Trait`.
147- pub fn is_vtable_safe_method ( self , trait_def_id : DefId , method : & ty:: AssocItem ) -> bool {
148- debug_assert ! ( self . generics_of( trait_def_id) . has_self) ;
149- debug ! ( "is_vtable_safe_method({:?}, {:?})" , trait_def_id, method) ;
150- // Any method that has a `Self: Sized` bound cannot be called.
151- if generics_require_sized_self ( self , method. def_id ) {
152- return false ;
153- }
154-
155- match virtual_call_violation_for_method ( self , trait_def_id, method) {
156- None | Some ( MethodViolationCode :: WhereClauseReferencesSelf ) => true ,
157- Some ( _) => false ,
158- }
154+ match virtual_call_violation_for_method ( tcx, trait_def_id, method) {
155+ None | Some ( MethodViolationCode :: WhereClauseReferencesSelf ) => true ,
156+ Some ( _) => false ,
159157 }
160158}
161159
@@ -724,5 +722,5 @@ fn contains_illegal_self_type_reference<'tcx>(
724722}
725723
726724pub ( super ) fn is_object_safe_provider ( tcx : TyCtxt < ' _ > , trait_def_id : DefId ) -> bool {
727- tcx . object_safety_violations ( trait_def_id) . is_empty ( )
725+ object_safety_violations ( tcx , trait_def_id) . is_empty ( )
728726}
0 commit comments