1 //! "Object safety" refers to the ability for a trait to be converted
2 //! to an object. In general, traits may only be converted to an
3 //! object if all of their methods meet certain criteria. In particular,
6 //! - have a suitable receiver from which we can extract a vtable and coerce to a "thin" version
7 //! that doesn't contain the vtable;
8 //! - not reference the erased type `Self` except for in this receiver;
9 //! - not have generic type parameters.
11 use super::elaborate_predicates;
13 use crate::traits::{self, Obligation, ObligationCause};
14 use crate::ty::subst::{InternalSubsts, Subst};
15 use crate::ty::{self, Predicate, ToPredicate, Ty, TyCtxt, TypeFoldable};
17 use rustc_hir::def_id::DefId;
18 use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
19 use rustc_span::symbol::Symbol;
20 use rustc_span::{Span, DUMMY_SP};
24 use std::iter::{self};
26 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
27 pub enum ObjectSafetyViolation {
28 /// `Self: Sized` declared on the trait.
31 /// Supertrait reference references `Self` an in illegal location
32 /// (e.g., `trait Foo : Bar<Self>`).
35 /// Method has something illegal.
36 Method(ast::Name, MethodViolationCode, Span),
39 AssocConst(ast::Name, Span),
42 impl ObjectSafetyViolation {
43 pub fn error_msg(&self) -> Cow<'static, str> {
45 ObjectSafetyViolation::SizedSelf => {
46 "the trait cannot require that `Self : Sized`".into()
48 ObjectSafetyViolation::SupertraitSelf => {
49 "the trait cannot use `Self` as a type parameter \
50 in the supertraits or where-clauses"
53 ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) => {
54 format!("associated function `{}` has no `self` parameter", name).into()
56 ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf, _) => format!(
57 "method `{}` references the `Self` type in its parameters or return type",
61 ObjectSafetyViolation::Method(
63 MethodViolationCode::WhereClauseReferencesSelf,
65 ) => format!("method `{}` references the `Self` type in where clauses", name).into(),
66 ObjectSafetyViolation::Method(name, MethodViolationCode::Generic, _) => {
67 format!("method `{}` has generic type parameters", name).into()
69 ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) => {
70 format!("method `{}`'s `self` parameter cannot be dispatched on", name).into()
72 ObjectSafetyViolation::AssocConst(name, _) => {
73 format!("the trait cannot contain associated consts like `{}`", name).into()
78 pub fn span(&self) -> Option<Span> {
79 // When `span` comes from a separate crate, it'll be `DUMMY_SP`. Treat it as `None` so
80 // diagnostics use a `note` instead of a `span_label`.
82 ObjectSafetyViolation::AssocConst(_, span)
83 | ObjectSafetyViolation::Method(_, _, span)
84 if span != DUMMY_SP =>
93 /// Reasons a method might not be object-safe.
94 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
95 pub enum MethodViolationCode {
99 /// e.g., `fn foo(&self, x: Self)` or `fn foo(&self) -> Self`
102 /// e.g., `fn foo(&self) where Self: Clone`
103 WhereClauseReferencesSelf,
105 /// e.g., `fn foo<A>()`
108 /// the method's receiver (`self` argument) can't be dispatched on
109 UndispatchableReceiver,
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
116 pub fn astconv_object_safety_violations(
119 ) -> Vec<ObjectSafetyViolation> {
120 debug_assert!(tcx.generics_of(trait_def_id).has_self);
121 let violations = traits::supertrait_def_ids(tcx, trait_def_id)
122 .filter(|&def_id| predicates_reference_self(tcx, def_id, true))
123 .map(|_| ObjectSafetyViolation::SupertraitSelf)
126 debug!("astconv_object_safety_violations(trait_def_id={:?}) = {:?}", trait_def_id, violations);
131 pub fn object_safety_violations(
134 ) -> Vec<ObjectSafetyViolation> {
135 debug_assert!(tcx.generics_of(trait_def_id).has_self);
136 debug!("object_safety_violations: {:?}", trait_def_id);
138 traits::supertrait_def_ids(tcx, trait_def_id)
139 .flat_map(|def_id| object_safety_violations_for_trait(tcx, def_id))
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(tcx: TyCtxt<'_>, trait_def_id: DefId, method: &ty::AssocItem) -> bool {
148 debug_assert!(tcx.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(tcx, method.def_id) {
155 match virtual_call_violation_for_method(tcx, trait_def_id, method) {
156 None | Some(MethodViolationCode::WhereClauseReferencesSelf) => true,
161 fn object_safety_violations_for_trait(
164 ) -> Vec<ObjectSafetyViolation> {
165 // Check methods for violations.
166 let mut violations: Vec<_> = tcx
167 .associated_items(trait_def_id)
168 .filter(|item| item.kind == ty::AssocKind::Method)
170 object_safety_violation_for_method(tcx, trait_def_id, &item)
171 .map(|code| ObjectSafetyViolation::Method(item.ident.name, code, item.ident.span))
173 .filter(|violation| {
174 if let ObjectSafetyViolation::Method(
176 MethodViolationCode::WhereClauseReferencesSelf,
180 // Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
181 // It's also hard to get a use site span, so we use the method definition span.
183 WHERE_CLAUSES_OBJECT_SAFETY,
187 "the trait `{}` cannot be made into an object",
188 tcx.def_path_str(trait_def_id)
190 &violation.error_msg(),
199 // Check the trait itself.
200 if trait_has_sized_self(tcx, trait_def_id) {
201 violations.push(ObjectSafetyViolation::SizedSelf);
203 if predicates_reference_self(tcx, trait_def_id, false) {
204 violations.push(ObjectSafetyViolation::SupertraitSelf);
208 tcx.associated_items(trait_def_id)
209 .filter(|item| item.kind == ty::AssocKind::Const)
210 .map(|item| ObjectSafetyViolation::AssocConst(item.ident.name, item.ident.span)),
214 "object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
215 trait_def_id, violations
221 fn predicates_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId, supertraits_only: bool) -> bool {
222 let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_def_id));
223 let predicates = if supertraits_only {
224 tcx.super_predicates_of(trait_def_id)
226 tcx.predicates_of(trait_def_id)
228 let self_ty = tcx.types.self_param;
229 let has_self_ty = |t: Ty<'_>| t.walk().any(|t| t == self_ty);
233 .map(|(predicate, _)| predicate.subst_supertrait(tcx, &trait_ref))
236 ty::Predicate::Trait(ref data) => {
237 // In the case of a trait predicate, we can skip the "self" type.
238 data.skip_binder().input_types().skip(1).any(has_self_ty)
240 ty::Predicate::Projection(ref data) => {
241 // And similarly for projections. This should be redundant with
242 // the previous check because any projection should have a
243 // matching `Trait` predicate with the same inputs, but we do
244 // the check to be safe.
246 // Note that we *do* allow projection *outputs* to contain
247 // `self` (i.e., `trait Foo: Bar<Output=Self::Result> { type Result; }`),
248 // we just require the user to specify *both* outputs
249 // in the object type (i.e., `dyn Foo<Output=(), Result=()>`).
251 // This is ALT2 in issue #56288, see that for discussion of the
252 // possible alternatives.
260 ty::Predicate::WellFormed(..)
261 | ty::Predicate::ObjectSafe(..)
262 | ty::Predicate::TypeOutlives(..)
263 | ty::Predicate::RegionOutlives(..)
264 | ty::Predicate::ClosureKind(..)
265 | ty::Predicate::Subtype(..)
266 | ty::Predicate::ConstEvaluatable(..) => false,
271 fn trait_has_sized_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {
272 generics_require_sized_self(tcx, trait_def_id)
275 fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
276 let sized_def_id = match tcx.lang_items().sized_trait() {
277 Some(def_id) => def_id,
279 return false; /* No Sized trait, can't require it! */
283 // Search for a predicate like `Self : Sized` amongst the trait bounds.
284 let predicates = tcx.predicates_of(def_id);
285 let predicates = predicates.instantiate_identity(tcx).predicates;
286 elaborate_predicates(tcx, predicates).any(|predicate| match predicate {
287 ty::Predicate::Trait(ref trait_pred) => {
288 trait_pred.def_id() == sized_def_id && trait_pred.skip_binder().self_ty().is_param(0)
290 ty::Predicate::Projection(..)
291 | ty::Predicate::Subtype(..)
292 | ty::Predicate::RegionOutlives(..)
293 | ty::Predicate::WellFormed(..)
294 | ty::Predicate::ObjectSafe(..)
295 | ty::Predicate::ClosureKind(..)
296 | ty::Predicate::TypeOutlives(..)
297 | ty::Predicate::ConstEvaluatable(..) => false,
301 /// Returns `Some(_)` if this method makes the containing trait not object safe.
302 fn object_safety_violation_for_method(
305 method: &ty::AssocItem,
306 ) -> Option<MethodViolationCode> {
307 debug!("object_safety_violation_for_method({:?}, {:?})", trait_def_id, method);
308 // Any method that has a `Self : Sized` requisite is otherwise
309 // exempt from the regulations.
310 if generics_require_sized_self(tcx, method.def_id) {
314 virtual_call_violation_for_method(tcx, trait_def_id, method)
317 /// Returns `Some(_)` if this method cannot be called on a trait
318 /// object; this does not necessarily imply that the enclosing trait
319 /// is not object safe, because the method might have a where clause
321 fn virtual_call_violation_for_method<'tcx>(
324 method: &ty::AssocItem,
325 ) -> Option<MethodViolationCode> {
326 // The method's first parameter must be named `self`
327 if !method.method_has_self_argument {
328 return Some(MethodViolationCode::StaticMethod);
331 let sig = tcx.fn_sig(method.def_id);
333 for input_ty in &sig.skip_binder().inputs()[1..] {
334 if contains_illegal_self_type_reference(tcx, trait_def_id, input_ty) {
335 return Some(MethodViolationCode::ReferencesSelf);
338 if contains_illegal_self_type_reference(tcx, trait_def_id, sig.output().skip_binder()) {
339 return Some(MethodViolationCode::ReferencesSelf);
342 // We can't monomorphize things like `fn foo<A>(...)`.
343 let own_counts = tcx.generics_of(method.def_id).own_counts();
344 if own_counts.types + own_counts.consts != 0 {
345 return Some(MethodViolationCode::Generic);
349 .predicates_of(method.def_id)
352 // A trait object can't claim to live more than the concrete type,
353 // so outlives predicates will always hold.
355 .filter(|(p, _)| p.to_opt_type_outlives().is_none())
357 // Do a shallow visit so that `contains_illegal_self_type_reference`
358 // may apply it's custom visiting.
359 .visit_tys_shallow(|t| contains_illegal_self_type_reference(tcx, trait_def_id, t))
361 return Some(MethodViolationCode::WhereClauseReferencesSelf);
365 tcx.liberate_late_bound_regions(method.def_id, &sig.map_bound(|sig| sig.inputs()[0]));
367 // Until `unsized_locals` is fully implemented, `self: Self` can't be dispatched on.
368 // However, this is already considered object-safe. We allow it as a special case here.
369 // FIXME(mikeyhew) get rid of this `if` statement once `receiver_is_dispatchable` allows
370 // `Receiver: Unsize<Receiver[Self => dyn Trait]>`.
371 if receiver_ty != tcx.types.self_param {
372 if !receiver_is_dispatchable(tcx, method, receiver_ty) {
373 return Some(MethodViolationCode::UndispatchableReceiver);
375 // Do sanity check to make sure the receiver actually has the layout of a pointer.
377 use crate::ty::layout::Abi;
379 let param_env = tcx.param_env(method.def_id);
381 let abi_of_ty = |ty: Ty<'tcx>| -> &Abi {
382 match tcx.layout_of(param_env.and(ty)) {
383 Ok(layout) => &layout.abi,
384 Err(err) => bug!("error: {}\n while computing layout for type {:?}", err, ty),
389 let unit_receiver_ty =
390 receiver_for_self_ty(tcx, receiver_ty, tcx.mk_unit(), method.def_id);
392 match abi_of_ty(unit_receiver_ty) {
393 &Abi::Scalar(..) => (),
395 tcx.sess.delay_span_bug(
396 tcx.def_span(method.def_id),
398 "receiver when `Self = ()` should have a Scalar ABI; found {:?}",
405 let trait_object_ty =
406 object_ty_for_trait(tcx, trait_def_id, tcx.mk_region(ty::ReStatic));
408 // e.g., `Rc<dyn Trait>`
409 let trait_object_receiver =
410 receiver_for_self_ty(tcx, receiver_ty, trait_object_ty, method.def_id);
412 match abi_of_ty(trait_object_receiver) {
413 &Abi::ScalarPair(..) => (),
415 tcx.sess.delay_span_bug(
416 tcx.def_span(method.def_id),
418 "receiver when `Self = {}` should have a ScalarPair ABI; \
431 /// Performs a type substitution to produce the version of `receiver_ty` when `Self = self_ty`.
432 /// For example, for `receiver_ty = Rc<Self>` and `self_ty = Foo`, returns `Rc<Foo>`.
433 fn receiver_for_self_ty<'tcx>(
435 receiver_ty: Ty<'tcx>,
437 method_def_id: DefId,
439 debug!("receiver_for_self_ty({:?}, {:?}, {:?})", receiver_ty, self_ty, method_def_id);
440 let substs = InternalSubsts::for_item(tcx, method_def_id, |param, _| {
441 if param.index == 0 { self_ty.into() } else { tcx.mk_param_from_def(param) }
444 let result = receiver_ty.subst(tcx, substs);
446 "receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}",
447 receiver_ty, self_ty, method_def_id, result
452 /// Creates the object type for the current trait. For example,
453 /// if the current trait is `Deref`, then this will be
454 /// `dyn Deref<Target = Self::Target> + 'static`.
455 fn object_ty_for_trait<'tcx>(
458 lifetime: ty::Region<'tcx>,
460 debug!("object_ty_for_trait: trait_def_id={:?}", trait_def_id);
462 let trait_ref = ty::TraitRef::identity(tcx, trait_def_id);
464 let trait_predicate =
465 ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref));
467 let mut associated_types = traits::supertraits(tcx, ty::Binder::dummy(trait_ref))
468 .flat_map(|super_trait_ref| {
469 tcx.associated_items(super_trait_ref.def_id()).map(move |item| (super_trait_ref, item))
471 .filter(|(_, item)| item.kind == ty::AssocKind::Type)
472 .collect::<Vec<_>>();
474 // existential predicates need to be in a specific order
475 associated_types.sort_by_cached_key(|(_, item)| tcx.def_path_hash(item.def_id));
477 let projection_predicates = associated_types.into_iter().map(|(super_trait_ref, item)| {
478 // We *can* get bound lifetimes here in cases like
479 // `trait MyTrait: for<'s> OtherTrait<&'s T, Output=bool>`.
481 // binder moved to (*)...
482 let super_trait_ref = super_trait_ref.skip_binder();
483 ty::ExistentialPredicate::Projection(ty::ExistentialProjection {
484 ty: tcx.mk_projection(item.def_id, super_trait_ref.substs),
485 item_def_id: item.def_id,
486 substs: super_trait_ref.substs,
490 let existential_predicates =
491 tcx.mk_existential_predicates(iter::once(trait_predicate).chain(projection_predicates));
493 let object_ty = tcx.mk_dynamic(
494 // (*) ... binder re-introduced here
495 ty::Binder::bind(existential_predicates),
499 debug!("object_ty_for_trait: object_ty=`{}`", object_ty);
504 /// Checks the method's receiver (the `self` argument) can be dispatched on when `Self` is a
505 /// trait object. We require that `DispatchableFromDyn` be implemented for the receiver type
506 /// in the following way:
507 /// - let `Receiver` be the type of the `self` argument, i.e `Self`, `&Self`, `Rc<Self>`,
508 /// - require the following bound:
511 /// Receiver[Self => T]: DispatchFromDyn<Receiver[Self => dyn Trait]>
514 /// where `Foo[X => Y]` means "the same type as `Foo`, but with `X` replaced with `Y`"
515 /// (substitution notation).
517 /// Some examples of receiver types and their required obligation:
518 /// - `&'a mut self` requires `&'a mut Self: DispatchFromDyn<&'a mut dyn Trait>`,
519 /// - `self: Rc<Self>` requires `Rc<Self>: DispatchFromDyn<Rc<dyn Trait>>`,
520 /// - `self: Pin<Box<Self>>` requires `Pin<Box<Self>>: DispatchFromDyn<Pin<Box<dyn Trait>>>`.
522 /// The only case where the receiver is not dispatchable, but is still a valid receiver
523 /// type (just not object-safe), is when there is more than one level of pointer indirection.
524 /// E.g., `self: &&Self`, `self: &Rc<Self>`, `self: Box<Box<Self>>`. In these cases, there
525 /// is no way, or at least no inexpensive way, to coerce the receiver from the version where
526 /// `Self = dyn Trait` to the version where `Self = T`, where `T` is the unknown erased type
527 /// contained by the trait object, because the object that needs to be coerced is behind
530 /// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result
531 /// in a new check that `Trait` is object safe, creating a cycle (until object_safe_for_dispatch
532 /// is stabilized, see tracking issue https://github.com/rust-lang/rust/issues/43561).
533 /// Instead, we fudge a little by introducing a new type parameter `U` such that
534 /// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
535 /// Written as a chalk-style query:
537 /// forall (U: Trait + ?Sized) {
538 /// if (Self: Unsize<U>) {
539 /// Receiver: DispatchFromDyn<Receiver[Self => U]>
543 /// for `self: &'a mut Self`, this means `&'a mut Self: DispatchFromDyn<&'a mut U>`
544 /// for `self: Rc<Self>`, this means `Rc<Self>: DispatchFromDyn<Rc<U>>`
545 /// for `self: Pin<Box<Self>>`, this means `Pin<Box<Self>>: DispatchFromDyn<Pin<Box<U>>>`
547 // FIXME(mikeyhew) when unsized receivers are implemented as part of unsized rvalues, add this
548 // fallback query: `Receiver: Unsize<Receiver[Self => U]>` to support receivers like
549 // `self: Wrapper<Self>`.
551 fn receiver_is_dispatchable<'tcx>(
553 method: &ty::AssocItem,
554 receiver_ty: Ty<'tcx>,
556 debug!("receiver_is_dispatchable: method = {:?}, receiver_ty = {:?}", method, receiver_ty);
558 let traits = (tcx.lang_items().unsize_trait(), tcx.lang_items().dispatch_from_dyn_trait());
559 let (unsize_did, dispatch_from_dyn_did) = if let (Some(u), Some(cu)) = traits {
562 debug!("receiver_is_dispatchable: Missing Unsize or DispatchFromDyn traits");
566 // the type `U` in the query
567 // use a bogus type parameter to mimick a forall(U) query using u32::MAX for now.
568 // FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can
569 // replace this with `dyn Trait`
570 let unsized_self_ty: Ty<'tcx> =
571 tcx.mk_ty_param(::std::u32::MAX, Symbol::intern("RustaceansAreAwesome"));
573 // `Receiver[Self => U]`
574 let unsized_receiver_ty =
575 receiver_for_self_ty(tcx, receiver_ty, unsized_self_ty, method.def_id);
577 // create a modified param env, with `Self: Unsize<U>` and `U: Trait` added to caller bounds
578 // `U: ?Sized` is already implied here
580 let mut param_env = tcx.param_env(method.def_id);
583 let unsize_predicate = ty::TraitRef {
585 substs: tcx.mk_substs_trait(tcx.types.self_param, &[unsized_self_ty.into()]),
589 // U: Trait<Arg1, ..., ArgN>
590 let trait_predicate = {
592 InternalSubsts::for_item(tcx, method.container.assert_trait(), |param, _| {
593 if param.index == 0 {
594 unsized_self_ty.into()
596 tcx.mk_param_from_def(param)
600 ty::TraitRef { def_id: unsize_did, substs }.to_predicate()
603 let caller_bounds: Vec<Predicate<'tcx>> = param_env
607 .chain(iter::once(unsize_predicate))
608 .chain(iter::once(trait_predicate))
611 param_env.caller_bounds = tcx.intern_predicates(&caller_bounds);
616 // Receiver: DispatchFromDyn<Receiver[Self => U]>
618 let predicate = ty::TraitRef {
619 def_id: dispatch_from_dyn_did,
620 substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]),
624 Obligation::new(ObligationCause::dummy(), param_env, predicate)
627 tcx.infer_ctxt().enter(|ref infcx| {
628 // the receiver is dispatchable iff the obligation holds
629 infcx.predicate_must_hold_modulo_regions(&obligation)
633 fn contains_illegal_self_type_reference<'tcx>(
638 // This is somewhat subtle. In general, we want to forbid
639 // references to `Self` in the argument and return types,
640 // since the value of `Self` is erased. However, there is one
641 // exception: it is ok to reference `Self` in order to access
642 // an associated type of the current trait, since we retain
643 // the value of those associated types in the object type
647 // trait SuperTrait {
651 // trait Trait : SuperTrait {
653 // fn foo(&self, x: Self) // bad
654 // fn foo(&self) -> Self // bad
655 // fn foo(&self) -> Option<Self> // bad
656 // fn foo(&self) -> Self::Y // OK, desugars to next example
657 // fn foo(&self) -> <Self as Trait>::Y // OK
658 // fn foo(&self) -> Self::X // OK, desugars to next example
659 // fn foo(&self) -> <Self as SuperTrait>::X // OK
663 // However, it is not as simple as allowing `Self` in a projected
664 // type, because there are illegal ways to use `Self` as well:
667 // trait Trait : SuperTrait {
669 // fn foo(&self) -> <Self as SomeOtherTrait>::X;
673 // Here we will not have the type of `X` recorded in the
674 // object type, and we cannot resolve `Self as SomeOtherTrait`
675 // without knowing what `Self` is.
677 let mut supertraits: Option<Vec<ty::PolyTraitRef<'tcx>>> = None;
678 let mut error = false;
679 let self_ty = tcx.types.self_param;
687 false // no contained types to walk
690 ty::Projection(ref data) => {
691 // This is a projected type `<Foo as SomeTrait>::X`.
693 // Compute supertraits of current trait lazily.
694 if supertraits.is_none() {
695 let trait_ref = ty::Binder::bind(ty::TraitRef::identity(tcx, trait_def_id));
696 supertraits = Some(traits::supertraits(tcx, trait_ref).collect());
699 // Determine whether the trait reference `Foo as
700 // SomeTrait` is in fact a supertrait of the
701 // current trait. In that case, this type is
702 // legal, because the type `X` will be specified
703 // in the object type. Note that we can just use
704 // direct equality here because all of these types
705 // are part of the formal parameter listing, and
706 // hence there should be no inference variables.
707 let projection_trait_ref = ty::Binder::bind(data.trait_ref(tcx));
708 let is_supertrait_of_current_trait =
709 supertraits.as_ref().unwrap().contains(&projection_trait_ref);
711 if is_supertrait_of_current_trait {
712 false // do not walk contained types, do not report error, do collect $200
714 true // DO walk contained types, POSSIBLY reporting an error
718 _ => true, // walk contained types, if any
725 pub(super) fn is_object_safe_provider(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {
726 object_safety_violations(tcx, trait_def_id).is_empty()