Skip to content

Commit 98d5842

Browse files
authored
Rollup merge of rust-lang#86327 - GuillaumeGomez:safe-intrinsics, r=lqd
Don't mark "safe" intrinsics as unsafe A good example of this is [intrinsics::abort](https://doc.rust-lang.org/nightly/core/intrinsics/fn.abort.html). Before: ![Screenshot from 2021-06-15 14-58-42](https://user-images.githubusercontent.com/3050060/122056942-65ddad00-cdea-11eb-829e-5f5e258387de.png) After: ![Screenshot from 2021-06-15 14-59-22](https://user-images.githubusercontent.com/3050060/122056956-6aa26100-cdea-11eb-94d8-e18b4956cfa4.png) cc ``@jyn514`` r? ``@lqd``
2 parents daee58c + f683040 commit 98d5842

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/librustdoc/clean/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use rustc_mir::const_eval::{is_const_fn, is_unstable_const_fn};
2626
use rustc_span::hygiene::{AstPass, MacroKind};
2727
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2828
use rustc_span::{self, ExpnKind};
29+
use rustc_target::spec::abi::Abi;
30+
use rustc_typeck::check::intrinsic::intrinsic_operation_unsafety;
2931
use rustc_typeck::hir_ty_to_ty;
3032

3133
use std::collections::hash_map::Entry;
@@ -2132,7 +2134,11 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
21322134
decl,
21332135
generics,
21342136
header: hir::FnHeader {
2135-
unsafety: hir::Unsafety::Unsafe,
2137+
unsafety: if abi == Abi::RustIntrinsic {
2138+
intrinsic_operation_unsafety(item.ident.name)
2139+
} else {
2140+
hir::Unsafety::Unsafe
2141+
},
21362142
abi,
21372143
constness: hir::Constness::NotConst,
21382144
asyncness: hir::IsAsync::NotAsync,

src/test/rustdoc/safe-intrinsic.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(intrinsics)]
2+
#![feature(no_core)]
3+
4+
#![no_core]
5+
#![crate_name = "foo"]
6+
7+
extern "rust-intrinsic" {
8+
// @has 'foo/fn.abort.html'
9+
// @has - '//pre[@class="rust fn"]' 'pub extern "rust-intrinsic" fn abort() -> !'
10+
pub fn abort() -> !;
11+
// @has 'foo/fn.unreachable.html'
12+
// @has - '//pre[@class="rust fn"]' 'pub unsafe extern "rust-intrinsic" fn unreachable() -> !'
13+
pub fn unreachable() -> !;
14+
}
15+
16+
extern "C" {
17+
// @has 'foo/fn.needs_drop.html'
18+
// @has - '//pre[@class="rust fn"]' 'pub unsafe extern "C" fn needs_drop() -> !'
19+
pub fn needs_drop() -> !;
20+
}

0 commit comments

Comments
 (0)