Skip to content

Keyword doc #51581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@
var res = buildHrefAndPath(obj);
obj.displayPath = pathSplitter(res[0]);
obj.fullPath = obj.displayPath + obj.name;
if (obj.ty === TY_KEYWORD) {
// To be sure than it isn't considered as duplicate with items.
obj.fullPath += '|k';
}
obj.href = res[1];
out.push(obj);
if (out.length >= MAX_RESULTS) {
Expand Down Expand Up @@ -781,7 +785,7 @@
case "fn":
return (name == "method" || name == "tymethod");
case "type":
return (name == "primitive");
return (name == "primitive" || name == "keyword");
}

// No match
Expand Down
28 changes: 28 additions & 0 deletions src/libstd/keyword_docs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[doc(keyword = "fn")]
//
/// The `fn` keyword.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we ever figure out if we needed the extra // between the regular attribute and the docs, or was that just for spacing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for spacing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. It seems a bit weird to leave it in, but i won't let it hold up the PR.

///
/// The `fn` keyword is used to declare a function.
///
/// Example:
///
/// ```rust
/// fn some_function() {
/// // code goes in here
/// }
/// ```
///
/// For more information about functions, take a look at the [Rust Book][book].
///
/// [book]: https://doc.rust-lang.org/book/second-edition/ch03-03-how-functions-work.html
mod fn_keyword { }
5 changes: 5 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,8 @@ pub use stdsimd::arch;
// the rustdoc documentation for primitive types. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("primitive_docs.rs");

// Include a number of private modules that exist solely to provide
// the rustdoc documentation for the existing keywords. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("keyword_docs.rs");
20 changes: 20 additions & 0 deletions src/test/rustdoc-js/keyword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-order

const QUERY = 'fn';

const EXPECTED = {
'others': [
{ 'path': 'std', 'name': 'fn', ty: 15 }, // 15 is for primitive types
{ 'path': 'std', 'name': 'fn', ty: 21 }, // 21 is for keywords
],
};
19 changes: 19 additions & 0 deletions src/test/rustdoc-js/should-fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// should-fail

const QUERY = 'fn';

const EXPECTED = {
'others': [
{ 'path': 'std', 'name': 'fn', ty: 14 },
],
};
8 changes: 7 additions & 1 deletion src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function loadContent(content) {
m._compile(content, "tmp.js");
m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1;
m.exports.exact_check = content.indexOf("\n// exact-check\n") !== -1;
m.exports.should_fail = content.indexOf("\n// should-fail\n") !== -1;
return m.exports;
}

Expand Down Expand Up @@ -259,6 +260,7 @@ function main(argv) {
const query = loadedFile.QUERY;
const ignore_order = loadedFile.ignore_order;
const exact_check = loadedFile.exact_check;
const should_fail = loadedFile.should_fail;
var results = loaded.execSearch(loaded.getQuery(query), index);
process.stdout.write('Checking "' + file + '" ... ');
var error_text = [];
Expand Down Expand Up @@ -289,7 +291,11 @@ function main(argv) {
}
}
}
if (error_text.length !== 0) {
if (error_text.length === 0 && should_fail === true) {
errors += 1;
console.error("FAILED");
console.error("==> Test was supposed to fail but all items were found...");
} else if (error_text.length !== 0 && should_fail === false) {
errors += 1;
console.error("FAILED");
console.error(error_text.join("\n"));
Expand Down