]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/clean/mod.rs
introduce PredicateAtom
[rust.git] / src / librustdoc / clean / mod.rs
index 8a4ee91df405fcb8b033ec6911e8916b71154aaf..728453deecff6fa4b77f4126c5cbcaedd78d21a9 100644 (file)
@@ -480,18 +480,18 @@ fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
 
 impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> {
     fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
-        match self.kind() {
-            ty::PredicateKind::Trait(ref pred, _) => Some(pred.clean(cx)),
-            ty::PredicateKind::Subtype(ref pred) => Some(pred.clean(cx)),
-            ty::PredicateKind::RegionOutlives(ref pred) => pred.clean(cx),
-            ty::PredicateKind::TypeOutlives(ref pred) => pred.clean(cx),
-            ty::PredicateKind::Projection(ref pred) => Some(pred.clean(cx)),
+        match self.skip_binders() {
+            ty::PredicateAtom::Trait(pred, _) => Some(ty::Binder::bind(pred).clean(cx)),
+            ty::PredicateAtom::Subtype(pred) => Some(ty::Binder::bind(pred).clean(cx)),
+            ty::PredicateAtom::RegionOutlives(pred) => ty::Binder::bind(pred).clean(cx),
+            ty::PredicateAtom::TypeOutlives(pred) => ty::Binder::bind(pred).clean(cx),
+            ty::PredicateAtom::Projection(pred) => Some(ty::Binder::bind(pred).clean(cx)),
 
-            ty::PredicateKind::WellFormed(..)
-            | ty::PredicateKind::ObjectSafe(..)
-            | ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..) => panic!("not user writable"),
+            ty::PredicateAtom::WellFormed(..)
+            | ty::PredicateAtom::ObjectSafe(..)
+            | ty::PredicateAtom::ClosureKind(..)
+            | ty::PredicateAtom::ConstEvaluatable(..)
+            | ty::PredicateAtom::ConstEquate(..) => panic!("not user writable"),
         }
     }
 }
@@ -754,19 +754,24 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
             .flat_map(|(p, _)| {
                 let mut projection = None;
                 let param_idx = (|| {
-                    if let Some(trait_ref) = p.to_opt_poly_trait_ref() {
-                        if let ty::Param(param) = trait_ref.skip_binder().self_ty().kind {
-                            return Some(param.index);
+                    match p.skip_binders() {
+                        ty::PredicateAtom::Trait(pred, _constness) => {
+                            if let ty::Param(param) = pred.self_ty().kind {
+                                return Some(param.index);
+                            }
                         }
-                    } else if let Some(outlives) = p.to_opt_type_outlives() {
-                        if let ty::Param(param) = outlives.skip_binder().0.kind {
-                            return Some(param.index);
+                        ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
+                            if let ty::Param(param) = ty.kind {
+                                return Some(param.index);
+                            }
                         }
-                    } else if let ty::PredicateKind::Projection(p) = p.kind() {
-                        if let ty::Param(param) = p.skip_binder().projection_ty.self_ty().kind {
-                            projection = Some(p);
-                            return Some(param.index);
+                        ty::PredicateAtom::Projection(p) => {
+                            if let ty::Param(param) = p.projection_ty.self_ty().kind {
+                                projection = Some(ty::Binder::bind(p));
+                                return Some(param.index);
+                            }
                         }
+                        _ => (),
                     }
 
                     None
@@ -1655,16 +1660,19 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
                     .predicates
                     .iter()
                     .filter_map(|predicate| {
-                        let trait_ref = if let Some(tr) = predicate.to_opt_poly_trait_ref() {
-                            tr
-                        } else if let ty::PredicateKind::TypeOutlives(pred) = predicate.kind() {
-                            // these should turn up at the end
-                            if let Some(r) = pred.skip_binder().1.clean(cx) {
-                                regions.push(GenericBound::Outlives(r));
+                        // Note: The substs of opaque types can contain unbound variables,
+                        // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
+                        let trait_ref = match predicate.bound_atom(cx.tcx).skip_binder() {
+                            ty::PredicateAtom::Trait(tr, _constness) => {
+                                ty::Binder::bind(tr.trait_ref)
                             }
-                            return None;
-                        } else {
-                            return None;
+                            ty::PredicateAtom::TypeOutlives(pred) => {
+                                if let Some(r) = pred.1.clean(cx) {
+                                    regions.push(GenericBound::Outlives(r));
+                                }
+                                return None;
+                            }
+                            _ => return None,
                         };
 
                         if let Some(sized) = cx.tcx.lang_items().sized_trait() {
@@ -1678,8 +1686,10 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
                             .predicates
                             .iter()
                             .filter_map(|pred| {
-                                if let ty::PredicateKind::Projection(proj) = pred.kind() {
-                                    let proj = proj.skip_binder();
+                                // We never rebind `proj`, so `skip_binders_unchecked` is safe here.
+                                if let ty::PredicateAtom::Projection(proj) =
+                                    pred.skip_binders_unchecked()
+                                {
                                     if proj.projection_ty.trait_ref(cx.tcx)
                                         == trait_ref.skip_binder()
                                     {
@@ -2353,10 +2363,6 @@ fn clean(&self, _: &DocContext<'_>) -> Stability {
                 attr::Stable { ref since } => since.to_string(),
                 _ => String::new(),
             },
-            deprecation: self.rustc_depr.as_ref().map(|d| Deprecation {
-                note: Some(d.reason.to_string()).filter(|r| !r.is_empty()),
-                since: Some(d.since.to_string()).filter(|d| !d.is_empty()),
-            }),
             unstable_reason: match self.level {
                 attr::Unstable { reason: Some(ref reason), .. } => Some(reason.to_string()),
                 _ => None,
@@ -2374,6 +2380,7 @@ fn clean(&self, _: &DocContext<'_>) -> Deprecation {
         Deprecation {
             since: self.since.map(|s| s.to_string()).filter(|s| !s.is_empty()),
             note: self.note.map(|n| n.to_string()).filter(|n| !n.is_empty()),
+            is_since_rustc_version: self.is_since_rustc_version,
         }
     }
 }