Skip to content

Commit 01fb32b

Browse files
committed
Auto merge of #51581 - GuillaumeGomez:keyword-doc, r=QuietMisdreavus
Keyword doc Part of #51451. r? @QuietMisdreavus
2 parents 68cee8b + 1fcce48 commit 01fb32b

File tree

6 files changed

+84
-2
lines changed

6 files changed

+84
-2
lines changed

src/librustdoc/html/static/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@
465465
var res = buildHrefAndPath(obj);
466466
obj.displayPath = pathSplitter(res[0]);
467467
obj.fullPath = obj.displayPath + obj.name;
468+
if (obj.ty === TY_KEYWORD) {
469+
// To be sure than it isn't considered as duplicate with items.
470+
obj.fullPath += '|k';
471+
}
468472
obj.href = res[1];
469473
out.push(obj);
470474
if (out.length >= MAX_RESULTS) {
@@ -781,7 +785,7 @@
781785
case "fn":
782786
return (name == "method" || name == "tymethod");
783787
case "type":
784-
return (name == "primitive");
788+
return (name == "primitive" || name == "keyword");
785789
}
786790

787791
// No match

src/libstd/keyword_docs.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[doc(keyword = "fn")]
12+
//
13+
/// The `fn` keyword.
14+
///
15+
/// The `fn` keyword is used to declare a function.
16+
///
17+
/// Example:
18+
///
19+
/// ```rust
20+
/// fn some_function() {
21+
/// // code goes in here
22+
/// }
23+
/// ```
24+
///
25+
/// For more information about functions, take a look at the [Rust Book][book].
26+
///
27+
/// [book]: https://doc.rust-lang.org/book/second-edition/ch03-03-how-functions-work.html
28+
mod fn_keyword { }

src/libstd/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,8 @@ pub use stdsimd::arch;
547547
// the rustdoc documentation for primitive types. Using `include!`
548548
// because rustdoc only looks for these modules at the crate level.
549549
include!("primitive_docs.rs");
550+
551+
// Include a number of private modules that exist solely to provide
552+
// the rustdoc documentation for the existing keywords. Using `include!`
553+
// because rustdoc only looks for these modules at the crate level.
554+
include!("keyword_docs.rs");

src/test/rustdoc-js/keyword.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-order
12+
13+
const QUERY = 'fn';
14+
15+
const EXPECTED = {
16+
'others': [
17+
{ 'path': 'std', 'name': 'fn', ty: 15 }, // 15 is for primitive types
18+
{ 'path': 'std', 'name': 'fn', ty: 21 }, // 21 is for keywords
19+
],
20+
};

src/test/rustdoc-js/should-fail.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// should-fail
12+
13+
const QUERY = 'fn';
14+
15+
const EXPECTED = {
16+
'others': [
17+
{ 'path': 'std', 'name': 'fn', ty: 14 },
18+
],
19+
};

src/tools/rustdoc-js/tester.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function loadContent(content) {
164164
m._compile(content, "tmp.js");
165165
m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1;
166166
m.exports.exact_check = content.indexOf("\n// exact-check\n") !== -1;
167+
m.exports.should_fail = content.indexOf("\n// should-fail\n") !== -1;
167168
return m.exports;
168169
}
169170

@@ -259,6 +260,7 @@ function main(argv) {
259260
const query = loadedFile.QUERY;
260261
const ignore_order = loadedFile.ignore_order;
261262
const exact_check = loadedFile.exact_check;
263+
const should_fail = loadedFile.should_fail;
262264
var results = loaded.execSearch(loaded.getQuery(query), index);
263265
process.stdout.write('Checking "' + file + '" ... ');
264266
var error_text = [];
@@ -289,7 +291,11 @@ function main(argv) {
289291
}
290292
}
291293
}
292-
if (error_text.length !== 0) {
294+
if (error_text.length === 0 && should_fail === true) {
295+
errors += 1;
296+
console.error("FAILED");
297+
console.error("==> Test was supposed to fail but all items were found...");
298+
} else if (error_text.length !== 0 && should_fail === false) {
293299
errors += 1;
294300
console.error("FAILED");
295301
console.error(error_text.join("\n"));

0 commit comments

Comments
 (0)