2020-01-05 23:28:45 +01:00
|
|
|
use crate::infer::opaque_types::required_region_bounds;
|
2019-02-05 18:20:45 +01:00
|
|
|
use crate::infer::InferCtxt;
|
2019-10-31 05:24:08 +01:00
|
|
|
use crate::traits::{self, AssocTypeBoundData};
|
2020-01-07 22:07:22 +01:00
|
|
|
use rustc::middle::lang_items;
|
|
|
|
use rustc::ty::subst::SubstsRef;
|
|
|
|
use rustc::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_hir::def_id::DefId;
|
2020-01-01 19:30:57 +01:00
|
|
|
use rustc_span::symbol::{kw, Ident};
|
2019-12-31 18:15:40 +01:00
|
|
|
use rustc_span::Span;
|
2015-08-06 20:27:21 +02:00
|
|
|
|
|
|
|
/// Returns the set of obligations needed to make `ty` well-formed.
|
|
|
|
/// If `ty` contains unresolved inference variables, this may include
|
|
|
|
/// further WF obligations. However, if `ty` IS an unresolved
|
|
|
|
/// inference variable, returns `None`, because we are not able to
|
|
|
|
/// make any progress at all. This is to prevent "livelock" where we
|
|
|
|
/// say "$0 is WF if $0 is WF".
|
2019-06-14 00:32:15 +02:00
|
|
|
pub fn obligations<'a, 'tcx>(
|
|
|
|
infcx: &InferCtxt<'a, 'tcx>,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
body_id: hir::HirId,
|
|
|
|
ty: Ty<'tcx>,
|
|
|
|
span: Span,
|
|
|
|
) -> Option<Vec<traits::PredicateObligation<'tcx>>> {
|
2019-12-24 23:38:22 +01:00
|
|
|
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
|
2015-08-06 20:27:21 +02:00
|
|
|
if wf.compute(ty) {
|
|
|
|
debug!("wf::obligations({:?}, body_id={:?}) = {:?}", ty, body_id, wf.out);
|
2020-01-08 22:06:25 +01:00
|
|
|
|
2015-08-06 20:27:21 +02:00
|
|
|
let result = wf.normalize();
|
|
|
|
debug!("wf::obligations({:?}, body_id={:?}) ~~> {:?}", ty, body_id, result);
|
|
|
|
Some(result)
|
|
|
|
} else {
|
|
|
|
None // no progress made, return None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the obligations that make this trait reference
|
|
|
|
/// well-formed. For example, if there is a trait `Set` defined like
|
|
|
|
/// `trait Set<K:Eq>`, then the trait reference `Foo: Set<Bar>` is WF
|
|
|
|
/// if `Bar: Eq`.
|
2019-06-14 00:32:15 +02:00
|
|
|
pub fn trait_obligations<'a, 'tcx>(
|
|
|
|
infcx: &InferCtxt<'a, 'tcx>,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
body_id: hir::HirId,
|
|
|
|
trait_ref: &ty::TraitRef<'tcx>,
|
|
|
|
span: Span,
|
2019-11-28 19:28:50 +01:00
|
|
|
item: Option<&'tcx hir::Item<'tcx>>,
|
2019-06-14 00:32:15 +02:00
|
|
|
) -> Vec<traits::PredicateObligation<'tcx>> {
|
2019-10-11 01:20:42 +02:00
|
|
|
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item };
|
2017-08-10 15:52:08 +02:00
|
|
|
wf.compute_trait_ref(trait_ref, Elaborate::All);
|
2015-08-06 20:27:21 +02:00
|
|
|
wf.normalize()
|
|
|
|
}
|
|
|
|
|
2019-06-14 00:32:15 +02:00
|
|
|
pub fn predicate_obligations<'a, 'tcx>(
|
|
|
|
infcx: &InferCtxt<'a, 'tcx>,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
body_id: hir::HirId,
|
|
|
|
predicate: &ty::Predicate<'tcx>,
|
|
|
|
span: Span,
|
|
|
|
) -> Vec<traits::PredicateObligation<'tcx>> {
|
2019-10-11 01:20:42 +02:00
|
|
|
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
|
2015-08-06 20:27:21 +02:00
|
|
|
|
|
|
|
// (*) ok to skip binders, because wf code is prepared for it
|
|
|
|
match *predicate {
|
2020-01-14 05:30:31 +01:00
|
|
|
ty::Predicate::Trait(ref t, _) => {
|
2017-08-10 15:52:08 +02:00
|
|
|
wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*)
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
2019-12-24 23:38:22 +01:00
|
|
|
ty::Predicate::RegionOutlives(..) => {}
|
2015-08-06 20:27:21 +02:00
|
|
|
ty::Predicate::TypeOutlives(ref t) => {
|
|
|
|
wf.compute(t.skip_binder().0);
|
|
|
|
}
|
|
|
|
ty::Predicate::Projection(ref t) => {
|
|
|
|
let t = t.skip_binder(); // (*)
|
|
|
|
wf.compute_projection(t.projection_ty);
|
|
|
|
wf.compute(t.ty);
|
|
|
|
}
|
|
|
|
ty::Predicate::WellFormed(t) => {
|
|
|
|
wf.compute(t);
|
|
|
|
}
|
2019-12-24 23:38:22 +01:00
|
|
|
ty::Predicate::ObjectSafe(_) => {}
|
|
|
|
ty::Predicate::ClosureKind(..) => {}
|
2017-03-10 03:47:09 +01:00
|
|
|
ty::Predicate::Subtype(ref data) => {
|
|
|
|
wf.compute(data.skip_binder().a); // (*)
|
|
|
|
wf.compute(data.skip_binder().b); // (*)
|
|
|
|
}
|
2017-08-07 07:08:53 +02:00
|
|
|
ty::Predicate::ConstEvaluatable(def_id, substs) => {
|
|
|
|
let obligations = wf.nominal_obligations(def_id, substs);
|
|
|
|
wf.out.extend(obligations);
|
|
|
|
|
|
|
|
for ty in substs.types() {
|
|
|
|
wf.compute(ty);
|
|
|
|
}
|
|
|
|
}
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
wf.normalize()
|
|
|
|
}
|
|
|
|
|
2019-06-14 18:39:39 +02:00
|
|
|
struct WfPredicates<'a, 'tcx> {
|
2019-06-13 23:48:52 +02:00
|
|
|
infcx: &'a InferCtxt<'a, 'tcx>,
|
2017-05-23 10:19:47 +02:00
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
2019-02-04 20:01:14 +01:00
|
|
|
body_id: hir::HirId,
|
2015-08-06 20:27:21 +02:00
|
|
|
span: Span,
|
|
|
|
out: Vec<traits::PredicateObligation<'tcx>>,
|
2019-11-28 19:28:50 +01:00
|
|
|
item: Option<&'tcx hir::Item<'tcx>>,
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 00:56:19 +02:00
|
|
|
/// Controls whether we "elaborate" supertraits and so forth on the WF
|
|
|
|
/// predicates. This is a kind of hack to address #43784. The
|
|
|
|
/// underlying problem in that issue was a trait structure like:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// trait Foo: Copy { }
|
|
|
|
/// trait Bar: Foo { }
|
|
|
|
/// impl<T: Bar> Foo for T { }
|
|
|
|
/// impl<T> Bar for T { }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// Here, in the `Foo` impl, we will check that `T: Copy` holds -- but
|
|
|
|
/// we decide that this is true because `T: Bar` is in the
|
|
|
|
/// where-clauses (and we can elaborate that to include `T:
|
|
|
|
/// Copy`). This wouldn't be a problem, except that when we check the
|
|
|
|
/// `Bar` impl, we decide that `T: Foo` must hold because of the `Foo`
|
|
|
|
/// impl. And so nowhere did we check that `T: Copy` holds!
|
|
|
|
///
|
|
|
|
/// To resolve this, we elaborate the WF requirements that must be
|
|
|
|
/// proven when checking impls. This means that (e.g.) the `impl Bar
|
|
|
|
/// for T` will be forced to prove not only that `T: Foo` but also `T:
|
|
|
|
/// Copy` (which it won't be able to do, because there is no `Copy`
|
|
|
|
/// impl for `T`).
|
2017-08-10 15:52:08 +02:00
|
|
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
|
|
|
enum Elaborate {
|
|
|
|
All,
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:48:52 +02:00
|
|
|
impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
2015-08-06 20:27:21 +02:00
|
|
|
fn cause(&mut self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> {
|
2015-12-15 10:31:58 +01:00
|
|
|
traits::ObligationCause::new(self.span, self.body_id, code)
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn normalize(&mut self) -> Vec<traits::PredicateObligation<'tcx>> {
|
|
|
|
let cause = self.cause(traits::MiscObligation);
|
|
|
|
let infcx = &mut self.infcx;
|
2017-05-23 10:19:47 +02:00
|
|
|
let param_env = self.param_env;
|
2020-02-10 14:28:56 +01:00
|
|
|
let mut obligations = Vec::with_capacity(self.out.len());
|
|
|
|
for pred in &self.out {
|
|
|
|
assert!(!pred.has_escaping_bound_vars());
|
2020-01-08 22:06:25 +01:00
|
|
|
let mut selcx = traits::SelectionContext::new(infcx);
|
|
|
|
let i = obligations.len();
|
|
|
|
let value =
|
|
|
|
traits::normalize_to(&mut selcx, param_env, cause.clone(), pred, &mut obligations);
|
|
|
|
obligations.insert(i, value);
|
2020-02-10 14:28:56 +01:00
|
|
|
}
|
2020-01-08 22:06:25 +01:00
|
|
|
obligations
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 01:20:42 +02:00
|
|
|
/// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
|
2017-08-10 15:52:08 +02:00
|
|
|
fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elaborate) {
|
2019-10-11 04:25:34 +02:00
|
|
|
let tcx = self.infcx.tcx;
|
2015-08-06 20:27:21 +02:00
|
|
|
let obligations = self.nominal_obligations(trait_ref.def_id, trait_ref.substs);
|
|
|
|
|
|
|
|
let cause = self.cause(traits::MiscObligation);
|
2017-05-23 10:19:47 +02:00
|
|
|
let param_env = self.param_env;
|
2017-08-10 14:41:24 +02:00
|
|
|
|
2019-10-22 21:40:46 +02:00
|
|
|
let item = &self.item;
|
2019-12-24 23:38:22 +01:00
|
|
|
let extend_cause_with_original_assoc_item_obligation =
|
|
|
|
|cause: &mut traits::ObligationCause<'_>,
|
|
|
|
pred: &ty::Predicate<'_>,
|
2020-02-06 23:21:44 +01:00
|
|
|
trait_assoc_items: &[ty::AssocItem]| {
|
2019-12-24 23:38:22 +01:00
|
|
|
let trait_item = tcx
|
|
|
|
.hir()
|
|
|
|
.as_local_hir_id(trait_ref.def_id)
|
|
|
|
.and_then(|trait_id| tcx.hir().find(trait_id));
|
|
|
|
let (trait_name, trait_generics) = match trait_item {
|
|
|
|
Some(hir::Node::Item(hir::Item {
|
|
|
|
ident,
|
|
|
|
kind: hir::ItemKind::Trait(.., generics, _, _),
|
|
|
|
..
|
|
|
|
}))
|
|
|
|
| Some(hir::Node::Item(hir::Item {
|
|
|
|
ident,
|
|
|
|
kind: hir::ItemKind::TraitAlias(generics, _),
|
|
|
|
..
|
|
|
|
})) => (Some(ident), Some(generics)),
|
|
|
|
_ => (None, None),
|
|
|
|
};
|
|
|
|
|
|
|
|
let item_span = item.map(|i| tcx.sess.source_map().def_span(i.span));
|
|
|
|
match pred {
|
|
|
|
ty::Predicate::Projection(proj) => {
|
|
|
|
// The obligation comes not from the current `impl` nor the `trait` being
|
|
|
|
// implemented, but rather from a "second order" obligation, like in
|
|
|
|
// `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs`:
|
|
|
|
//
|
|
|
|
// error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
|
|
|
|
// --> $DIR/point-at-type-on-obligation-failure.rs:13:5
|
|
|
|
// |
|
|
|
|
// LL | type Ok;
|
|
|
|
// | -- associated type defined here
|
|
|
|
// ...
|
|
|
|
// LL | impl Bar for Foo {
|
|
|
|
// | ---------------- in this `impl` item
|
|
|
|
// LL | type Ok = ();
|
|
|
|
// | ^^^^^^^^^^^^^ expected `u32`, found `()`
|
|
|
|
// |
|
|
|
|
// = note: expected type `u32`
|
|
|
|
// found type `()`
|
|
|
|
//
|
|
|
|
// FIXME: we would want to point a span to all places that contributed to this
|
|
|
|
// obligation. In the case above, it should be closer to:
|
|
|
|
//
|
|
|
|
// error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
|
|
|
|
// --> $DIR/point-at-type-on-obligation-failure.rs:13:5
|
|
|
|
// |
|
|
|
|
// LL | type Ok;
|
|
|
|
// | -- associated type defined here
|
|
|
|
// LL | type Sibling: Bar2<Ok=Self::Ok>;
|
|
|
|
// | -------------------------------- obligation set here
|
|
|
|
// ...
|
|
|
|
// LL | impl Bar for Foo {
|
|
|
|
// | ---------------- in this `impl` item
|
|
|
|
// LL | type Ok = ();
|
|
|
|
// | ^^^^^^^^^^^^^ expected `u32`, found `()`
|
|
|
|
// ...
|
|
|
|
// LL | impl Bar2 for Foo2 {
|
|
|
|
// | ---------------- in this `impl` item
|
|
|
|
// LL | type Ok = u32;
|
|
|
|
// | -------------- obligation set here
|
|
|
|
// |
|
|
|
|
// = note: expected type `u32`
|
|
|
|
// found type `()`
|
2020-01-18 01:14:29 +01:00
|
|
|
if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
|
2019-12-24 23:38:22 +01:00
|
|
|
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
|
2020-02-28 13:36:45 +01:00
|
|
|
if let Some(impl_item) =
|
|
|
|
items.iter().find(|item| item.ident == trait_assoc_item.ident)
|
2019-12-24 23:38:22 +01:00
|
|
|
{
|
|
|
|
cause.span = impl_item.span;
|
|
|
|
cause.code = traits::AssocTypeBound(Box::new(AssocTypeBoundData {
|
|
|
|
impl_span: item_span,
|
|
|
|
original: trait_assoc_item.ident.span,
|
|
|
|
bounds: vec![],
|
|
|
|
}));
|
|
|
|
}
|
2019-10-11 04:25:34 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-14 05:30:31 +01:00
|
|
|
ty::Predicate::Trait(proj, _) => {
|
2019-12-24 23:38:22 +01:00
|
|
|
// An associated item obligation born out of the `trait` failed to be met.
|
|
|
|
// Point at the `impl` that failed the obligation, the associated item that
|
|
|
|
// needed to meet the obligation, and the definition of that associated item,
|
|
|
|
// which should hold the obligation in most cases. An example can be seen in
|
|
|
|
// `src/test/ui/associated-types/point-at-type-on-obligation-failure-2.rs`:
|
|
|
|
//
|
|
|
|
// error[E0277]: the trait bound `bool: Bar` is not satisfied
|
|
|
|
// --> $DIR/point-at-type-on-obligation-failure-2.rs:8:5
|
|
|
|
// |
|
|
|
|
// LL | type Assoc: Bar;
|
|
|
|
// | ----- associated type defined here
|
|
|
|
// ...
|
|
|
|
// LL | impl Foo for () {
|
|
|
|
// | --------------- in this `impl` item
|
|
|
|
// LL | type Assoc = bool;
|
|
|
|
// | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
|
|
|
|
//
|
|
|
|
// If the obligation comes from the where clause in the `trait`, we point at it:
|
|
|
|
//
|
|
|
|
// error[E0277]: the trait bound `bool: Bar` is not satisfied
|
|
|
|
// --> $DIR/point-at-type-on-obligation-failure-2.rs:8:5
|
|
|
|
// |
|
|
|
|
// | trait Foo where <Self as Foo>>::Assoc: Bar {
|
|
|
|
// | -------------------------- restricted in this bound
|
|
|
|
// LL | type Assoc;
|
|
|
|
// | ----- associated type defined here
|
|
|
|
// ...
|
|
|
|
// LL | impl Foo for () {
|
|
|
|
// | --------------- in this `impl` item
|
|
|
|
// LL | type Assoc = bool;
|
|
|
|
// | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
|
|
|
|
if let (
|
|
|
|
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
|
2020-01-18 01:14:29 +01:00
|
|
|
Some(hir::ItemKind::Impl { items, .. }),
|
2019-12-24 23:38:22 +01:00
|
|
|
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
|
2019-10-11 01:20:42 +02:00
|
|
|
{
|
2019-12-24 23:38:22 +01:00
|
|
|
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
|
2020-02-06 23:21:44 +01:00
|
|
|
.iter()
|
2020-02-28 13:36:45 +01:00
|
|
|
.find(|i| i.def_id == *item_def_id)
|
2019-12-24 23:38:22 +01:00
|
|
|
.and_then(|trait_assoc_item| {
|
2020-01-18 01:14:29 +01:00
|
|
|
items
|
2019-12-24 23:38:22 +01:00
|
|
|
.iter()
|
2020-02-28 13:36:45 +01:00
|
|
|
.find(|i| i.ident == trait_assoc_item.ident)
|
2019-12-24 23:38:22 +01:00
|
|
|
.map(|impl_item| (impl_item, trait_assoc_item))
|
|
|
|
})
|
|
|
|
{
|
|
|
|
let bounds = trait_generics
|
|
|
|
.map(|generics| {
|
|
|
|
get_generic_bound_spans(
|
|
|
|
&generics,
|
|
|
|
trait_name,
|
|
|
|
trait_assoc_item.ident,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap_or_else(Vec::new);
|
|
|
|
cause.span = impl_item.span;
|
|
|
|
cause.code = traits::AssocTypeBound(Box::new(AssocTypeBoundData {
|
|
|
|
impl_span: item_span,
|
|
|
|
original: trait_assoc_item.ident.span,
|
|
|
|
bounds,
|
|
|
|
}));
|
|
|
|
}
|
2019-10-11 01:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
2019-12-24 23:38:22 +01:00
|
|
|
_ => {}
|
2019-10-11 01:20:42 +02:00
|
|
|
}
|
2019-12-24 23:38:22 +01:00
|
|
|
};
|
2019-10-22 21:40:46 +02:00
|
|
|
|
2017-08-10 15:52:08 +02:00
|
|
|
if let Elaborate::All = elaborate {
|
2020-02-17 22:09:01 +01:00
|
|
|
// FIXME: Make `extend_cause_with_original_assoc_item_obligation` take an iterator
|
|
|
|
// instead of a slice.
|
|
|
|
let trait_assoc_items: Vec<_> =
|
|
|
|
tcx.associated_items(trait_ref.def_id).in_definition_order().copied().collect();
|
2019-10-22 21:40:46 +02:00
|
|
|
|
2020-01-22 16:30:15 +01:00
|
|
|
let predicates = obligations.iter().map(|obligation| obligation.predicate).collect();
|
2019-10-22 21:40:46 +02:00
|
|
|
let implied_obligations = traits::elaborate_predicates(tcx, predicates);
|
2017-08-10 15:52:08 +02:00
|
|
|
let implied_obligations = implied_obligations.map(|pred| {
|
2019-10-22 21:40:46 +02:00
|
|
|
let mut cause = cause.clone();
|
|
|
|
extend_cause_with_original_assoc_item_obligation(
|
|
|
|
&mut cause,
|
|
|
|
&pred,
|
2020-02-17 22:09:01 +01:00
|
|
|
&*trait_assoc_items,
|
2019-10-22 21:40:46 +02:00
|
|
|
);
|
2019-10-11 01:20:42 +02:00
|
|
|
traits::Obligation::new(cause, param_env, pred)
|
2017-08-10 15:52:08 +02:00
|
|
|
});
|
|
|
|
self.out.extend(implied_obligations);
|
|
|
|
}
|
2017-08-10 15:02:41 +02:00
|
|
|
|
2017-08-10 15:52:08 +02:00
|
|
|
self.out.extend(obligations);
|
2017-08-10 14:41:24 +02:00
|
|
|
|
2019-12-24 23:38:22 +01:00
|
|
|
self.out.extend(trait_ref.substs.types().filter(|ty| !ty.has_escaping_bound_vars()).map(
|
|
|
|
|ty| traits::Obligation::new(cause.clone(), param_env, ty::Predicate::WellFormed(ty)),
|
|
|
|
));
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Pushes the obligations required for `trait_ref::Item` to be WF
|
|
|
|
/// into `self.out`.
|
|
|
|
fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) {
|
|
|
|
// A projection is well-formed if (a) the trait ref itself is
|
2016-05-05 21:11:41 +02:00
|
|
|
// WF and (b) the trait-ref holds. (It may also be
|
2015-08-06 20:27:21 +02:00
|
|
|
// normalizable and be WF that way.)
|
2017-07-11 16:33:09 +02:00
|
|
|
let trait_ref = data.trait_ref(self.infcx.tcx);
|
2017-08-25 03:57:44 +02:00
|
|
|
self.compute_trait_ref(&trait_ref, Elaborate::None);
|
2015-08-06 20:27:21 +02:00
|
|
|
|
2018-10-22 22:38:51 +02:00
|
|
|
if !data.has_escaping_bound_vars() {
|
2020-01-14 05:30:32 +01:00
|
|
|
let predicate = trait_ref.without_const().to_predicate();
|
2015-08-06 20:27:21 +02:00
|
|
|
let cause = self.cause(traits::ProjectionWf(data));
|
2017-05-23 10:19:47 +02:00
|
|
|
self.out.push(traits::Obligation::new(cause, self.param_env, predicate));
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 19:56:59 +01:00
|
|
|
/// Pushes the obligations required for an array length to be WF
|
2017-08-05 15:11:24 +02:00
|
|
|
/// into `self.out`.
|
2019-03-14 10:19:31 +01:00
|
|
|
fn compute_array_len(&mut self, constant: ty::Const<'tcx>) {
|
2019-11-22 21:26:09 +01:00
|
|
|
if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = constant.val {
|
|
|
|
assert!(promoted.is_none());
|
|
|
|
|
2018-06-25 20:53:02 +02:00
|
|
|
let obligations = self.nominal_obligations(def_id, substs);
|
|
|
|
self.out.extend(obligations);
|
|
|
|
|
|
|
|
let predicate = ty::Predicate::ConstEvaluatable(def_id, substs);
|
|
|
|
let cause = self.cause(traits::MiscObligation);
|
2019-12-24 23:38:22 +01:00
|
|
|
self.out.push(traits::Obligation::new(cause, self.param_env, predicate));
|
2017-08-07 07:08:53 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-05 15:11:24 +02:00
|
|
|
|
2016-09-01 12:34:56 +02:00
|
|
|
fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) {
|
2018-10-22 22:38:51 +02:00
|
|
|
if !subty.has_escaping_bound_vars() {
|
2016-04-22 00:46:23 +02:00
|
|
|
let cause = self.cause(cause);
|
2016-11-14 03:42:15 +01:00
|
|
|
let trait_ref = ty::TraitRef {
|
2019-08-27 23:17:58 +02:00
|
|
|
def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None),
|
2016-11-14 03:42:15 +01:00
|
|
|
substs: self.infcx.tcx.mk_substs_trait(subty, &[]),
|
|
|
|
};
|
2020-01-14 05:30:32 +01:00
|
|
|
self.out.push(traits::Obligation::new(
|
|
|
|
cause,
|
|
|
|
self.param_env,
|
|
|
|
trait_ref.without_const().to_predicate(),
|
|
|
|
));
|
2016-04-22 00:46:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Pushes new obligations into `out`. Returns `true` if it was able
|
2015-08-06 20:27:21 +02:00
|
|
|
/// to generate all the predicates needed to validate that `ty0`
|
|
|
|
/// is WF. Returns false if `ty0` is an unresolved type variable,
|
|
|
|
/// in which case we are not able to simplify at all.
|
|
|
|
fn compute(&mut self, ty0: Ty<'tcx>) -> bool {
|
|
|
|
let mut subtys = ty0.walk();
|
2017-05-23 10:19:47 +02:00
|
|
|
let param_env = self.param_env;
|
2015-08-06 20:27:21 +02:00
|
|
|
while let Some(ty) = subtys.next() {
|
2019-09-16 20:08:35 +02:00
|
|
|
match ty.kind {
|
2019-12-24 23:38:22 +01:00
|
|
|
ty::Bool
|
|
|
|
| ty::Char
|
|
|
|
| ty::Int(..)
|
|
|
|
| ty::Uint(..)
|
|
|
|
| ty::Float(..)
|
|
|
|
| ty::Error
|
|
|
|
| ty::Str
|
|
|
|
| ty::GeneratorWitness(..)
|
|
|
|
| ty::Never
|
|
|
|
| ty::Param(_)
|
|
|
|
| ty::Bound(..)
|
|
|
|
| ty::Placeholder(..)
|
|
|
|
| ty::Foreign(..) => {
|
2015-08-06 20:27:21 +02:00
|
|
|
// WfScalar, WfParameter, etc
|
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Slice(subty) => {
|
2017-08-05 15:11:24 +02:00
|
|
|
self.require_sized(subty, traits::SliceOrArrayElem);
|
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Array(subty, len) => {
|
2016-09-01 12:34:56 +02:00
|
|
|
self.require_sized(subty, traits::SliceOrArrayElem);
|
2018-12-11 19:56:59 +01:00
|
|
|
self.compute_array_len(*len);
|
2016-04-22 00:46:23 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Tuple(ref tys) => {
|
2016-04-22 00:46:23 +02:00
|
|
|
if let Some((_last, rest)) = tys.split_last() {
|
|
|
|
for elem in rest {
|
2019-04-26 01:27:33 +02:00
|
|
|
self.require_sized(elem.expect_ty(), traits::TupleElem);
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
2015-12-15 10:31:58 +01:00
|
|
|
}
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::RawPtr(_) => {
|
2015-08-06 20:27:21 +02:00
|
|
|
// simple cases that are WF if their type args are WF
|
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Projection(data) => {
|
2015-08-06 20:27:21 +02:00
|
|
|
subtys.skip_current_subtree(); // subtree handled by compute_projection
|
|
|
|
self.compute_projection(data);
|
|
|
|
}
|
|
|
|
|
2018-10-03 17:06:28 +02:00
|
|
|
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Adt(def, substs) => {
|
2015-08-06 20:27:21 +02:00
|
|
|
// WfNominalType
|
|
|
|
let obligations = self.nominal_obligations(def.did, substs);
|
|
|
|
self.out.extend(obligations);
|
|
|
|
}
|
|
|
|
|
2018-12-18 21:27:22 +01:00
|
|
|
ty::FnDef(did, substs) => {
|
|
|
|
let obligations = self.nominal_obligations(did, substs);
|
|
|
|
self.out.extend(obligations);
|
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Ref(r, rty, _) => {
|
2015-08-06 20:27:21 +02:00
|
|
|
// WfReference
|
2018-10-22 22:38:51 +02:00
|
|
|
if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
|
2015-08-06 20:27:21 +02:00
|
|
|
let cause = self.cause(traits::ReferenceOutlivesReferent(ty));
|
2019-12-24 23:38:22 +01:00
|
|
|
self.out.push(traits::Obligation::new(
|
|
|
|
cause,
|
|
|
|
param_env,
|
|
|
|
ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
|
|
|
|
rty, r,
|
|
|
|
))),
|
|
|
|
));
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Generator(..) => {
|
2017-11-17 17:13:49 +01:00
|
|
|
// Walk ALL the types in the generator: this will
|
|
|
|
// include the upvar types as well as the yield
|
|
|
|
// type. Note that this is mildly distinct from
|
|
|
|
// the closure case, where we have to be careful
|
|
|
|
// about the signature of the closure. We don't
|
|
|
|
// have the problem of implied bounds here since
|
|
|
|
// generators don't take arguments.
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Closure(def_id, substs) => {
|
2017-11-17 17:13:49 +01:00
|
|
|
// Only check the upvar types for WF, not the rest
|
|
|
|
// of the types within. This is needed because we
|
|
|
|
// capture the signature and it may not be WF
|
|
|
|
// without the implied bounds. Consider a closure
|
|
|
|
// like `|x: &'a T|` -- it may be that `T: 'a` is
|
|
|
|
// not known to hold in the creator's context (and
|
|
|
|
// indeed the closure may not be invoked by its
|
|
|
|
// creator, but rather turned to someone who *can*
|
|
|
|
// verify that).
|
|
|
|
//
|
|
|
|
// The special treatment of closures here really
|
|
|
|
// ought not to be necessary either; the problem
|
|
|
|
// is related to #25860 -- there is no way for us
|
|
|
|
// to express a fn type complete with the implied
|
|
|
|
// bounds that it is assuming. I think in reality
|
|
|
|
// the WF rules around fn are a bit messed up, and
|
|
|
|
// that is the rot problem: `fn(&'a T)` should
|
|
|
|
// probably always be WF, because it should be
|
|
|
|
// shorthand for something like `where(T: 'a) {
|
|
|
|
// fn(&'a T) }`, as discussed in #25860.
|
2017-11-20 19:49:18 +01:00
|
|
|
//
|
|
|
|
// Note that we are also skipping the generic
|
|
|
|
// types. This is consistent with the `outlives`
|
|
|
|
// code, but anyway doesn't matter: within the fn
|
|
|
|
// body where they are created, the generics will
|
|
|
|
// always be WF, and outside of that fn body we
|
|
|
|
// are not directly inspecting closure types
|
|
|
|
// anyway, except via auto trait matching (which
|
|
|
|
// only inspects the upvar types).
|
2017-11-08 22:31:47 +01:00
|
|
|
subtys.skip_current_subtree(); // subtree handled by compute_projection
|
2019-09-26 19:30:44 +02:00
|
|
|
for upvar_ty in substs.as_closure().upvar_tys(def_id, self.infcx.tcx) {
|
2017-11-08 22:31:47 +01:00
|
|
|
self.compute(upvar_ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-18 21:27:22 +01:00
|
|
|
ty::FnPtr(_) => {
|
2015-06-13 22:15:03 +02:00
|
|
|
// let the loop iterate into the argument/return
|
2015-12-15 10:31:58 +01:00
|
|
|
// types appearing in the fn signature
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
2018-08-23 21:51:32 +02:00
|
|
|
ty::Opaque(did, substs) => {
|
2016-07-22 17:56:22 +02:00
|
|
|
// all of the requirements on type parameters
|
|
|
|
// should've been checked by the instantiation
|
|
|
|
// of whatever returned this exact `impl Trait`.
|
2018-07-17 13:44:42 +02:00
|
|
|
|
2019-08-01 01:41:54 +02:00
|
|
|
// for named opaque `impl Trait` types we still need to check them
|
2020-01-05 20:52:34 +01:00
|
|
|
if ty::is_impl_trait_defn(self.infcx.tcx, did).is_none() {
|
2018-07-17 13:44:42 +02:00
|
|
|
let obligations = self.nominal_obligations(did, substs);
|
|
|
|
self.out.extend(obligations);
|
|
|
|
}
|
2016-07-22 17:56:22 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Dynamic(data, r) => {
|
2015-08-06 20:27:21 +02:00
|
|
|
// WfObject
|
|
|
|
//
|
|
|
|
// Here, we defer WF checking due to higher-ranked
|
|
|
|
// regions. This is perhaps not ideal.
|
2016-11-16 17:21:49 +01:00
|
|
|
self.from_object_ty(ty, data, r);
|
2015-08-06 20:27:21 +02:00
|
|
|
|
|
|
|
// FIXME(#27579) RFC also considers adding trait
|
|
|
|
// obligations that don't refer to Self and
|
|
|
|
// checking those
|
|
|
|
|
2019-12-24 23:38:22 +01:00
|
|
|
let defer_to_coercion = self.infcx.tcx.features().object_safe_for_dispatch;
|
2019-01-08 22:14:04 +01:00
|
|
|
|
|
|
|
if !defer_to_coercion {
|
|
|
|
let cause = self.cause(traits::MiscObligation);
|
2019-12-24 23:38:22 +01:00
|
|
|
let component_traits = data.auto_traits().chain(data.principal_def_id());
|
|
|
|
self.out.extend(component_traits.map(|did| {
|
|
|
|
traits::Obligation::new(
|
2019-01-08 22:14:04 +01:00
|
|
|
cause.clone(),
|
|
|
|
param_env,
|
2019-12-24 23:38:22 +01:00
|
|
|
ty::Predicate::ObjectSafe(did),
|
|
|
|
)
|
|
|
|
}));
|
2019-01-08 22:14:04 +01:00
|
|
|
}
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inference variables are the complicated case, since we don't
|
|
|
|
// know what type they are. We do two things:
|
|
|
|
//
|
|
|
|
// 1. Check if they have been resolved, and if so proceed with
|
|
|
|
// THAT type.
|
|
|
|
// 2. If not, check whether this is the type that we
|
|
|
|
// started with (ty0). In that case, we've made no
|
|
|
|
// progress at all, so return false. Otherwise,
|
|
|
|
// we've at least simplified things (i.e., we went
|
|
|
|
// from `Vec<$0>: WF` to `$0: WF`, so we can
|
|
|
|
// register a pending obligation and keep
|
|
|
|
// moving. (Goal is that an "inductive hypothesis"
|
|
|
|
// is satisfied to ensure termination.)
|
2018-08-22 02:35:02 +02:00
|
|
|
ty::Infer(_) => {
|
2019-04-30 23:27:33 +02:00
|
|
|
let ty = self.infcx.shallow_resolve(ty);
|
2019-12-24 23:38:22 +01:00
|
|
|
if let ty::Infer(_) = ty.kind {
|
|
|
|
// not yet resolved...
|
|
|
|
if ty == ty0 {
|
|
|
|
// ...this is the type we started from! no progress.
|
2015-08-06 20:27:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let cause = self.cause(traits::MiscObligation);
|
2019-12-24 23:38:22 +01:00
|
|
|
self.out.push(
|
|
|
|
// ...not the type we started from, so we made progress.
|
|
|
|
traits::Obligation::new(
|
|
|
|
cause,
|
|
|
|
self.param_env,
|
|
|
|
ty::Predicate::WellFormed(ty),
|
|
|
|
),
|
|
|
|
);
|
2015-08-06 20:27:21 +02:00
|
|
|
} else {
|
|
|
|
// Yes, resolved, proceed with the
|
|
|
|
// result. Should never return false because
|
2018-08-22 02:35:02 +02:00
|
|
|
// `ty` is not a Infer.
|
2015-08-06 20:27:21 +02:00
|
|
|
assert!(self.compute(ty));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we made it through that loop above, we made progress!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-24 23:38:22 +01:00
|
|
|
fn nominal_obligations(
|
|
|
|
&mut self,
|
|
|
|
def_id: DefId,
|
|
|
|
substs: SubstsRef<'tcx>,
|
|
|
|
) -> Vec<traits::PredicateObligation<'tcx>> {
|
|
|
|
let predicates = self.infcx.tcx.predicates_of(def_id).instantiate(self.infcx.tcx, substs);
|
2015-08-06 20:27:21 +02:00
|
|
|
let cause = self.cause(traits::ItemObligation(def_id));
|
2019-12-24 23:38:22 +01:00
|
|
|
predicates
|
|
|
|
.predicates
|
|
|
|
.into_iter()
|
|
|
|
.map(|pred| traits::Obligation::new(cause.clone(), self.param_env, pred))
|
|
|
|
.filter(|pred| !pred.has_escaping_bound_vars())
|
|
|
|
.collect()
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
|
2019-12-24 23:38:22 +01:00
|
|
|
fn from_object_ty(
|
|
|
|
&mut self,
|
|
|
|
ty: Ty<'tcx>,
|
|
|
|
data: ty::Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>,
|
|
|
|
region: ty::Region<'tcx>,
|
|
|
|
) {
|
2015-08-06 20:27:21 +02:00
|
|
|
// Imagine a type like this:
|
|
|
|
//
|
|
|
|
// trait Foo { }
|
|
|
|
// trait Bar<'c> : 'c { }
|
|
|
|
//
|
|
|
|
// &'b (Foo+'c+Bar<'d>)
|
|
|
|
// ^
|
|
|
|
//
|
|
|
|
// In this case, the following relationships must hold:
|
|
|
|
//
|
|
|
|
// 'b <= 'c
|
|
|
|
// 'd <= 'c
|
|
|
|
//
|
|
|
|
// The first conditions is due to the normal region pointer
|
|
|
|
// rules, which say that a reference cannot outlive its
|
|
|
|
// referent.
|
|
|
|
//
|
|
|
|
// The final condition may be a bit surprising. In particular,
|
|
|
|
// you may expect that it would have been `'c <= 'd`, since
|
|
|
|
// usually lifetimes of outer things are conservative
|
|
|
|
// approximations for inner things. However, it works somewhat
|
|
|
|
// differently with trait objects: here the idea is that if the
|
|
|
|
// user specifies a region bound (`'c`, in this case) it is the
|
|
|
|
// "master bound" that *implies* that bounds from other traits are
|
|
|
|
// all met. (Remember that *all bounds* in a type like
|
|
|
|
// `Foo+Bar+Zed` must be met, not just one, hence if we write
|
|
|
|
// `Foo<'x>+Bar<'y>`, we know that the type outlives *both* 'x and
|
|
|
|
// 'y.)
|
|
|
|
//
|
|
|
|
// Note: in fact we only permit builtin traits, not `Bar<'d>`, I
|
|
|
|
// am looking forward to the future here.
|
2019-03-12 15:57:06 +01:00
|
|
|
if !data.has_escaping_bound_vars() && !region.has_escaping_bound_vars() {
|
2019-12-24 23:38:22 +01:00
|
|
|
let implicit_bounds = object_region_bounds(self.infcx.tcx, data);
|
2015-08-06 20:27:21 +02:00
|
|
|
|
2016-11-16 17:21:49 +01:00
|
|
|
let explicit_bound = region;
|
2015-08-06 20:27:21 +02:00
|
|
|
|
2018-10-02 11:00:41 +02:00
|
|
|
self.out.reserve(implicit_bounds.len());
|
2015-08-06 20:27:21 +02:00
|
|
|
for implicit_bound in implicit_bounds {
|
2016-10-14 16:09:59 +02:00
|
|
|
let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound));
|
2019-12-24 23:38:22 +01:00
|
|
|
let outlives =
|
|
|
|
ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound));
|
|
|
|
self.out.push(traits::Obligation::new(
|
|
|
|
cause,
|
|
|
|
self.param_env,
|
|
|
|
outlives.to_predicate(),
|
|
|
|
));
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Given an object type like `SomeTrait + Send`, computes the lifetime
|
2015-08-06 20:27:21 +02:00
|
|
|
/// bounds that must hold on the elided self type. These are derived
|
|
|
|
/// from the declarations of `SomeTrait`, `Send`, and friends -- if
|
|
|
|
/// they declare `trait SomeTrait : 'static`, for example, then
|
|
|
|
/// `'static` would appear in the list. The hard work is done by
|
2020-01-05 23:28:45 +01:00
|
|
|
/// `infer::required_region_bounds`, see that for more information.
|
2019-06-13 23:48:52 +02:00
|
|
|
pub fn object_region_bounds<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
2019-06-11 23:11:55 +02:00
|
|
|
existential_predicates: ty::Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>,
|
|
|
|
) -> Vec<ty::Region<'tcx>> {
|
2015-08-06 20:27:21 +02:00
|
|
|
// Since we don't actually *know* the self type for an object,
|
|
|
|
// this "open(err)" serves as a kind of dummy standin -- basically
|
2018-09-07 15:46:53 +02:00
|
|
|
// a placeholder type.
|
2019-03-01 05:02:32 +01:00
|
|
|
let open_ty = tcx.mk_ty_infer(ty::FreshTy(0));
|
2015-08-06 20:27:21 +02:00
|
|
|
|
2019-12-24 23:38:22 +01:00
|
|
|
let predicates = existential_predicates
|
|
|
|
.iter()
|
|
|
|
.filter_map(|predicate| {
|
|
|
|
if let ty::ExistentialPredicate::Projection(_) = *predicate.skip_binder() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(predicate.with_self_ty(tcx, open_ty))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
2015-08-06 20:27:21 +02:00
|
|
|
|
2020-01-05 23:28:45 +01:00
|
|
|
required_region_bounds(tcx, open_ty, predicates)
|
2015-08-06 20:27:21 +02:00
|
|
|
}
|
2019-10-31 05:24:08 +01:00
|
|
|
|
|
|
|
/// Find the span of a generic bound affecting an associated type.
|
|
|
|
fn get_generic_bound_spans(
|
2019-11-30 17:46:46 +01:00
|
|
|
generics: &hir::Generics<'_>,
|
2019-10-31 05:24:08 +01:00
|
|
|
trait_name: Option<&Ident>,
|
|
|
|
assoc_item_name: Ident,
|
|
|
|
) -> Vec<Span> {
|
|
|
|
let mut bounds = vec![];
|
|
|
|
for clause in generics.where_clause.predicates.iter() {
|
|
|
|
if let hir::WherePredicate::BoundPredicate(pred) = clause {
|
|
|
|
match &pred.bounded_ty.kind {
|
|
|
|
hir::TyKind::Path(hir::QPath::Resolved(Some(ty), path)) => {
|
|
|
|
let mut s = path.segments.iter();
|
|
|
|
if let (a, Some(b), None) = (s.next(), s.next(), s.next()) {
|
|
|
|
if a.map(|s| &s.ident) == trait_name
|
|
|
|
&& b.ident == assoc_item_name
|
|
|
|
&& is_self_path(&ty.kind)
|
|
|
|
{
|
|
|
|
// `<Self as Foo>::Bar`
|
|
|
|
bounds.push(pred.span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hir::TyKind::Path(hir::QPath::TypeRelative(ty, segment)) => {
|
|
|
|
if segment.ident == assoc_item_name {
|
|
|
|
if is_self_path(&ty.kind) {
|
|
|
|
// `Self::Bar`
|
|
|
|
bounds.push(pred.span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bounds
|
|
|
|
}
|
|
|
|
|
2019-11-30 17:46:46 +01:00
|
|
|
fn is_self_path(kind: &hir::TyKind<'_>) -> bool {
|
2019-10-31 05:24:08 +01:00
|
|
|
match kind {
|
|
|
|
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
|
|
|
|
let mut s = path.segments.iter();
|
|
|
|
if let (Some(segment), None) = (s.next(), s.next()) {
|
|
|
|
if segment.ident.name == kw::SelfUpper {
|
|
|
|
// `type(Self)`
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|