1
Fork 0

Auto merge of #50033 - GuillaumeGomez:rollup, r=GuillaumeGomez

Rollup of 4 pull requests

Successful merges:

 - #49699 (Removed 'proc' from the reserved keywords list)
 - #49966 (Multiple query search)
 - #50013 (Remove no longer necessary comparison to Vec::splice.)
 - #50032 (rustdoc: Don't include private paths in all.html)

Failed merges:
This commit is contained in:
bors 2018-04-17 16:51:55 +00:00
commit 9379bcdd0b
8 changed files with 219 additions and 160 deletions

View file

@ -1521,9 +1521,6 @@ impl String {
/// and replaces it with the given string. /// and replaces it with the given string.
/// The given string doesn't need to be the same length as the range. /// The given string doesn't need to be the same length as the range.
/// ///
/// Note: Unlike [`Vec::splice`], the replacement happens eagerly, and this
/// method does not return the removed chars.
///
/// # Panics /// # Panics
/// ///
/// Panics if the starting point or end point do not lie on a [`char`] /// Panics if the starting point or end point do not lie on a [`char`]

View file

@ -37,128 +37,116 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
-> io::Result<()> -> io::Result<()>
{ {
write!(dst, write!(dst,
r##"<!DOCTYPE html> "<!DOCTYPE html>\
<html lang="en"> <html lang=\"en\">\
<head> <head>\
<meta charset="utf-8"> <meta charset=\"utf-8\">\
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
<meta name="generator" content="rustdoc"> <meta name=\"generator\" content=\"rustdoc\">\
<meta name="description" content="{description}"> <meta name=\"description\" content=\"{description}\">\
<meta name="keywords" content="{keywords}"> <meta name=\"keywords\" content=\"{keywords}\">\
<title>{title}</title>\
<title>{title}</title> <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}normalize{suffix}.css\">\
<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}rustdoc{suffix}.css\" \
<link rel="stylesheet" type="text/css" href="{root_path}normalize{suffix}.css"> id=\"mainThemeStyle\">\
<link rel="stylesheet" type="text/css" href="{root_path}rustdoc{suffix}.css" {themes}\
id="mainThemeStyle"> <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}dark{suffix}.css\">\
{themes} <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}light{suffix}.css\" \
<link rel="stylesheet" type="text/css" href="{root_path}dark{suffix}.css"> id=\"themeStyle\">\
<link rel="stylesheet" type="text/css" href="{root_path}light{suffix}.css" id="themeStyle"> <script src=\"{root_path}storage{suffix}.js\"></script>\
<script src="{root_path}storage{suffix}.js"></script> {css_extension}\
{css_extension} {favicon}\
{in_header}\
{favicon} </head>\
{in_header} <body class=\"rustdoc {css_class}\">\
</head> <!--[if lte IE 8]>\
<body class="rustdoc {css_class}"> <div class=\"warning\">\
<!--[if lte IE 8]> This old browser is unsupported and will most likely display funky \
<div class="warning"> things.\
This old browser is unsupported and will most likely display funky </div>\
things. <![endif]-->\
</div> {before_content}\
<![endif]--> <nav class=\"sidebar\">\
<div class=\"sidebar-menu\">&#9776;</div>\
{before_content} {logo}\
{sidebar}\
<nav class="sidebar"> </nav>\
<div class="sidebar-menu">&#9776;</div> <div class=\"theme-picker\">\
{logo} <button id=\"theme-picker\" aria-label=\"Pick another theme!\">\
{sidebar} <img src=\"{root_path}brush{suffix}.svg\" width=\"18\" alt=\"Pick another theme!\">\
</nav> </button>\
<div id=\"theme-choices\"></div>\
<div class="theme-picker"> </div>\
<button id="theme-picker" aria-label="Pick another theme!"> <script src=\"{root_path}theme{suffix}.js\"></script>\
<img src="{root_path}brush{suffix}.svg" width="18" alt="Pick another theme!"> <nav class=\"sub\">\
</button> <form class=\"search-form js-only\">\
<div id="theme-choices"></div> <div class=\"search-container\">\
</div> <input class=\"search-input\" name=\"search\" \
<script src="{root_path}theme{suffix}.js"></script> autocomplete=\"off\" \
<nav class="sub"> placeholder=\"Click or press S to search, ? for more options…\" \
<form class="search-form js-only"> type=\"search\">\
<div class="search-container"> </div>\
<input class="search-input" name="search" </form>\
autocomplete="off" </nav>\
placeholder="Click or press S to search, ? for more options…" <section id=\"main\" class=\"content\">{content}</section>\
type="search"> <section id=\"search\" class=\"content hidden\"></section>\
</div> <section class=\"footer\"></section>\
</form> <aside id=\"help\" class=\"hidden\">\
</nav> <div>\
<h1 class=\"hidden\">Help</h1>\
<section id='main' class="content">{content}</section> <div class=\"shortcuts\">\
<section id='search' class="content hidden"></section> <h2>Keyboard Shortcuts</h2>\
<dl>\
<section class="footer"></section> <dt><kbd>?</kbd></dt>\
<dd>Show this help dialog</dd>\
<aside id="help" class="hidden"> <dt><kbd>S</kbd></dt>\
<div> <dd>Focus the search field</dd>\
<h1 class="hidden">Help</h1> <dt><kbd></kbd></dt>\
<dd>Move up in search results</dd>\
<div class="shortcuts"> <dt><kbd></kbd></dt>\
<h2>Keyboard Shortcuts</h2> <dd>Move down in search results</dd>\
<dt><kbd></kbd></dt>\
<dl> <dd>Switch tab</dd>\
<dt><kbd>?</kbd></dt> <dt><kbd>&#9166;</kbd></dt>\
<dd>Show this help dialog</dd> <dd>Go to active search result</dd>\
<dt><kbd>S</kbd></dt> <dt><kbd>+</kbd></dt>\
<dd>Focus the search field</dd> <dd>Expand all sections</dd>\
<dt><kbd></kbd></dt> <dt><kbd>-</kbd></dt>\
<dd>Move up in search results</dd> <dd>Collapse all sections</dd>\
<dt><kbd></kbd></dt> </dl>\
<dd>Move down in search results</dd> </div>\
<dt><kbd></kbd></dt> <div class=\"infos\">\
<dd>Switch tab</dd> <h2>Search Tricks</h2>\
<dt><kbd>&#9166;</kbd></dt> <p>\
<dd>Go to active search result</dd> Prefix searches with a type followed by a colon (e.g. \
<dt><kbd>+</kbd></dt> <code>fn:</code>) to restrict the search to a given type.\
<dd>Expand all sections</dd> </p>\
<dt><kbd>-</kbd></dt> <p>\
<dd>Collapse all sections</dd> Accepted types are: <code>fn</code>, <code>mod</code>, \
</dl> <code>struct</code>, <code>enum</code>, \
</div> <code>trait</code>, <code>type</code>, <code>macro</code>, \
and <code>const</code>.\
<div class="infos"> </p>\
<h2>Search Tricks</h2> <p>\
Search functions by type signature (e.g. \
<p> <code>vec -> usize</code> or <code>* -> vec</code>)\
Prefix searches with a type followed by a colon (e.g. </p>\
<code>fn:</code>) to restrict the search to a given type. <p>\
</p> Search multiple things at once by splitting your query with comma (e.g. \
<code>str,u8</code> or <code>String,struct:Vec,test</code>)\
<p> </p>\
Accepted types are: <code>fn</code>, <code>mod</code>, </div>\
<code>struct</code>, <code>enum</code>, </div>\
<code>trait</code>, <code>type</code>, <code>macro</code>, </aside>\
and <code>const</code>. {after_content}\
</p> <script>\
window.rootPath = \"{root_path}\";\
<p> window.currentCrate = \"{krate}\";\
Search functions by type signature (e.g. </script>\
<code>vec -> usize</code> or <code>* -> vec</code>) <script src=\"{root_path}main{suffix}.js\"></script>\
</p> <script defer src=\"{root_path}search-index.js\"></script>\
</div> </body>\
</div> </html>",
</aside>
{after_content}
<script>
window.rootPath = "{root_path}";
window.currentCrate = "{krate}";
</script>
<script src="{root_path}main{suffix}.js"></script>
<script defer src="{root_path}search-index.js"></script>
</body>
</html>"##,
css_extension = if css_file_extension { css_extension = if css_file_extension {
format!("<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}theme{suffix}.css\">", format!("<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}theme{suffix}.css\">",
root_path = page.root_path, root_path = page.root_path,

View file

@ -1728,7 +1728,9 @@ impl Context {
let mut dst = try_err!(File::create(&joint_dst), &joint_dst); let mut dst = try_err!(File::create(&joint_dst), &joint_dst);
try_err!(dst.write_all(&buf), &joint_dst); try_err!(dst.write_all(&buf), &joint_dst);
if !self.render_redirect_pages {
all.append(full_path(self, &item), &item_type); all.append(full_path(self, &item), &item_type);
}
// Redirect from a sane URL using the namespace to Rustdoc's // Redirect from a sane URL using the namespace to Rustdoc's
// URL for the page. // URL for the page.
let redir_name = format!("{}.{}.html", name, item_type.name_space()); let redir_name = format!("{}.{}.html", name, item_type.name_space());

View file

@ -1299,14 +1299,78 @@
printTab(currentTab); printTab(currentTab);
} }
function search(e) { function execSearch(query, searchWords) {
var query, var queries = query.raw.split(",");
obj, i, len, var results = {
results = {"in_args": [], "returned": [], "others": []}, 'in_args': [],
resultIndex; 'returned': [],
var params = getQueryStringParams(); 'others': [],
};
for (var i = 0; i < queries.length; ++i) {
var query = queries[i].trim();
if (query.length !== 0) {
var tmp = execQuery(getQuery(query), searchWords);
results['in_args'].push(tmp['in_args']);
results['returned'].push(tmp['returned']);
results['others'].push(tmp['others']);
}
}
if (queries.length > 1) {
function getSmallest(arrays, positions) {
var start = null;
for (var it = 0; it < positions.length; ++it) {
if (arrays[it].length > positions[it] &&
(start === null || start > arrays[it][positions[it]].lev)) {
start = arrays[it][positions[it]].lev;
}
}
return start;
}
function mergeArrays(arrays) {
var ret = [];
var positions = [];
for (var x = 0; x < arrays.length; ++x) {
positions.push(0);
}
while (ret.length < MAX_RESULTS) {
var smallest = getSmallest(arrays, positions);
if (smallest === null) {
break;
}
for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
if (arrays[x].length > positions[x] &&
arrays[x][positions[x]].lev === smallest) {
ret.push(arrays[x][positions[x]]);
positions[x] += 1;
}
}
}
return ret;
}
return {
'in_args': mergeArrays(results['in_args']),
'returned': mergeArrays(results['returned']),
'others': mergeArrays(results['others']),
};
} else {
return {
'in_args': results['in_args'][0],
'returned': results['returned'][0],
'others': results['others'][0],
};
}
}
function search(e) {
var params = getQueryStringParams();
var query = getQuery(document.getElementsByClassName('search-input')[0].value);
query = getQuery(document.getElementsByClassName('search-input')[0].value);
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
} }
@ -1328,8 +1392,7 @@
} }
} }
results = execQuery(query, index); showResults(execSearch(query, index));
showResults(results);
} }
function buildIndex(rawSearchIndex) { function buildIndex(rawSearchIndex) {

View file

@ -336,24 +336,23 @@ declare_keywords! {
(46, Offsetof, "offsetof") (46, Offsetof, "offsetof")
(47, Override, "override") (47, Override, "override")
(48, Priv, "priv") (48, Priv, "priv")
(49, Proc, "proc") (49, Pure, "pure")
(50, Pure, "pure") (50, Sizeof, "sizeof")
(51, Sizeof, "sizeof") (51, Typeof, "typeof")
(52, Typeof, "typeof") (52, Unsized, "unsized")
(53, Unsized, "unsized") (53, Virtual, "virtual")
(54, Virtual, "virtual") (54, Yield, "yield")
(55, Yield, "yield")
// Special lifetime names // Special lifetime names
(56, UnderscoreLifetime, "'_") (55, UnderscoreLifetime, "'_")
(57, StaticLifetime, "'static") (56, StaticLifetime, "'static")
// Weak keywords, have special meaning only in specific contexts. // Weak keywords, have special meaning only in specific contexts.
(58, Auto, "auto") (57, Auto, "auto")
(59, Catch, "catch") (58, Catch, "catch")
(60, Default, "default") (59, Default, "default")
(61, Dyn, "dyn") (60, Dyn, "dyn")
(62, Union, "union") (61, Union, "union")
} }
// If an interner exists, return it. Otherwise, prepare a fresh one. // If an interner exists, return it. Otherwise, prepare a fresh one.

View file

@ -1,4 +1,4 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at // file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT. // http://rust-lang.org/COPYRIGHT.
// //
@ -8,12 +8,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// compile-flags: -Z parse-only const QUERY = 'str,u8';
// Test that we generate obsolete syntax errors around usages of `proc`. const EXPECTED = {
'others': [
fn foo(p: proc()) { } //~ ERROR expected type, found reserved keyword `proc` { 'path': 'std', 'name': 'str' },
{ 'path': 'std', 'name': 'u8' },
fn bar() { proc() 1; } //~ ERROR expected expression, found reserved keyword `proc` { 'path': 'std::ffi', 'name': 'CStr' },
{ 'path': 'std::simd', 'name': 'u8x2' },
fn main() { } ],
};

View file

@ -28,3 +28,11 @@ pub union Union {
pub const CONST: u32 = 0; pub const CONST: u32 = 0;
pub static STATIC: &str = "baguette"; pub static STATIC: &str = "baguette";
pub fn function() {} pub fn function() {}
mod private_module {
pub struct ReexportedStruct;
}
// @has foo/all.html '//a[@href="struct.ReexportedStruct.html"]' 'ReexportedStruct'
// @!has foo/all.html 'private_module'
pub use private_module::ReexportedStruct;

View file

@ -157,7 +157,8 @@ function main(argv) {
// execQuery first parameter is built in getQuery (which takes in the search input). // execQuery first parameter is built in getQuery (which takes in the search input).
// execQuery last parameter is built in buildIndex. // execQuery last parameter is built in buildIndex.
// buildIndex requires the hashmap from search-index. // buildIndex requires the hashmap from search-index.
var functionsToLoad = ["levenshtein", "validateResult", "getQuery", "buildIndex", "execQuery"]; var functionsToLoad = ["levenshtein", "validateResult", "getQuery", "buildIndex", "execQuery",
"execSearch"];
finalJS += 'window = { "currentCrate": "std" };\n'; finalJS += 'window = { "currentCrate": "std" };\n';
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs); finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
@ -174,7 +175,7 @@ function main(argv) {
'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
const expected = loadedFile.EXPECTED; const expected = loadedFile.EXPECTED;
const query = loadedFile.QUERY; const query = loadedFile.QUERY;
var results = loaded.execQuery(loaded.getQuery(query), index); var results = loaded.execSearch(loaded.getQuery(query), index);
process.stdout.write('Checking "' + file + '" ... '); process.stdout.write('Checking "' + file + '" ... ');
var error_text = []; var error_text = [];
for (var key in expected) { for (var key in expected) {