From 170f068103dca16eb1fe169e67d27c532ec34e50 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 24 Oct 2018 23:34:54 +0200 Subject: [PATCH 1/2] Don't render const keyword on stable --- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/test/rustdoc/const-display.rs | 43 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc/const-display.rs diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 217345548c8..4bd3c6a8455 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -207,7 +207,7 @@ pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait { fn build_external_function(cx: &DocContext, did: DefId) -> clean::Function { let sig = cx.tcx.fn_sig(did); - let constness = if cx.tcx.is_const_fn(did) { + let constness = if cx.tcx.is_min_const_fn(did) { hir::Constness::Const } else { hir::Constness::NotConst diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1e33ec8c376..f08b594a8e4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2009,7 +2009,7 @@ impl<'tcx> Clean for ty::AssociatedItem { ty::TraitContainer(_) => self.defaultness.has_value() }; if provided { - let constness = if cx.tcx.is_const_fn(self.def_id) { + let constness = if cx.tcx.is_min_const_fn(self.def_id) { hir::Constness::Const } else { hir::Constness::NotConst diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs new file mode 100644 index 00000000000..0b727190913 --- /dev/null +++ b/src/test/rustdoc/const-display.rs @@ -0,0 +1,43 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "foo"] + +#![unstable(feature = "humans", + reason = "who ever let humans program computers, we're apparently really bad at it", + issue = "0")] + +#![feature(rustc_const_unstable, const_fn, foo, foo2)] +#![feature(min_const_unsafe_fn)] +#![feature(staged_api)] + +// @has 'foo/fn.foo.html' '//pre' 'pub const unsafe fn foo() -> u32' +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature="foo")] +pub const unsafe fn foo() -> u32 { 42 } + +// @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32' +#[unstable(feature = "humans", issue="0")] +pub const fn foo2() -> u32 { 42 } + +// @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32' +#[stable(feature = "rust1", since = "1.0.0")] +pub const fn bar2() -> u32 { 42 } + +// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const unsafe fn foo2_gated() -> u32' +#[unstable(feature = "foo2", issue="0")] +pub const unsafe fn foo2_gated() -> u32 { 42 } + +// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const unsafe fn bar2_gated() -> u32' +#[stable(feature = "rust1", since = "1.0.0")] +pub const unsafe fn bar2_gated() -> u32 { 42 } + +// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const unsafe fn bar_not_gated() -> u32' +pub const unsafe fn bar_not_gated() -> u32 { 42 } From a6943d9d66d6dc8b7be9db556e28dbc8125f7336 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Dec 2018 22:24:20 +0100 Subject: [PATCH 2/2] Set constness correctly --- src/librustdoc/clean/mod.rs | 10 ++++++++-- src/test/rustdoc/const-display.rs | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f08b594a8e4..44ea3d1ac2d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1674,6 +1674,12 @@ impl Clean for doctree::Function { (self.generics.clean(cx), (&self.decl, self.body).clean(cx)) }); + let did = cx.tcx.hir().local_def_id(self.id); + let constness = if cx.tcx.is_min_const_fn(did) { + hir::Constness::Const + } else { + hir::Constness::NotConst + }; Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -1681,11 +1687,11 @@ impl Clean for doctree::Function { visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), - def_id: cx.tcx.hir().local_def_id(self.id), + def_id: did, inner: FunctionItem(Function { decl, generics, - header: self.header, + header: hir::FnHeader { constness, ..self.header }, }), } } diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index 0b727190913..8ac0d07ceef 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -18,12 +18,12 @@ #![feature(min_const_unsafe_fn)] #![feature(staged_api)] -// @has 'foo/fn.foo.html' '//pre' 'pub const unsafe fn foo() -> u32' +// @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature="foo")] pub const unsafe fn foo() -> u32 { 42 } -// @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32' +// @has 'foo/fn.foo2.html' '//pre' 'pub fn foo2() -> u32' #[unstable(feature = "humans", issue="0")] pub const fn foo2() -> u32 { 42 } @@ -31,7 +31,7 @@ pub const fn foo2() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] pub const fn bar2() -> u32 { 42 } -// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const unsafe fn foo2_gated() -> u32' +// @has 'foo/fn.foo2_gated.html' '//pre' 'pub unsafe fn foo2_gated() -> u32' #[unstable(feature = "foo2", issue="0")] pub const unsafe fn foo2_gated() -> u32 { 42 } @@ -39,5 +39,5 @@ pub const unsafe fn foo2_gated() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] pub const unsafe fn bar2_gated() -> u32 { 42 } -// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const unsafe fn bar_not_gated() -> u32' +// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub unsafe fn bar_not_gated() -> u32' pub const unsafe fn bar_not_gated() -> u32 { 42 }