1 use crate::infer::InferCtxt;
2 use crate::opaque_types::required_region_bounds;
3 use crate::traits::{self, AssocTypeBoundData};
5 use rustc_hir::def_id::DefId;
6 use rustc_hir::lang_items;
7 use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
8 use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
9 use rustc_span::symbol::{kw, Ident};
12 /// Returns the set of obligations needed to make `ty` well-formed.
13 /// If `ty` contains unresolved inference variables, this may include
14 /// further WF obligations. However, if `ty` IS an unresolved
15 /// inference variable, returns `None`, because we are not able to
16 /// make any progress at all. This is to prevent "livelock" where we
17 /// say "$0 is WF if $0 is WF".
18 pub fn obligations<'a, 'tcx>(
19 infcx: &InferCtxt<'a, 'tcx>,
20 param_env: ty::ParamEnv<'tcx>,
24 ) -> Option<Vec<traits::PredicateObligation<'tcx>>> {
25 let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
27 debug!("wf::obligations({:?}, body_id={:?}) = {:?}", ty, body_id, wf.out);
29 let result = wf.normalize();
30 debug!("wf::obligations({:?}, body_id={:?}) ~~> {:?}", ty, body_id, result);
33 None // no progress made, return None
37 /// Returns the obligations that make this trait reference
38 /// well-formed. For example, if there is a trait `Set` defined like
39 /// `trait Set<K:Eq>`, then the trait reference `Foo: Set<Bar>` is WF
41 pub fn trait_obligations<'a, 'tcx>(
42 infcx: &InferCtxt<'a, 'tcx>,
43 param_env: ty::ParamEnv<'tcx>,
45 trait_ref: &ty::TraitRef<'tcx>,
47 item: Option<&'tcx hir::Item<'tcx>>,
48 ) -> Vec<traits::PredicateObligation<'tcx>> {
49 let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item };
50 wf.compute_trait_ref(trait_ref, Elaborate::All);
54 pub fn predicate_obligations<'a, 'tcx>(
55 infcx: &InferCtxt<'a, 'tcx>,
56 param_env: ty::ParamEnv<'tcx>,
58 predicate: &ty::Predicate<'tcx>,
60 ) -> Vec<traits::PredicateObligation<'tcx>> {
61 let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
63 // (*) ok to skip binders, because wf code is prepared for it
65 ty::Predicate::Trait(ref t, _) => {
66 wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*)
68 ty::Predicate::RegionOutlives(..) => {}
69 ty::Predicate::TypeOutlives(ref t) => {
70 wf.compute(t.skip_binder().0);
72 ty::Predicate::Projection(ref t) => {
73 let t = t.skip_binder(); // (*)
74 wf.compute_projection(t.projection_ty);
77 ty::Predicate::WellFormed(t) => {
80 ty::Predicate::ObjectSafe(_) => {}
81 ty::Predicate::ClosureKind(..) => {}
82 ty::Predicate::Subtype(ref data) => {
83 wf.compute(data.skip_binder().a); // (*)
84 wf.compute(data.skip_binder().b); // (*)
86 ty::Predicate::ConstEvaluatable(def_id, substs) => {
87 let obligations = wf.nominal_obligations(def_id, substs);
88 wf.out.extend(obligations);
90 for ty in substs.types() {
99 struct WfPredicates<'a, 'tcx> {
100 infcx: &'a InferCtxt<'a, 'tcx>,
101 param_env: ty::ParamEnv<'tcx>,
104 out: Vec<traits::PredicateObligation<'tcx>>,
105 item: Option<&'tcx hir::Item<'tcx>>,
108 /// Controls whether we "elaborate" supertraits and so forth on the WF
109 /// predicates. This is a kind of hack to address #43784. The
110 /// underlying problem in that issue was a trait structure like:
113 /// trait Foo: Copy { }
114 /// trait Bar: Foo { }
115 /// impl<T: Bar> Foo for T { }
116 /// impl<T> Bar for T { }
119 /// Here, in the `Foo` impl, we will check that `T: Copy` holds -- but
120 /// we decide that this is true because `T: Bar` is in the
121 /// where-clauses (and we can elaborate that to include `T:
122 /// Copy`). This wouldn't be a problem, except that when we check the
123 /// `Bar` impl, we decide that `T: Foo` must hold because of the `Foo`
124 /// impl. And so nowhere did we check that `T: Copy` holds!
126 /// To resolve this, we elaborate the WF requirements that must be
127 /// proven when checking impls. This means that (e.g.) the `impl Bar
128 /// for T` will be forced to prove not only that `T: Foo` but also `T:
129 /// Copy` (which it won't be able to do, because there is no `Copy`
131 #[derive(Debug, PartialEq, Eq, Copy, Clone)]
137 impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
138 fn cause(&mut self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> {
139 traits::ObligationCause::new(self.span, self.body_id, code)
142 fn normalize(&mut self) -> Vec<traits::PredicateObligation<'tcx>> {
143 let cause = self.cause(traits::MiscObligation);
144 let infcx = &mut self.infcx;
145 let param_env = self.param_env;
146 let mut obligations = Vec::with_capacity(self.out.len());
147 for pred in &self.out {
148 assert!(!pred.has_escaping_bound_vars());
149 let mut selcx = traits::SelectionContext::new(infcx);
150 let i = obligations.len();
152 traits::normalize_to(&mut selcx, param_env, cause.clone(), pred, &mut obligations);
153 obligations.insert(i, value);
158 /// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
159 fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elaborate) {
160 let tcx = self.infcx.tcx;
161 let obligations = self.nominal_obligations(trait_ref.def_id, trait_ref.substs);
163 let cause = self.cause(traits::MiscObligation);
164 let param_env = self.param_env;
166 let item = &self.item;
167 let extend_cause_with_original_assoc_item_obligation =
168 |cause: &mut traits::ObligationCause<'_>,
169 pred: &ty::Predicate<'_>,
170 trait_assoc_items: &[ty::AssocItem]| {
173 .as_local_hir_id(trait_ref.def_id)
174 .and_then(|trait_id| tcx.hir().find(trait_id));
175 let (trait_name, trait_generics) = match trait_item {
176 Some(hir::Node::Item(hir::Item {
178 kind: hir::ItemKind::Trait(.., generics, _, _),
181 | Some(hir::Node::Item(hir::Item {
183 kind: hir::ItemKind::TraitAlias(generics, _),
185 })) => (Some(ident), Some(generics)),
189 let item_span = item.map(|i| tcx.sess.source_map().guess_head_span(i.span));
191 ty::Predicate::Projection(proj) => {
192 // The obligation comes not from the current `impl` nor the `trait` being
193 // implemented, but rather from a "second order" obligation, like in
194 // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs`:
196 // error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
197 // --> $DIR/point-at-type-on-obligation-failure.rs:13:5
200 // | -- associated type defined here
202 // LL | impl Bar for Foo {
203 // | ---------------- in this `impl` item
204 // LL | type Ok = ();
205 // | ^^^^^^^^^^^^^ expected `u32`, found `()`
207 // = note: expected type `u32`
210 // FIXME: we would want to point a span to all places that contributed to this
211 // obligation. In the case above, it should be closer to:
213 // error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
214 // --> $DIR/point-at-type-on-obligation-failure.rs:13:5
217 // | -- associated type defined here
218 // LL | type Sibling: Bar2<Ok=Self::Ok>;
219 // | -------------------------------- obligation set here
221 // LL | impl Bar for Foo {
222 // | ---------------- in this `impl` item
223 // LL | type Ok = ();
224 // | ^^^^^^^^^^^^^ expected `u32`, found `()`
226 // LL | impl Bar2 for Foo2 {
227 // | ---------------- in this `impl` item
228 // LL | type Ok = u32;
229 // | -------------- obligation set here
231 // = note: expected type `u32`
233 if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
234 let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
235 if let Some(impl_item) =
236 items.iter().find(|item| item.ident == trait_assoc_item.ident)
238 cause.span = impl_item.span;
239 cause.code = traits::AssocTypeBound(Box::new(AssocTypeBoundData {
240 impl_span: item_span,
241 original: trait_assoc_item.ident.span,
247 ty::Predicate::Trait(proj, _) => {
248 // An associated item obligation born out of the `trait` failed to be met.
249 // Point at the `impl` that failed the obligation, the associated item that
250 // needed to meet the obligation, and the definition of that associated item,
251 // which should hold the obligation in most cases. An example can be seen in
252 // `src/test/ui/associated-types/point-at-type-on-obligation-failure-2.rs`:
254 // error[E0277]: the trait bound `bool: Bar` is not satisfied
255 // --> $DIR/point-at-type-on-obligation-failure-2.rs:8:5
257 // LL | type Assoc: Bar;
258 // | ----- associated type defined here
260 // LL | impl Foo for () {
261 // | --------------- in this `impl` item
262 // LL | type Assoc = bool;
263 // | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
265 // If the obligation comes from the where clause in the `trait`, we point at it:
267 // error[E0277]: the trait bound `bool: Bar` is not satisfied
268 // --> $DIR/point-at-type-on-obligation-failure-2.rs:8:5
270 // | trait Foo where <Self as Foo>>::Assoc: Bar {
271 // | -------------------------- restricted in this bound
273 // | ----- associated type defined here
275 // LL | impl Foo for () {
276 // | --------------- in this `impl` item
277 // LL | type Assoc = bool;
278 // | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
280 ty::Projection(ty::ProjectionTy { item_def_id, .. }),
281 Some(hir::ItemKind::Impl { items, .. }),
282 ) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
284 if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
286 .find(|i| i.def_id == *item_def_id)
287 .and_then(|trait_assoc_item| {
290 .find(|i| i.ident == trait_assoc_item.ident)
291 .map(|impl_item| (impl_item, trait_assoc_item))
294 let bounds = trait_generics
296 get_generic_bound_spans(
299 trait_assoc_item.ident,
302 .unwrap_or_else(Vec::new);
303 cause.span = impl_item.span;
304 cause.code = traits::AssocTypeBound(Box::new(AssocTypeBoundData {
305 impl_span: item_span,
306 original: trait_assoc_item.ident.span,
316 if let Elaborate::All = elaborate {
317 // FIXME: Make `extend_cause_with_original_assoc_item_obligation` take an iterator
318 // instead of a slice.
319 let trait_assoc_items: Vec<_> =
320 tcx.associated_items(trait_ref.def_id).in_definition_order().copied().collect();
322 let predicates = obligations.iter().map(|obligation| obligation.predicate).collect();
323 let implied_obligations = traits::elaborate_predicates(tcx, predicates);
324 let implied_obligations = implied_obligations.map(|pred| {
325 let mut cause = cause.clone();
326 extend_cause_with_original_assoc_item_obligation(
331 traits::Obligation::new(cause, param_env, pred)
333 self.out.extend(implied_obligations);
336 self.out.extend(obligations);
338 self.out.extend(trait_ref.substs.types().filter(|ty| !ty.has_escaping_bound_vars()).map(
339 |ty| traits::Obligation::new(cause.clone(), param_env, ty::Predicate::WellFormed(ty)),
343 /// Pushes the obligations required for `trait_ref::Item` to be WF
345 fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) {
346 // A projection is well-formed if (a) the trait ref itself is
347 // WF and (b) the trait-ref holds. (It may also be
348 // normalizable and be WF that way.)
349 let trait_ref = data.trait_ref(self.infcx.tcx);
350 self.compute_trait_ref(&trait_ref, Elaborate::None);
352 if !data.has_escaping_bound_vars() {
353 let predicate = trait_ref.without_const().to_predicate();
354 let cause = self.cause(traits::ProjectionWf(data));
355 self.out.push(traits::Obligation::new(cause, self.param_env, predicate));
359 /// Pushes the obligations required for an array length to be WF
361 fn compute_array_len(&mut self, constant: ty::Const<'tcx>) {
362 if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = constant.val {
363 assert!(promoted.is_none());
365 let obligations = self.nominal_obligations(def_id, substs);
366 self.out.extend(obligations);
368 let predicate = ty::Predicate::ConstEvaluatable(def_id, substs);
369 let cause = self.cause(traits::MiscObligation);
370 self.out.push(traits::Obligation::new(cause, self.param_env, predicate));
374 fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) {
375 if !subty.has_escaping_bound_vars() {
376 let cause = self.cause(cause);
377 let trait_ref = ty::TraitRef {
378 def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None),
379 substs: self.infcx.tcx.mk_substs_trait(subty, &[]),
381 self.out.push(traits::Obligation::new(
384 trait_ref.without_const().to_predicate(),
389 /// Pushes new obligations into `out`. Returns `true` if it was able
390 /// to generate all the predicates needed to validate that `ty0`
391 /// is WF. Returns false if `ty0` is an unresolved type variable,
392 /// in which case we are not able to simplify at all.
393 fn compute(&mut self, ty0: Ty<'tcx>) -> bool {
394 let mut walker = ty0.walk();
395 let param_env = self.param_env;
396 while let Some(arg) = walker.next() {
397 let ty = match arg.unpack() {
398 GenericArgKind::Type(ty) => ty,
400 // No WF constraints for lifetimes being present, any outlives
401 // obligations are handled by the parent (e.g. `ty::Ref`).
402 GenericArgKind::Lifetime(_) => continue,
404 // FIXME(eddyb) this is wrong and needs to be replaced
405 // (see https://github.com/rust-lang/rust/pull/70107).
406 GenericArgKind::Const(_) => continue,
417 | ty::GeneratorWitness(..)
421 | ty::Placeholder(..)
422 | ty::Foreign(..) => {
423 // WfScalar, WfParameter, etc
426 ty::Slice(subty) => {
427 self.require_sized(subty, traits::SliceOrArrayElem);
430 ty::Array(subty, len) => {
431 self.require_sized(subty, traits::SliceOrArrayElem);
432 // FIXME(eddyb) handle `GenericArgKind::Const` above instead.
433 self.compute_array_len(*len);
436 ty::Tuple(ref tys) => {
437 if let Some((_last, rest)) = tys.split_last() {
439 self.require_sized(elem.expect_ty(), traits::TupleElem);
445 // simple cases that are WF if their type args are WF
448 ty::Projection(data) => {
449 walker.skip_current_subtree(); // subtree handled by compute_projection
450 self.compute_projection(data);
453 ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
455 ty::Adt(def, substs) => {
457 let obligations = self.nominal_obligations(def.did, substs);
458 self.out.extend(obligations);
461 ty::FnDef(did, substs) => {
462 let obligations = self.nominal_obligations(did, substs);
463 self.out.extend(obligations);
466 ty::Ref(r, rty, _) => {
468 if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
469 let cause = self.cause(traits::ReferenceOutlivesReferent(ty));
470 self.out.push(traits::Obligation::new(
473 ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
480 ty::Generator(..) => {
481 // Walk ALL the types in the generator: this will
482 // include the upvar types as well as the yield
483 // type. Note that this is mildly distinct from
484 // the closure case, where we have to be careful
485 // about the signature of the closure. We don't
486 // have the problem of implied bounds here since
487 // generators don't take arguments.
490 ty::Closure(_, substs) => {
491 // Only check the upvar types for WF, not the rest
492 // of the types within. This is needed because we
493 // capture the signature and it may not be WF
494 // without the implied bounds. Consider a closure
495 // like `|x: &'a T|` -- it may be that `T: 'a` is
496 // not known to hold in the creator's context (and
497 // indeed the closure may not be invoked by its
498 // creator, but rather turned to someone who *can*
501 // The special treatment of closures here really
502 // ought not to be necessary either; the problem
503 // is related to #25860 -- there is no way for us
504 // to express a fn type complete with the implied
505 // bounds that it is assuming. I think in reality
506 // the WF rules around fn are a bit messed up, and
507 // that is the rot problem: `fn(&'a T)` should
508 // probably always be WF, because it should be
509 // shorthand for something like `where(T: 'a) {
510 // fn(&'a T) }`, as discussed in #25860.
512 // Note that we are also skipping the generic
513 // types. This is consistent with the `outlives`
514 // code, but anyway doesn't matter: within the fn
515 // body where they are created, the generics will
516 // always be WF, and outside of that fn body we
517 // are not directly inspecting closure types
518 // anyway, except via auto trait matching (which
519 // only inspects the upvar types).
520 walker.skip_current_subtree(); // subtree handled by compute_projection
521 for upvar_ty in substs.as_closure().upvar_tys() {
522 self.compute(upvar_ty);
527 // let the loop iterate into the argument/return
528 // types appearing in the fn signature
531 ty::Opaque(did, substs) => {
532 // all of the requirements on type parameters
533 // should've been checked by the instantiation
534 // of whatever returned this exact `impl Trait`.
536 // for named opaque `impl Trait` types we still need to check them
537 if ty::is_impl_trait_defn(self.infcx.tcx, did).is_none() {
538 let obligations = self.nominal_obligations(did, substs);
539 self.out.extend(obligations);
543 ty::Dynamic(data, r) => {
546 // Here, we defer WF checking due to higher-ranked
547 // regions. This is perhaps not ideal.
548 self.from_object_ty(ty, data, r);
550 // FIXME(#27579) RFC also considers adding trait
551 // obligations that don't refer to Self and
554 let defer_to_coercion = self.infcx.tcx.features().object_safe_for_dispatch;
556 if !defer_to_coercion {
557 let cause = self.cause(traits::MiscObligation);
558 let component_traits = data.auto_traits().chain(data.principal_def_id());
559 self.out.extend(component_traits.map(|did| {
560 traits::Obligation::new(
563 ty::Predicate::ObjectSafe(did),
569 // Inference variables are the complicated case, since we don't
570 // know what type they are. We do two things:
572 // 1. Check if they have been resolved, and if so proceed with
574 // 2. If not, check whether this is the type that we
575 // started with (ty0). In that case, we've made no
576 // progress at all, so return false. Otherwise,
577 // we've at least simplified things (i.e., we went
578 // from `Vec<$0>: WF` to `$0: WF`, so we can
579 // register a pending obligation and keep
580 // moving. (Goal is that an "inductive hypothesis"
581 // is satisfied to ensure termination.)
583 let ty = self.infcx.shallow_resolve(ty);
584 if let ty::Infer(_) = ty.kind {
585 // not yet resolved...
587 // ...this is the type we started from! no progress.
591 let cause = self.cause(traits::MiscObligation);
593 // ...not the type we started from, so we made progress.
594 traits::Obligation::new(
597 ty::Predicate::WellFormed(ty),
601 // Yes, resolved, proceed with the
602 // result. Should never return false because
603 // `ty` is not a Infer.
604 assert!(self.compute(ty));
610 // if we made it through that loop above, we made progress!
614 fn nominal_obligations(
617 substs: SubstsRef<'tcx>,
618 ) -> Vec<traits::PredicateObligation<'tcx>> {
619 let predicates = self.infcx.tcx.predicates_of(def_id).instantiate(self.infcx.tcx, substs);
620 let cause = self.cause(traits::ItemObligation(def_id));
624 .map(|pred| traits::Obligation::new(cause.clone(), self.param_env, pred))
625 .filter(|pred| !pred.has_escaping_bound_vars())
632 data: ty::Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>,
633 region: ty::Region<'tcx>,
635 // Imagine a type like this:
638 // trait Bar<'c> : 'c { }
640 // &'b (Foo+'c+Bar<'d>)
643 // In this case, the following relationships must hold:
648 // The first conditions is due to the normal region pointer
649 // rules, which say that a reference cannot outlive its
652 // The final condition may be a bit surprising. In particular,
653 // you may expect that it would have been `'c <= 'd`, since
654 // usually lifetimes of outer things are conservative
655 // approximations for inner things. However, it works somewhat
656 // differently with trait objects: here the idea is that if the
657 // user specifies a region bound (`'c`, in this case) it is the
658 // "master bound" that *implies* that bounds from other traits are
659 // all met. (Remember that *all bounds* in a type like
660 // `Foo+Bar+Zed` must be met, not just one, hence if we write
661 // `Foo<'x>+Bar<'y>`, we know that the type outlives *both* 'x and
664 // Note: in fact we only permit builtin traits, not `Bar<'d>`, I
665 // am looking forward to the future here.
666 if !data.has_escaping_bound_vars() && !region.has_escaping_bound_vars() {
667 let implicit_bounds = object_region_bounds(self.infcx.tcx, data);
669 let explicit_bound = region;
671 self.out.reserve(implicit_bounds.len());
672 for implicit_bound in implicit_bounds {
673 let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound));
675 ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound));
676 self.out.push(traits::Obligation::new(
679 outlives.to_predicate(),
686 /// Given an object type like `SomeTrait + Send`, computes the lifetime
687 /// bounds that must hold on the elided self type. These are derived
688 /// from the declarations of `SomeTrait`, `Send`, and friends -- if
689 /// they declare `trait SomeTrait : 'static`, for example, then
690 /// `'static` would appear in the list. The hard work is done by
691 /// `infer::required_region_bounds`, see that for more information.
692 pub fn object_region_bounds<'tcx>(
694 existential_predicates: ty::Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>,
695 ) -> Vec<ty::Region<'tcx>> {
696 // Since we don't actually *know* the self type for an object,
697 // this "open(err)" serves as a kind of dummy standin -- basically
698 // a placeholder type.
699 let open_ty = tcx.mk_ty_infer(ty::FreshTy(0));
701 let predicates = existential_predicates
703 .filter_map(|predicate| {
704 if let ty::ExistentialPredicate::Projection(_) = *predicate.skip_binder() {
707 Some(predicate.with_self_ty(tcx, open_ty))
712 required_region_bounds(tcx, open_ty, predicates)
715 /// Find the span of a generic bound affecting an associated type.
716 fn get_generic_bound_spans(
717 generics: &hir::Generics<'_>,
718 trait_name: Option<&Ident>,
719 assoc_item_name: Ident,
721 let mut bounds = vec![];
722 for clause in generics.where_clause.predicates.iter() {
723 if let hir::WherePredicate::BoundPredicate(pred) = clause {
724 match &pred.bounded_ty.kind {
725 hir::TyKind::Path(hir::QPath::Resolved(Some(ty), path)) => {
726 let mut s = path.segments.iter();
727 if let (a, Some(b), None) = (s.next(), s.next(), s.next()) {
728 if a.map(|s| &s.ident) == trait_name
729 && b.ident == assoc_item_name
730 && is_self_path(&ty.kind)
732 // `<Self as Foo>::Bar`
733 bounds.push(pred.span);
737 hir::TyKind::Path(hir::QPath::TypeRelative(ty, segment)) => {
738 if segment.ident == assoc_item_name {
739 if is_self_path(&ty.kind) {
741 bounds.push(pred.span);
752 fn is_self_path(kind: &hir::TyKind<'_>) -> bool {
753 if let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = kind {
754 let mut s = path.segments.iter();
755 if let (Some(segment), None) = (s.next(), s.next()) {
756 if segment.ident.name == kw::SelfUpper {