]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/clean/mod.rs
Check basic constness before unstable constness
[rust.git] / src / librustdoc / clean / mod.rs
index 14e0fa7eabb00ab27a3b654e501376403b982aec..405fbf7430599b9c3f2c46f28bc7d3c23359565a 100644 (file)
@@ -23,7 +23,7 @@
 use rustc_middle::ty::fold::TypeFolder;
 use rustc_middle::ty::subst::InternalSubsts;
 use rustc_middle::ty::{self, AdtKind, Lift, Ty, TyCtxt};
-use rustc_mir::const_eval::is_min_const_fn;
+use rustc_mir::const_eval::{is_const_fn, is_min_const_fn, is_unstable_const_fn};
 use rustc_span::hygiene::MacroKind;
 use rustc_span::symbol::{kw, sym, Ident, Symbol};
 use rustc_span::{self, Pos};
@@ -764,17 +764,17 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
                 let param_idx = (|| {
                     match p.skip_binders() {
                         ty::PredicateAtom::Trait(pred, _constness) => {
-                            if let ty::Param(param) = pred.self_ty().kind {
+                            if let ty::Param(param) = pred.self_ty().kind() {
                                 return Some(param.index);
                             }
                         }
                         ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
-                            if let ty::Param(param) = ty.kind {
+                            if let ty::Param(param) = ty.kind() {
                                 return Some(param.index);
                             }
                         }
                         ty::PredicateAtom::Projection(p) => {
-                            if let ty::Param(param) = p.projection_ty.self_ty().kind {
+                            if let ty::Param(param) = p.projection_ty.self_ty().kind() {
                                 projection = Some(ty::Binder::bind(p));
                                 return Some(param.index);
                             }
@@ -900,7 +900,8 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
             enter_impl_trait(cx, || (self.generics.clean(cx), (self.decl, self.body).clean(cx)));
 
         let did = cx.tcx.hir().local_def_id(self.id);
-        let constness = if is_min_const_fn(cx.tcx, did.to_def_id()) {
+        let constness = if is_const_fn(cx.tcx, did.to_def_id())
+            && !is_unstable_const_fn(cx.tcx, did.to_def_id()).is_some() {
             hir::Constness::Const
         } else {
             hir::Constness::NotConst
@@ -1108,7 +1109,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
             hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
                 let mut m = (sig, &self.generics, body, None).clean(cx);
                 if m.header.constness == hir::Constness::Const
-                    && !is_min_const_fn(cx.tcx, local_did.to_def_id())
+                    && is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
                 {
                     m.header.constness = hir::Constness::NotConst;
                 }
@@ -1121,7 +1122,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
                 let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
                 let mut t = TyMethod { header: sig.header, decl, generics, all_types, ret_types };
                 if t.header.constness == hir::Constness::Const
-                    && !is_min_const_fn(cx.tcx, local_did.to_def_id())
+                    && is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
                 {
                     t.header.constness = hir::Constness::NotConst;
                 }
@@ -1154,7 +1155,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
             hir::ImplItemKind::Fn(ref sig, body) => {
                 let mut m = (sig, &self.generics, body, Some(self.defaultness)).clean(cx);
                 if m.header.constness == hir::Constness::Const
-                    && !is_min_const_fn(cx.tcx, local_did.to_def_id())
+                    && is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
                 {
                     m.header.constness = hir::Constness::NotConst;
                 }
@@ -1206,7 +1207,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
                     let self_arg_ty = sig.input(0).skip_binder();
                     if self_arg_ty == self_ty {
                         decl.inputs.values[0].type_ = Generic(String::from("Self"));
-                    } else if let ty::Ref(_, ty, _) = self_arg_ty.kind {
+                    } else if let ty::Ref(_, ty, _) = *self_arg_ty.kind() {
                         if ty == self_ty {
                             match decl.inputs.values[0].type_ {
                                 BorrowedRef { ref mut type_, .. } => {
@@ -1511,7 +1512,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
             TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => {
                 let mut res = Res::Err;
                 let ty = hir_ty_to_ty(cx.tcx, self);
-                if let ty::Projection(proj) = ty.kind {
+                if let ty::Projection(proj) = ty.kind() {
                     res = Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id);
                 }
                 let trait_path = hir::Path { span: self.span, res, segments: &[] };
@@ -1554,7 +1555,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
 impl<'tcx> Clean<Type> for Ty<'tcx> {
     fn clean(&self, cx: &DocContext<'_>) -> Type {
         debug!("cleaning type: {:?}", self);
-        match self.kind {
+        match *self.kind() {
             ty::Never => Never,
             ty::Bool => Primitive(PrimitiveType::Bool),
             ty::Char => Primitive(PrimitiveType::Char),