diff --git a/src/librustdoc/html/static/js/externs.js b/src/librustdoc/html/static/js/externs.js
index 8cebce7ae86..6fd60d6cc34 100644
--- a/src/librustdoc/html/static/js/externs.js
+++ b/src/librustdoc/html/static/js/externs.js
@@ -41,8 +41,9 @@ let ParserState;
* foundElems: number,
* totalElems: number,
* literalSearch: boolean,
- * corrections: Array<{from: string, to: integer}>,
+ * corrections: Array<{from: string, to: integer}> | null,
* typeFingerprint: Uint32Array,
+ * error: Array | null,
* }}
*/
let ParsedQuery;
diff --git a/tests/rustdoc-js/basic.js b/tests/rustdoc-js/basic.js
index e186d510887..c38b8435c2d 100644
--- a/tests/rustdoc-js/basic.js
+++ b/tests/rustdoc-js/basic.js
@@ -1,6 +1,6 @@
const EXPECTED = {
'query': 'Fo',
'others': [
- { 'path': 'basic', 'name': 'Foo' },
+ { 'path': 'basic', 'name': 'Foo', 'desc': 'Docs for Foo' },
],
};
diff --git a/tests/rustdoc-js/doc-alias.js b/tests/rustdoc-js/doc-alias.js
index 7e4e8a776d8..e57bd71419d 100644
--- a/tests/rustdoc-js/doc-alias.js
+++ b/tests/rustdoc-js/doc-alias.js
@@ -5,6 +5,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Struct',
+ 'desc': 'Doc for Struct
',
'alias': 'StructItem',
'href': '../doc_alias/struct.Struct.html',
'is_alias': true
@@ -17,6 +18,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Struct',
'name': 'field',
+ 'desc': 'Doc for Struct
’s field
',
'alias': 'StructFieldItem',
'href': '../doc_alias/struct.Struct.html#structfield.field',
'is_alias': true
@@ -29,6 +31,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Struct',
'name': 'method',
+ 'desc': 'Doc for Struct::method
',
'alias': 'StructMethodItem',
'href': '../doc_alias/struct.Struct.html#method.method',
'is_alias': true
@@ -45,6 +48,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Struct',
'name': 'ImplConstItem',
+ 'desc': 'Doc for Struct::ImplConstItem
',
'alias': 'StructImplConstItem',
'href': '../doc_alias/struct.Struct.html#associatedconstant.ImplConstItem',
'is_alias': true
@@ -57,6 +61,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Struct',
'name': 'function',
+ 'desc': 'Doc for Trait::function
implemented for Struct',
'alias': 'ImplTraitFunction',
'href': '../doc_alias/struct.Struct.html#method.function',
'is_alias': true
@@ -69,6 +74,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Enum',
+ 'desc': 'Doc for Enum
',
'alias': 'EnumItem',
'href': '../doc_alias/enum.Enum.html',
'is_alias': true
@@ -81,6 +87,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Enum',
'name': 'Variant',
+ 'desc': 'Doc for Enum::Variant
',
'alias': 'VariantItem',
'href': '../doc_alias/enum.Enum.html#variant.Variant',
'is_alias': true
@@ -93,6 +100,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Enum',
'name': 'method',
+ 'desc': 'Doc for Enum::method
',
'alias': 'EnumMethodItem',
'href': '../doc_alias/enum.Enum.html#method.method',
'is_alias': true
@@ -105,6 +113,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Typedef',
+ 'desc': 'Doc for type alias Typedef
',
'alias': 'TypedefItem',
'href': '../doc_alias/type.Typedef.html',
'is_alias': true
@@ -117,6 +126,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Trait',
+ 'desc': 'Doc for Trait
',
'alias': 'TraitItem',
'href': '../doc_alias/trait.Trait.html',
'is_alias': true
@@ -129,6 +139,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Trait',
'name': 'Target',
+ 'desc': 'Doc for Trait::Target
',
'alias': 'TraitTypeItem',
'href': '../doc_alias/trait.Trait.html#associatedtype.Target',
'is_alias': true
@@ -141,6 +152,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Trait',
'name': 'AssociatedConst',
+ 'desc': 'Doc for Trait::AssociatedConst
',
'alias': 'AssociatedConstItem',
'href': '../doc_alias/trait.Trait.html#associatedconstant.AssociatedConst',
'is_alias': true
@@ -153,6 +165,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Trait',
'name': 'function',
+ 'desc': 'Doc for Trait::function
',
'alias': 'TraitFunctionItem',
'href': '../doc_alias/trait.Trait.html#tymethod.function',
'is_alias': true
@@ -165,6 +178,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'function',
+ 'desc': 'Doc for function
',
'alias': 'FunctionItem',
'href': '../doc_alias/fn.function.html',
'is_alias': true
@@ -177,6 +191,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Module',
+ 'desc': 'Doc for Module
',
'alias': 'ModuleItem',
'href': '../doc_alias/Module/index.html',
'is_alias': true
@@ -189,6 +204,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Const',
+ 'desc': 'Doc for Const
',
'alias': 'ConstItem',
'href': '../doc_alias/constant.Const.html',
'is_alias': true
@@ -205,6 +221,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Static',
+ 'desc': 'Doc for Static
',
'alias': 'StaticItem',
'href': '../doc_alias/static.Static.html',
'is_alias': true
@@ -217,6 +234,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Union',
+ 'desc': 'Doc for Union
',
'alias': 'UnionItem',
'href': '../doc_alias/union.Union.html',
'is_alias': true
@@ -225,6 +243,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Union',
'name': 'union_item',
+ 'desc': 'Doc for Union::union_item
',
'href': '../doc_alias/union.Union.html#structfield.union_item'
},
],
@@ -235,6 +254,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Union',
'name': 'union_item',
+ 'desc': 'Doc for Union::union_item
',
'alias': 'UnionFieldItem',
'href': '../doc_alias/union.Union.html#structfield.union_item',
'is_alias': true
@@ -247,6 +267,7 @@ const EXPECTED = [
{
'path': 'doc_alias::Union',
'name': 'method',
+ 'desc': 'Doc for Union::method
',
'alias': 'UnionMethodItem',
'href': '../doc_alias/union.Union.html#method.method',
'is_alias': true
@@ -259,6 +280,7 @@ const EXPECTED = [
{
'path': 'doc_alias',
'name': 'Macro',
+ 'desc': 'Doc for Macro
',
'alias': 'MacroItem',
'href': '../doc_alias/macro.Macro.html',
'is_alias': true
diff --git a/tests/rustdoc-js/doc-alias.rs b/tests/rustdoc-js/doc-alias.rs
index 453b55c956c..bf075385327 100644
--- a/tests/rustdoc-js/doc-alias.rs
+++ b/tests/rustdoc-js/doc-alias.rs
@@ -1,12 +1,16 @@
+/// Doc for `Struct`
#[doc(alias = "StructItem")]
pub struct Struct {
+ /// Doc for `Struct`'s `field`
#[doc(alias = "StructFieldItem")]
pub field: u32,
}
impl Struct {
+ /// Doc for `Struct::ImplConstItem`
#[doc(alias = "StructImplConstItem")]
pub const ImplConstItem: i32 = 0;
+ /// Doc for `Struct::method`
#[doc(alias = "StructMethodItem")]
pub fn method(&self) {}
}
@@ -15,61 +19,78 @@ impl Trait for Struct {
type Target = u32;
const AssociatedConst: i32 = 12;
+ /// Doc for `Trait::function` implemented for Struct
#[doc(alias = "ImplTraitFunction")]
fn function() -> Self::Target {
0
}
}
+/// Doc for `Enum`
#[doc(alias = "EnumItem")]
pub enum Enum {
+ /// Doc for `Enum::Variant`
#[doc(alias = "VariantItem")]
Variant,
}
impl Enum {
+ /// Doc for `Enum::method`
#[doc(alias = "EnumMethodItem")]
pub fn method(&self) {}
}
+/// Doc for type alias `Typedef`
#[doc(alias = "TypedefItem")]
pub type Typedef = i32;
+/// Doc for `Trait`
#[doc(alias = "TraitItem")]
pub trait Trait {
+ /// Doc for `Trait::Target`
#[doc(alias = "TraitTypeItem")]
type Target;
+ /// Doc for `Trait::AssociatedConst`
#[doc(alias = "AssociatedConstItem")]
const AssociatedConst: i32;
+ /// Doc for `Trait::function`
#[doc(alias = "TraitFunctionItem")]
fn function() -> Self::Target;
}
+/// Doc for `function`
#[doc(alias = "FunctionItem")]
pub fn function() {}
+/// Doc for `Module`
#[doc(alias = "ModuleItem")]
pub mod Module {}
+/// Doc for `Const`
#[doc(alias = "ConstItem")]
pub const Const: u32 = 0;
+/// Doc for `Static`
#[doc(alias = "StaticItem")]
pub static Static: u32 = 0;
+/// Doc for `Union`
#[doc(alias = "UnionItem")]
pub union Union {
+ /// Doc for `Union::union_item`
#[doc(alias = "UnionFieldItem")]
pub union_item: u32,
pub y: f32,
}
impl Union {
+ /// Doc for `Union::method`
#[doc(alias = "UnionMethodItem")]
pub fn method(&self) {}
}
+/// Doc for `Macro`
#[doc(alias = "MacroItem")]
#[macro_export]
macro_rules! Macro {
diff --git a/tests/rustdoc-js/non-english-identifier.js b/tests/rustdoc-js/non-english-identifier.js
new file mode 100644
index 00000000000..59c6a3a7f99
--- /dev/null
+++ b/tests/rustdoc-js/non-english-identifier.js
@@ -0,0 +1,163 @@
+const PARSED = [
+ {
+ query: '中文',
+ elems: [{
+ name: "中文",
+ fullPath: ["中文"],
+ pathWithoutLast: [],
+ pathLast: "中文",
+ generics: [],
+ typeFilter: -1,
+ }],
+ returned: [],
+ foundElems: 1,
+ original: "中文",
+ userQuery: "中文",
+ error: null,
+ },
+ {
+ query: '_0Mixed中英文',
+ elems: [{
+ name: "_0mixed中英文",
+ fullPath: ["_0mixed中英文"],
+ pathWithoutLast: [],
+ pathLast: "_0mixed中英文",
+ generics: [],
+ typeFilter: -1,
+ }],
+ foundElems: 1,
+ original: "_0Mixed中英文",
+ returned: [],
+ userQuery: "_0mixed中英文",
+ error: null,
+ },
+ {
+ query: 'my_crate::中文API',
+ elems: [{
+ name: "my_crate::中文api",
+ fullPath: ["my_crate", "中文api"],
+ pathWithoutLast: ["my_crate"],
+ pathLast: "中文api",
+ generics: [],
+ typeFilter: -1,
+ }],
+ foundElems: 1,
+ original: "my_crate::中文API",
+ returned: [],
+ userQuery: "my_crate::中文api",
+ error: null,
+ },
+ {
+ query: '类型A,类型B<约束C>->返回类型<关联类型=路径::约束D>',
+ elems: [{
+ name: "类型a",
+ fullPath: ["类型a"],
+ pathWithoutLast: [],
+ pathLast: "类型a",
+ generics: [],
+ }, {
+ name: "类型b",
+ fullPath: ["类型b"],
+ pathWithoutLast: [],
+ pathLast: "类型b",
+ generics: [{
+ name: "约束c",
+ fullPath: ["约束c"],
+ pathWithoutLast: [],
+ pathLast: "约束c",
+ generics: [],
+ }],
+ }],
+ foundElems: 3,
+ totalElems: 5,
+ literalSearch: true,
+ original: "类型A,类型B<约束C>->返回类型<关联类型=路径::约束D>",
+ returned: [{
+ name: "返回类型",
+ fullPath: ["返回类型"],
+ pathWithoutLast: [],
+ pathLast: "返回类型",
+ generics: [],
+ }],
+ userQuery: "类型a,类型b<约束c>->返回类型<关联类型=路径::约束d>",
+ error: null,
+ },
+ {
+ query: 'my_crate 中文宏!',
+ elems: [{
+ name: "my_crate 中文宏",
+ fullPath: ["my_crate", "中文宏"],
+ pathWithoutLast: ["my_crate"],
+ pathLast: "中文宏",
+ generics: [],
+ typeFilter: 16,
+ }],
+ foundElems: 1,
+ original: "my_crate 中文宏!",
+ returned: [],
+ userQuery: "my_crate 中文宏!",
+ error: null,
+ },
+ {
+ query: '非法符号——',
+ elems: [],
+ foundElems: 0,
+ original: "非法符号——",
+ returned: [],
+ userQuery: "非法符号——",
+ error: "Unexpected `—` after `号`",
+ }
+]
+const EXPECTED = [
+ {
+ query: '加法',
+ others: [
+ {
+ name: "add",
+ path: "non_english_identifier",
+ is_alias: true,
+ alias: "加法",
+ href: "../non_english_identifier/macro.add.html"
+ },
+ {
+ name: "add",
+ path: "non_english_identifier",
+ is_alias: true,
+ alias: "加法",
+ href: "../non_english_identifier/fn.add.html"
+ },
+ {
+ name: "加法",
+ path: "non_english_identifier",
+ href: "../non_english_identifier/trait.加法.html",
+ desc: "Add"
+ },
+ {
+ name: "中文名称的加法宏",
+ path: "non_english_identifier",
+ href: "../non_english_identifier/macro.中文名称的加法宏.html",
+ },
+ {
+ name: "中文名称的加法API",
+ path: "non_english_identifier",
+ href: "../non_english_identifier/fn.中文名称的加法API.html",
+ }],
+ in_args: [{
+ name: "加上",
+ path: "non_english_identifier::加法",
+ href: "../non_english_identifier/trait.加法.html#tymethod.加上",
+ }],
+ returned: [],
+ },
+ { // Extensive type-based search is still buggy, experimental & work-in-progress.
+ query: '可迭代->可选',
+ others: [{
+ name: "总计",
+ path: "non_english_identifier",
+ href: "../non_english_identifier/fn.总计.html",
+ desc: "“sum”"
+ }],
+ in_args: [],
+ returned: [],
+ },
+];
\ No newline at end of file
diff --git a/tests/rustdoc-js/non-english-identifier.rs b/tests/rustdoc-js/non-english-identifier.rs
new file mode 100644
index 00000000000..70b5141472c
--- /dev/null
+++ b/tests/rustdoc-js/non-english-identifier.rs
@@ -0,0 +1,47 @@
+#[doc(alias = "加法")]
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+pub fn 中文名称的加法API(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[macro_export]
+macro_rules! 中文名称的加法宏 {
+ ($left:expr, $right:expr) => {
+ ($left) + ($right)
+ };
+}
+
+#[doc(alias = "加法")]
+#[macro_export]
+macro_rules! add {
+ ($left:expr, $right:expr) => {
+ ($left) + ($right)
+ };
+}
+
+/// Add
+pub trait 加法<类型> {
+ type 结果;
+ fn 加上(self, 被加数: 类型) -> Self::结果;
+}
+
+/// IntoIterator
+pub trait 可迭代 {
+ type 项;
+ type 转为迭代器: Iterator- ;
+ fn 迭代(self) -> Self::转为迭代器;
+}
+
+pub type 可选<类型> = Option<类型>;
+
+/// "sum"
+pub fn 总计<集合, 个体>(容器: 集合) -> 可选<集合::项>
+where
+ 集合: 可迭代<项 = 个体>,
+ 个体: 加法<个体, 结果 = 个体>,
+{
+ 容器.迭代().reduce(|累计值, 当前值| 累计值.加上(当前值))
+}