From 09773b4f24841c5ff3b2ba035e3b9772a58f6178 Mon Sep 17 00:00:00 2001 From: binarycat Date: Thu, 24 Oct 2024 19:50:54 -0500 Subject: [PATCH] allow type-based search on foreign functions fixes https://github.com/rust-lang/rust/issues/131804 --- src/librustdoc/html/render/search_index.rs | 5 ++++- tests/rustdoc-js/extern-func.js | 8 ++++++++ tests/rustdoc-js/extern-func.rs | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc-js/extern-func.js create mode 100644 tests/rustdoc-js/extern-func.rs diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index c958458b662..d1939adc1a5 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -759,7 +759,10 @@ pub(crate) fn get_function_type_for_search<'tcx>( } }); let (mut inputs, mut output, where_clause) = match item.kind { - clean::FunctionItem(ref f) | clean::MethodItem(ref f, _) | clean::TyMethodItem(ref f) => { + clean::ForeignFunctionItem(ref f, _) + | clean::FunctionItem(ref f) + | clean::MethodItem(ref f, _) + | clean::TyMethodItem(ref f) => { get_fn_inputs_and_outputs(f, tcx, impl_or_trait_generics, cache) } _ => return None, diff --git a/tests/rustdoc-js/extern-func.js b/tests/rustdoc-js/extern-func.js new file mode 100644 index 00000000000..a3fe2d8ea42 --- /dev/null +++ b/tests/rustdoc-js/extern-func.js @@ -0,0 +1,8 @@ +const EXPECTED = [ + { + 'query': 'c_float -> c_float', + 'others': [ + { 'path': 'extern_func', 'name': 'sqrt' } + ], + }, +]; diff --git a/tests/rustdoc-js/extern-func.rs b/tests/rustdoc-js/extern-func.rs new file mode 100644 index 00000000000..ab1e3e75da7 --- /dev/null +++ b/tests/rustdoc-js/extern-func.rs @@ -0,0 +1,5 @@ +use std::ffi::c_float; + +extern "C" { + pub fn sqrt(x: c_float) -> c_float; +}