Auto merge of #74936 - GuillaumeGomez:const-rustc_const_unstable, r=jyn514
Don't print "const" keyword on non-nightly build if rustc_const_unstable is used on the item Fixes #74579.
This commit is contained in:
commit
1275cc15d6
@ -1083,25 +1083,37 @@ fn clean(&self, _: &DocContext<'_>) -> TypeKind {
|
||||
|
||||
impl Clean<Item> for hir::TraitItem<'_> {
|
||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
|
||||
let inner = match self.kind {
|
||||
hir::TraitItemKind::Const(ref ty, default) => {
|
||||
AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx, e)))
|
||||
}
|
||||
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
|
||||
MethodItem((sig, &self.generics, body, None).clean(cx))
|
||||
let mut m = (sig, &self.generics, body, None).clean(cx);
|
||||
if m.header.constness == hir::Constness::Const
|
||||
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
|
||||
{
|
||||
m.header.constness = hir::Constness::NotConst;
|
||||
}
|
||||
MethodItem(m)
|
||||
}
|
||||
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => {
|
||||
let (generics, decl) = enter_impl_trait(cx, || {
|
||||
(self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx))
|
||||
});
|
||||
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
|
||||
TyMethodItem(TyMethod { header: sig.header, decl, generics, all_types, ret_types })
|
||||
let mut t = TyMethod { header: sig.header, decl, generics, all_types, ret_types };
|
||||
if t.header.constness == hir::Constness::Const
|
||||
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
|
||||
{
|
||||
t.header.constness = hir::Constness::NotConst;
|
||||
}
|
||||
TyMethodItem(t)
|
||||
}
|
||||
hir::TraitItemKind::Type(ref bounds, ref default) => {
|
||||
AssocTypeItem(bounds.clean(cx), default.clean(cx))
|
||||
}
|
||||
};
|
||||
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
|
||||
Item {
|
||||
name: Some(self.ident.name.clean(cx)),
|
||||
attrs: self.attrs.clean(cx),
|
||||
@ -1117,12 +1129,19 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||
|
||||
impl Clean<Item> for hir::ImplItem<'_> {
|
||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
|
||||
let inner = match self.kind {
|
||||
hir::ImplItemKind::Const(ref ty, expr) => {
|
||||
AssocConstItem(ty.clean(cx), Some(print_const_expr(cx, expr)))
|
||||
}
|
||||
hir::ImplItemKind::Fn(ref sig, body) => {
|
||||
MethodItem((sig, &self.generics, body, Some(self.defaultness)).clean(cx))
|
||||
let mut m = (sig, &self.generics, body, Some(self.defaultness)).clean(cx);
|
||||
if m.header.constness == hir::Constness::Const
|
||||
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
|
||||
{
|
||||
m.header.constness = hir::Constness::NotConst;
|
||||
}
|
||||
MethodItem(m)
|
||||
}
|
||||
hir::ImplItemKind::TyAlias(ref ty) => {
|
||||
let type_ = ty.clean(cx);
|
||||
@ -1130,7 +1149,6 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||
TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
|
||||
}
|
||||
};
|
||||
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
|
||||
Item {
|
||||
name: Some(self.ident.name.clean(cx)),
|
||||
source: self.span.clean(cx),
|
||||
|
@ -32,3 +32,12 @@ pub const fn bar2() -> u32 { 42 }
|
||||
|
||||
// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub unsafe fn bar_not_gated() -> u32'
|
||||
pub const unsafe fn bar_not_gated() -> u32 { 42 }
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
impl Foo {
|
||||
// @has 'foo/struct.Foo.html' '//h4[@id="method.gated"]/code' 'pub unsafe fn gated() -> u32'
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature="foo", issue = "none")]
|
||||
pub const unsafe fn gated() -> u32 { 42 }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user