Skip to content

Commit 09d6ab9

Browse files
committed
Auto merge of #56845 - GuillaumeGomez:const-docs, r=oli-obk
Don't render const keyword on stable Fixes #55246. Continuation of #55327. r? @oli-obk
2 parents 9622f9d + a6943d9 commit 09d6ab9

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait {
207207
fn build_external_function(cx: &DocContext, did: DefId) -> clean::Function {
208208
let sig = cx.tcx.fn_sig(did);
209209

210-
let constness = if cx.tcx.is_const_fn(did) {
210+
let constness = if cx.tcx.is_min_const_fn(did) {
211211
hir::Constness::Const
212212
} else {
213213
hir::Constness::NotConst

src/librustdoc/clean/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1674,18 +1674,24 @@ impl Clean<Item> for doctree::Function {
16741674
(self.generics.clean(cx), (&self.decl, self.body).clean(cx))
16751675
});
16761676

1677+
let did = cx.tcx.hir().local_def_id(self.id);
1678+
let constness = if cx.tcx.is_min_const_fn(did) {
1679+
hir::Constness::Const
1680+
} else {
1681+
hir::Constness::NotConst
1682+
};
16771683
Item {
16781684
name: Some(self.name.clean(cx)),
16791685
attrs: self.attrs.clean(cx),
16801686
source: self.whence.clean(cx),
16811687
visibility: self.vis.clean(cx),
16821688
stability: self.stab.clean(cx),
16831689
deprecation: self.depr.clean(cx),
1684-
def_id: cx.tcx.hir().local_def_id(self.id),
1690+
def_id: did,
16851691
inner: FunctionItem(Function {
16861692
decl,
16871693
generics,
1688-
header: self.header,
1694+
header: hir::FnHeader { constness, ..self.header },
16891695
}),
16901696
}
16911697
}
@@ -2009,7 +2015,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
20092015
ty::TraitContainer(_) => self.defaultness.has_value()
20102016
};
20112017
if provided {
2012-
let constness = if cx.tcx.is_const_fn(self.def_id) {
2018+
let constness = if cx.tcx.is_min_const_fn(self.def_id) {
20132019
hir::Constness::Const
20142020
} else {
20152021
hir::Constness::NotConst

src/test/rustdoc/const-display.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2018 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+
#![crate_name = "foo"]
12+
13+
#![unstable(feature = "humans",
14+
reason = "who ever let humans program computers, we're apparently really bad at it",
15+
issue = "0")]
16+
17+
#![feature(rustc_const_unstable, const_fn, foo, foo2)]
18+
#![feature(min_const_unsafe_fn)]
19+
#![feature(staged_api)]
20+
21+
// @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32'
22+
#[stable(feature = "rust1", since = "1.0.0")]
23+
#[rustc_const_unstable(feature="foo")]
24+
pub const unsafe fn foo() -> u32 { 42 }
25+
26+
// @has 'foo/fn.foo2.html' '//pre' 'pub fn foo2() -> u32'
27+
#[unstable(feature = "humans", issue="0")]
28+
pub const fn foo2() -> u32 { 42 }
29+
30+
// @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32'
31+
#[stable(feature = "rust1", since = "1.0.0")]
32+
pub const fn bar2() -> u32 { 42 }
33+
34+
// @has 'foo/fn.foo2_gated.html' '//pre' 'pub unsafe fn foo2_gated() -> u32'
35+
#[unstable(feature = "foo2", issue="0")]
36+
pub const unsafe fn foo2_gated() -> u32 { 42 }
37+
38+
// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const unsafe fn bar2_gated() -> u32'
39+
#[stable(feature = "rust1", since = "1.0.0")]
40+
pub const unsafe fn bar2_gated() -> u32 { 42 }
41+
42+
// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub unsafe fn bar_not_gated() -> u32'
43+
pub const unsafe fn bar_not_gated() -> u32 { 42 }

0 commit comments

Comments
 (0)