Skip to content

Commit e9b7069

Browse files
authored
Rollup merge of rust-lang#106751 - clubby789:const-intrinsic, r=GuillaumeGomez
Fix rendering 'const' in header for intrinsics Fixes rust-lang#99398
2 parents c61f29c + 740f6aa commit e9b7069

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/librustdoc/clean/types.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -676,15 +676,23 @@ impl Item {
676676
}
677677
let header = match *self.kind {
678678
ItemKind::ForeignFunctionItem(_) => {
679-
let abi = tcx.fn_sig(self.item_id.as_def_id().unwrap()).abi();
679+
let def_id = self.item_id.as_def_id().unwrap();
680+
let abi = tcx.fn_sig(def_id).abi();
680681
hir::FnHeader {
681682
unsafety: if abi == Abi::RustIntrinsic {
682683
intrinsic_operation_unsafety(tcx, self.item_id.as_def_id().unwrap())
683684
} else {
684685
hir::Unsafety::Unsafe
685686
},
686687
abi,
687-
constness: hir::Constness::NotConst,
688+
constness: if abi == Abi::RustIntrinsic
689+
&& tcx.is_const_fn(def_id)
690+
&& is_unstable_const_fn(tcx, def_id).is_none()
691+
{
692+
hir::Constness::Const
693+
} else {
694+
hir::Constness::NotConst
695+
},
688696
asyncness: hir::IsAsync::NotAsync,
689697
}
690698
}

tests/rustdoc/const-intrinsic.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(intrinsics)]
2+
#![feature(staged_api)]
3+
4+
#![crate_name = "foo"]
5+
#![stable(since="1.0.0", feature="rust1")]
6+
7+
extern "rust-intrinsic" {
8+
// @has 'foo/fn.transmute.html'
9+
// @has - '//pre[@class="rust fn"]' 'pub const unsafe extern "rust-intrinsic" fn transmute<T, U>(_: T) -> U'
10+
#[stable(since="1.0.0", feature="rust1")]
11+
#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
12+
pub fn transmute<T, U>(_: T) -> U;
13+
14+
// @has 'foo/fn.unreachable.html'
15+
// @has - '//pre[@class="rust fn"]' 'pub unsafe extern "rust-intrinsic" fn unreachable() -> !'
16+
#[stable(since="1.0.0", feature="rust1")]
17+
pub fn unreachable() -> !;
18+
}
19+
20+
extern "C" {
21+
// @has 'foo/fn.needs_drop.html'
22+
// @has - '//pre[@class="rust fn"]' 'pub unsafe extern "C" fn needs_drop() -> !'
23+
#[stable(since="1.0.0", feature="rust1")]
24+
pub fn needs_drop() -> !;
25+
}

0 commit comments

Comments
 (0)