Skip to content

Commit 742ff5a

Browse files
Fix rendering of const keyword for functions
1 parent efa3ec6 commit 742ff5a

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

src/librustdoc/html/render.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ use externalfiles::ExternalHtml;
5454

5555
use serialize::json::{ToJson, Json, as_json};
5656
use syntax::{abi, ast};
57-
use syntax::feature_gate::UnstableFeatures;
5857
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId};
5958
use rustc::middle::privacy::AccessLevels;
6059
use rustc::middle::stability;
6160
use rustc::hir;
6261
use rustc::util::nodemap::{FxHashMap, FxHashSet};
63-
use rustc::session::config::nightly_options::is_nightly_build;
6462
use rustc_data_structures::flock;
6563

6664
use clean::{self, AttributesExt, GetDefId, SelfTy, Mutability, Span};
@@ -2192,14 +2190,9 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21922190

21932191
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21942192
f: &clean::Function) -> fmt::Result {
2195-
// FIXME(#24111): remove when `const_fn` is stabilized
2196-
let vis_constness = match UnstableFeatures::from_environment() {
2197-
UnstableFeatures::Allow => f.constness,
2198-
_ => hir::Constness::NotConst
2199-
};
22002193
let name_len = format!("{}{}{}{:#}fn {}{:#}",
22012194
VisSpace(&it.visibility),
2202-
ConstnessSpace(vis_constness),
2195+
ConstnessSpace(f.constness),
22032196
UnsafetySpace(f.unsafety),
22042197
AbiSpace(f.abi),
22052198
it.name.as_ref().unwrap(),
@@ -2209,7 +2202,7 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22092202
write!(w, "{vis}{constness}{unsafety}{abi}fn \
22102203
{name}{generics}{decl}{where_clause}</pre>",
22112204
vis = VisSpace(&it.visibility),
2212-
constness = ConstnessSpace(vis_constness),
2205+
constness = ConstnessSpace(f.constness),
22132206
unsafety = UnsafetySpace(f.unsafety),
22142207
abi = AbiSpace(f.abi),
22152208
name = it.name.as_ref().unwrap(),
@@ -2591,14 +2584,8 @@ fn render_assoc_item(w: &mut fmt::Formatter,
25912584
href(did).map(|p| format!("{}#{}.{}", p.0, ty, name)).unwrap_or(anchor)
25922585
}
25932586
};
2594-
// FIXME(#24111): remove when `const_fn` is stabilized
2595-
let vis_constness = if is_nightly_build() {
2596-
constness
2597-
} else {
2598-
hir::Constness::NotConst
2599-
};
26002587
let mut head_len = format!("{}{}{:#}fn {}{:#}",
2601-
ConstnessSpace(vis_constness),
2588+
ConstnessSpace(constness),
26022589
UnsafetySpace(unsafety),
26032590
AbiSpace(abi),
26042591
name,
@@ -2611,7 +2598,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
26112598
};
26122599
write!(w, "{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
26132600
{generics}{decl}{where_clause}",
2614-
ConstnessSpace(vis_constness),
2601+
ConstnessSpace(constness),
26152602
UnsafetySpace(unsafety),
26162603
AbiSpace(abi),
26172604
href = href,

src/test/rustdoc/const-fn.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(const_fn)]
12+
#![crate_name = "foo"]
13+
14+
// @has foo/fn.bar.html
15+
// @has - '//*[@class="rust fn"]' 'pub const fn bar() -> '
16+
/// foo
17+
pub const fn bar() -> usize {
18+
2
19+
}
20+
21+
// @has foo/struct.Foo.html
22+
// @has - '//*[@class="method"]' 'const fn new()'
23+
pub struct Foo(usize);
24+
25+
impl Foo {
26+
pub const fn new() -> Foo { Foo(0) }
27+
}

0 commit comments

Comments
 (0)