]> git.lizzy.rs Git - rust.git/commitdiff
Fix const not displayed in rustdoc
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 16 Mar 2017 01:15:10 +0000 (02:15 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 16 Mar 2017 01:15:10 +0000 (02:15 +0100)
src/librustdoc/clean/mod.rs
src/librustdoc/html/render.rs
src/test/rustdoc/const.rs [new file with mode: 0644]

index 1294296840ebd75b329bd6df6c81e1309883caf3..b51a298c72dd535f2891720d68f611b0bb30ed73 100644 (file)
@@ -1388,7 +1388,7 @@ fn clean(&self, cx: &DocContext) -> Item {
                         decl: decl,
                         abi: sig.abi(),
 
-                        // trait methods canot (currently, at least) be const
+                        // trait methods cannot (currently, at least) be const
                         constness: hir::Constness::NotConst,
                     })
                 } else {
index c571bcb08e4b7fc3c0c3e2d9758c2998c73029fa..8f65c30602c5a73d9753f614f9ee9ac4ea9a2e07 100644 (file)
@@ -60,6 +60,7 @@
 use rustc::middle::stability;
 use rustc::hir;
 use rustc::util::nodemap::{FxHashMap, FxHashSet};
+use rustc::session::config::nightly_options::is_nightly_build;
 use rustc_data_structures::flock;
 
 use clean::{self, AttributesExt, GetDefId, SelfTy, Mutability};
@@ -2316,9 +2317,10 @@ fn method(w: &mut fmt::Formatter,
             }
         };
         // FIXME(#24111): remove when `const_fn` is stabilized
-        let vis_constness = match UnstableFeatures::from_environment() {
-            UnstableFeatures::Allow => constness,
-            _ => hir::Constness::NotConst
+        let vis_constness = if is_nightly_build() {
+            constness
+        } else {
+            hir::Constness::NotConst
         };
         let prefix = format!("{}{}{:#}fn {}{:#}",
                              ConstnessSpace(vis_constness),
diff --git a/src/test/rustdoc/const.rs b/src/test/rustdoc/const.rs
new file mode 100644 (file)
index 0000000..380feb9
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type="lib"]
+
+#![feature(const_fn)]
+
+pub struct Foo;
+
+impl Foo {
+    // @has const/struct.Foo.html '//*[@id="new.v"]//code' 'const unsafe fn new'
+    pub const unsafe fn new() -> Foo {
+        Foo
+    }
+}