From 1dd1f95af835be787231b8609163581c761d974a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 15 Jun 2018 23:23:11 +0200 Subject: [PATCH 1/3] Add doc for fn keyword --- src/libstd/keyword_docs.rs | 28 ++++++++++++++++++++++++++++ src/libstd/lib.rs | 5 +++++ 2 files changed, 33 insertions(+) create mode 100644 src/libstd/keyword_docs.rs diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs new file mode 100644 index 0000000000000..01bd3edaee981 --- /dev/null +++ b/src/libstd/keyword_docs.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[doc(keyword = "fn")] +// +/// The `fn` keyword. +/// +/// 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 { } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 1bdc1dc2b7cfb..a6061e96ae587 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -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"); From e28502edcadbf9ab6102493e8774f1af32df4eb9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 15 Jun 2018 23:23:25 +0200 Subject: [PATCH 2/3] Fix search fn keyword --- src/librustdoc/html/static/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index ed6745cd7f525..bb996e00d352a 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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) { @@ -781,7 +785,7 @@ case "fn": return (name == "method" || name == "tymethod"); case "type": - return (name == "primitive"); + return (name == "primitive" || name == "keyword"); } // No match From 1fcce48451b5d4484d29ddf0641d2228ba78fdbd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 15 Jun 2018 23:39:20 +0200 Subject: [PATCH 3/3] Add rustdoc-js tester should-fail option --- src/test/rustdoc-js/keyword.js | 20 ++++++++++++++++++++ src/test/rustdoc-js/should-fail.js | 19 +++++++++++++++++++ src/tools/rustdoc-js/tester.js | 8 +++++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js/keyword.js create mode 100644 src/test/rustdoc-js/should-fail.js diff --git a/src/test/rustdoc-js/keyword.js b/src/test/rustdoc-js/keyword.js new file mode 100644 index 0000000000000..65de3a4662f29 --- /dev/null +++ b/src/test/rustdoc-js/keyword.js @@ -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 or the MIT license +// , 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 + ], +}; diff --git a/src/test/rustdoc-js/should-fail.js b/src/test/rustdoc-js/should-fail.js new file mode 100644 index 0000000000000..5e41422612adb --- /dev/null +++ b/src/test/rustdoc-js/should-fail.js @@ -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 or the MIT license +// , 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 }, + ], +}; diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index a05c8a8ac9133..3c1fceaf8faa8 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -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; } @@ -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 = []; @@ -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"));