@@ -9,6 +9,7 @@ use rustc_ast::ast;
99use rustc_attr_data_structures:: { self as attrs, DeprecatedSince } ;
1010use rustc_hir:: def:: CtorKind ;
1111use rustc_hir:: def_id:: DefId ;
12+ use rustc_hir:: { HeaderSafety , Safety } ;
1213use rustc_metadata:: rendered_const;
1314use rustc_middle:: { bug, ty} ;
1415use rustc_span:: { Pos , kw, sym} ;
@@ -383,10 +384,22 @@ impl FromClean<clean::Union> for Union {
383384
384385impl FromClean < rustc_hir:: FnHeader > for FunctionHeader {
385386 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+ } ;
386399 FunctionHeader {
387400 is_async : header. is_async ( ) ,
388401 is_const : header. is_const ( ) ,
389- is_unsafe : header . is_unsafe ( ) ,
402+ is_unsafe,
390403 abi : header. abi . into_json ( renderer) ,
391404 }
392405 }
0 commit comments