Skip to content

Commit 5a3b393

Browse files
authored
Rollup merge of #146131 - notriddle:rustdoc-search-load-itemtype-test, r=GuillaumeGomez
rustdoc-search: add test case for indexing every item type Test case for #146117
2 parents 3eed9ef + dd8df3b commit 5a3b393

File tree

5 files changed

+168
-1
lines changed

5 files changed

+168
-1
lines changed

src/etc/htmldocck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def get_absolute_path(self, path):
247247
paths = list(Path(self.root).glob(path))
248248
if len(paths) != 1:
249249
raise FailedCheck("glob path does not resolve to one file")
250-
path = str(paths[0])
250+
return str(paths[0])
251251
return os.path.join(self.root, path)
252252

253253
def get_file(self, path):
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![crate_type = "proc-macro"]
2+
3+
extern crate proc_macro;
4+
use proc_macro::*;
5+
6+
//@ has bar/macro.a_procmacro.html
7+
//@ hasraw search.index/name/*.js a_procmacro
8+
#[proc_macro]
9+
pub fn a_procmacro(_: TokenStream) -> TokenStream {
10+
unimplemented!()
11+
}
12+
13+
//@ has bar/attr.a_procattribute.html
14+
//@ hasraw search.index/name/*.js a_procattribute
15+
#[proc_macro_attribute]
16+
pub fn a_procattribute(_: TokenStream, _: TokenStream) -> TokenStream {
17+
unimplemented!()
18+
}
19+
20+
//@ has bar/derive.AProcDerive.html
21+
//@ !has bar/derive.a_procderive.html
22+
//@ hasraw search.index/name/*.js AProcDerive
23+
//@ !hasraw search.index/name/*.js a_procderive
24+
#[proc_macro_derive(AProcDerive)]
25+
pub fn a_procderive(_: TokenStream) -> TokenStream {
26+
unimplemented!()
27+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ has baz/struct.Baz.html
2+
//@ hasraw search.index/name/*.js Baz
3+
pub struct Baz;
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#![feature(extern_types, rustc_attrs, rustdoc_internals, trait_alias)]
2+
#![allow(internal_features)]
3+
#![no_std]
4+
5+
//@ has foo/keyword.while.html
6+
//@ hasraw search.index/name/*.js while
7+
//@ !hasraw search.index/name/*.js w_keyword
8+
#[doc(keyword = "while")]
9+
mod w_keyword {}
10+
11+
//@ has foo/primitive.u32.html
12+
//@ hasraw search.index/name/*.js u32
13+
//@ !hasraw search.index/name/*.js u_primitive
14+
#[rustc_doc_primitive = "u32"]
15+
mod u_primitive {}
16+
17+
//@ has foo/x_mod/index.html
18+
//@ hasraw search.index/name/*.js x_mod
19+
pub mod x_mod {}
20+
21+
//@ hasraw foo/index.html y_crate
22+
//@ hasraw search.index/name/*.js y_crate
23+
#[doc(no_inline)]
24+
pub extern crate core as y_crate;
25+
26+
//@ hasraw foo/index.html z_import
27+
//@ hasraw search.index/name/*.js z_import
28+
#[doc(no_inline)]
29+
pub use core::option as z_import;
30+
31+
//@ has foo/struct.AStruct.html
32+
//@ hasraw search.index/name/*.js AStruct
33+
pub struct AStruct {
34+
//@ hasraw foo/struct.AStruct.html a_structfield
35+
//@ hasraw search.index/name/*.js a_structfield
36+
pub a_structfield: i32,
37+
}
38+
39+
//@ has foo/enum.AEnum.html
40+
//@ hasraw search.index/name/*.js AEnum
41+
pub enum AEnum {
42+
//@ hasraw foo/enum.AEnum.html AVariant
43+
//@ hasraw search.index/name/*.js AVariant
44+
AVariant,
45+
}
46+
47+
//@ has foo/fn.a_fn.html
48+
//@ hasraw search.index/name/*.js a_fn
49+
pub fn a_fn() {}
50+
51+
//@ has foo/type.AType.html
52+
//@ hasraw search.index/name/*.js AType
53+
pub type AType = AStruct;
54+
55+
//@ has foo/static.a_static.html
56+
//@ hasraw search.index/name/*.js a_static
57+
pub static a_static: i32 = 1;
58+
59+
//@ has foo/trait.ATrait.html
60+
//@ hasraw search.index/name/*.js ATrait
61+
pub trait ATrait {
62+
//@ hasraw foo/trait.ATrait.html a_tymethod
63+
//@ hasraw search.index/name/*.js a_tymethod
64+
fn a_tymethod();
65+
//@ hasraw foo/trait.ATrait.html AAssocType
66+
//@ hasraw search.index/name/*.js AAssocType
67+
type AAssocType;
68+
//@ hasraw foo/trait.ATrait.html AAssocConst
69+
//@ hasraw search.index/name/*.js AAssocConst
70+
const AAssocConst: bool;
71+
}
72+
73+
// skip ItemType::Impl, since impls are anonymous
74+
// and have no search entry
75+
76+
impl AStruct {
77+
//@ hasraw foo/struct.AStruct.html a_method
78+
//@ hasraw search.index/name/*.js a_method
79+
pub fn a_method() {}
80+
}
81+
82+
//@ has foo/macro.a_macro.html
83+
//@ hasraw search.index/name/*.js a_macro
84+
#[macro_export]
85+
macro_rules! a_macro {
86+
() => {};
87+
}
88+
89+
//@ has foo/constant.A_CONSTANT.html
90+
//@ hasraw search.index/name/*.js A_CONSTANT
91+
pub const A_CONSTANT: i32 = 1;
92+
93+
//@ has foo/union.AUnion.html
94+
//@ hasraw search.index/name/*.js AUnion
95+
pub union AUnion {
96+
//@ hasraw foo/union.AUnion.html a_unionfield
97+
//@ hasraw search.index/name/*.js a_unionfield
98+
pub a_unionfield: i32,
99+
}
100+
101+
extern "C" {
102+
//@ has foo/foreigntype.AForeignType.html
103+
//@ hasraw search.index/name/*.js AForeignType
104+
pub type AForeignType;
105+
}
106+
107+
// procattribute and procderive are defined in
108+
// bar.rs, because they only work with proc_macro
109+
// crate type.
110+
111+
//@ has foo/traitalias.ATraitAlias.html
112+
//@ hasraw search.index/name/*.js ATraitAlias
113+
pub trait ATraitAlias = ATrait;
114+
115+
//@ has foo/attribute.doc.html
116+
//@ hasraw search.index/name/*.js doc
117+
//@ !hasraw search.index/name/*.js aa_mod
118+
#[doc(attribute = "doc")]
119+
mod aa_mod {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test that rustdoc can deserialize a search index with every itemtype.
2+
// https://github.com/rust-lang/rust/pull/146117
3+
4+
use std::path::Path;
5+
6+
use run_make_support::{htmldocck, rfs, rustdoc, source_root};
7+
8+
fn main() {
9+
let out_dir = Path::new("rustdoc-search-load-itemtype");
10+
11+
rfs::create_dir_all(&out_dir);
12+
rustdoc().out_dir(&out_dir).input("foo.rs").run();
13+
rustdoc().out_dir(&out_dir).input("bar.rs").arg("--crate-type=proc-macro").run();
14+
rustdoc().out_dir(&out_dir).input("baz.rs").run();
15+
htmldocck().arg(out_dir).arg("foo.rs").run();
16+
htmldocck().arg(out_dir).arg("bar.rs").run();
17+
htmldocck().arg(out_dir).arg("baz.rs").run();
18+
}

0 commit comments

Comments
 (0)