Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix const not displayed in rustdoc #40564

Merged
merged 1 commit into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
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 {
Expand Down
8 changes: 5 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use rustc::middle::privacy::AccessLevels;
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};
Expand Down Expand Up @@ -2316,9 +2317,10 @@ fn render_assoc_item(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),
Expand Down
22 changes: 22 additions & 0 deletions src/test/rustdoc/const.rs
Original file line number Diff line number Diff line change
@@ -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
}
}