Skip to content

Commit eb7384d

Browse files
Add missing "is_min_const_fn" calls to prevent "const" to be displayed if the "rustc_const_unstable" attribute is present
1 parent 3a92b99 commit eb7384d

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/librustdoc/clean/mod.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -1090,25 +1090,37 @@ impl Clean<TypeKind> for hir::def::DefKind {
10901090

10911091
impl Clean<Item> for hir::TraitItem<'_> {
10921092
fn clean(&self, cx: &DocContext<'_>) -> Item {
1093+
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
10931094
let inner = match self.kind {
10941095
hir::TraitItemKind::Const(ref ty, default) => {
10951096
AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx, e)))
10961097
}
10971098
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1098-
MethodItem((sig, &self.generics, body, None).clean(cx))
1099+
let mut m = (sig, &self.generics, body, None).clean(cx);
1100+
if m.header.constness == hir::Constness::Const
1101+
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
1102+
{
1103+
m.header.constness = hir::Constness::NotConst;
1104+
}
1105+
MethodItem(m)
10991106
}
11001107
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => {
11011108
let (generics, decl) = enter_impl_trait(cx, || {
11021109
(self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx))
11031110
});
11041111
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
1105-
TyMethodItem(TyMethod { header: sig.header, decl, generics, all_types, ret_types })
1112+
let mut t = TyMethod { header: sig.header, decl, generics, all_types, ret_types };
1113+
if t.header.constness == hir::Constness::Const
1114+
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
1115+
{
1116+
t.header.constness = hir::Constness::NotConst;
1117+
}
1118+
TyMethodItem(t)
11061119
}
11071120
hir::TraitItemKind::Type(ref bounds, ref default) => {
11081121
AssocTypeItem(bounds.clean(cx), default.clean(cx))
11091122
}
11101123
};
1111-
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
11121124
Item {
11131125
name: Some(self.ident.name.clean(cx)),
11141126
attrs: self.attrs.clean(cx),
@@ -1124,20 +1136,26 @@ impl Clean<Item> for hir::TraitItem<'_> {
11241136

11251137
impl Clean<Item> for hir::ImplItem<'_> {
11261138
fn clean(&self, cx: &DocContext<'_>) -> Item {
1139+
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
11271140
let inner = match self.kind {
11281141
hir::ImplItemKind::Const(ref ty, expr) => {
11291142
AssocConstItem(ty.clean(cx), Some(print_const_expr(cx, expr)))
11301143
}
11311144
hir::ImplItemKind::Fn(ref sig, body) => {
1132-
MethodItem((sig, &self.generics, body, Some(self.defaultness)).clean(cx))
1145+
let mut m = (sig, &self.generics, body, Some(self.defaultness)).clean(cx);
1146+
if m.header.constness == hir::Constness::Const
1147+
&& !is_min_const_fn(cx.tcx, local_did.to_def_id())
1148+
{
1149+
m.header.constness = hir::Constness::NotConst;
1150+
}
1151+
MethodItem(m)
11331152
}
11341153
hir::ImplItemKind::TyAlias(ref ty) => {
11351154
let type_ = ty.clean(cx);
11361155
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
11371156
TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
11381157
}
11391158
};
1140-
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
11411159
Item {
11421160
name: Some(self.ident.name.clean(cx)),
11431161
source: self.span.clean(cx),

0 commit comments

Comments
 (0)