@@ -9,6 +9,7 @@ use rustc_ast::ast;
9
9
use rustc_attr_data_structures:: { self as attrs, DeprecatedSince } ;
10
10
use rustc_hir:: def:: CtorKind ;
11
11
use rustc_hir:: def_id:: DefId ;
12
+ use rustc_hir:: { HeaderSafety , Safety } ;
12
13
use rustc_metadata:: rendered_const;
13
14
use rustc_middle:: { bug, ty} ;
14
15
use rustc_span:: { Pos , kw, sym} ;
@@ -383,10 +384,22 @@ impl FromClean<clean::Union> for Union {
383
384
384
385
impl FromClean < rustc_hir:: FnHeader > for FunctionHeader {
385
386
fn from_clean ( header : & rustc_hir:: FnHeader , renderer : & JsonRenderer < ' _ > ) -> Self {
387
+ let is_unsafe = match header. safety {
388
+ HeaderSafety :: SafeTargetFeatures => {
389
+ // The type system's internal implementation details consider
390
+ // safe functions with the `#[target_feature]` attribute to be analogous
391
+ // to unsafe functions: `header.is_unsafe()` returns `true` for them.
392
+ // For rustdoc, this isn't the right decision, so we explicitly return `false`.
393
+ // Context: https://github.com/rust-lang/rust/issues/142655
394
+ false
395
+ }
396
+ HeaderSafety :: Normal ( Safety :: Safe ) => false ,
397
+ HeaderSafety :: Normal ( Safety :: Unsafe ) => true ,
398
+ } ;
386
399
FunctionHeader {
387
400
is_async : header. is_async ( ) ,
388
401
is_const : header. is_const ( ) ,
389
- is_unsafe : header . is_unsafe ( ) ,
402
+ is_unsafe,
390
403
abi : header. abi . into_json ( renderer) ,
391
404
}
392
405
}
0 commit comments