Skip to content

Commit a055c5a

Browse files
committed
Auto merge of rust-lang#76623 - slightlyoutofphase:master, r=jyn514
Use `is_unstable_const_fn` instead of `is_min_const_fn` in rustdoc where appropriate This closes rust-lang#76501. Specifically, it allows for nightly users with the `#![feature(const_fn)]` flag enabled to still have their `const fn` declarations documented as such, while retaining the desired behavior that rustdoc *not* document functions that have the `rustc_const_unstable` attribute as `const`.
2 parents 17d3277 + 8a1288b commit a055c5a

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/librustdoc/clean/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_middle::middle::stability;
2323
use rustc_middle::ty::fold::TypeFolder;
2424
use rustc_middle::ty::subst::InternalSubsts;
2525
use rustc_middle::ty::{self, AdtKind, Lift, Ty, TyCtxt};
26-
use rustc_mir::const_eval::is_min_const_fn;
26+
use rustc_mir::const_eval::{is_const_fn, is_min_const_fn, is_unstable_const_fn};
2727
use rustc_span::hygiene::MacroKind;
2828
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2929
use rustc_span::{self, Pos};
@@ -900,7 +900,9 @@ impl Clean<Item> for doctree::Function<'_> {
900900
enter_impl_trait(cx, || (self.generics.clean(cx), (self.decl, self.body).clean(cx)));
901901

902902
let did = cx.tcx.hir().local_def_id(self.id);
903-
let constness = if is_min_const_fn(cx.tcx, did.to_def_id()) {
903+
let constness = if is_const_fn(cx.tcx, did.to_def_id())
904+
&& !is_unstable_const_fn(cx.tcx, did.to_def_id()).is_some()
905+
{
904906
hir::Constness::Const
905907
} else {
906908
hir::Constness::NotConst
@@ -1108,7 +1110,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
11081110
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
11091111
let mut m = (sig, &self.generics, body, None).clean(cx);
11101112
if m.header.constness == hir::Constness::Const
1111-
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
1113+
&& is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
11121114
{
11131115
m.header.constness = hir::Constness::NotConst;
11141116
}
@@ -1121,7 +1123,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
11211123
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
11221124
let mut t = TyMethod { header: sig.header, decl, generics, all_types, ret_types };
11231125
if t.header.constness == hir::Constness::Const
1124-
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
1126+
&& is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
11251127
{
11261128
t.header.constness = hir::Constness::NotConst;
11271129
}
@@ -1154,7 +1156,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
11541156
hir::ImplItemKind::Fn(ref sig, body) => {
11551157
let mut m = (sig, &self.generics, body, Some(self.defaultness)).clean(cx);
11561158
if m.header.constness == hir::Constness::Const
1157-
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
1159+
&& is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
11581160
{
11591161
m.header.constness = hir::Constness::NotConst;
11601162
}

src/test/rustdoc/const-display.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#[rustc_const_unstable(feature="foo", issue = "none")]
1313
pub const unsafe fn foo() -> u32 { 42 }
1414

15-
// @has 'foo/fn.foo2.html' '//pre' 'pub fn foo2() -> u32'
15+
// @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32'
1616
#[unstable(feature = "humans", issue = "none")]
1717
pub const fn foo2() -> u32 { 42 }
1818

@@ -21,7 +21,7 @@ pub const fn foo2() -> u32 { 42 }
2121
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
2222
pub const fn bar2() -> u32 { 42 }
2323

24-
// @has 'foo/fn.foo2_gated.html' '//pre' 'pub unsafe fn foo2_gated() -> u32'
24+
// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const unsafe fn foo2_gated() -> u32'
2525
#[unstable(feature = "foo2", issue = "none")]
2626
pub const unsafe fn foo2_gated() -> u32 { 42 }
2727

@@ -30,7 +30,7 @@ pub const unsafe fn foo2_gated() -> u32 { 42 }
3030
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
3131
pub const unsafe fn bar2_gated() -> u32 { 42 }
3232

33-
// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub unsafe fn bar_not_gated() -> u32'
33+
// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const unsafe fn bar_not_gated() -> u32'
3434
pub const unsafe fn bar_not_gated() -> u32 { 42 }
3535

3636
pub struct Foo;

src/test/rustdoc/issue-76501.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(const_fn)]
2+
3+
// @has 'issue_76501/fn.bloop.html' '//pre' 'pub const fn bloop() -> i32'
4+
/// A useless function that always returns 1.
5+
pub const fn bloop() -> i32 {
6+
1
7+
}
8+
9+
/// A struct.
10+
pub struct Struct {}
11+
12+
impl Struct {
13+
// @has 'issue_76501/struct.Struct.html' '//*[@class="method"]' 'pub const fn blurp() -> i32'
14+
/// A useless function that always returns 1.
15+
pub const fn blurp() -> i32 {
16+
1
17+
}
18+
}

0 commit comments

Comments
 (0)