diff options
| author | bors <bors@rust-lang.org> | 2018-12-06 12:41:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-12-06 12:41:30 +0000 |
| commit | 367e783e6f66a4dba32decdc68a262953d2f3f1b (patch) | |
| tree | cda4764d303feb6c62218550fb619c73a2eebdc8 /src/librustdoc | |
| parent | 128a1fa4e1f85e04f522653bb9bee83ed6523440 (diff) | |
| parent | cd1ee5edbd080659f1ff353dd828bdf9749cf11d (diff) | |
| download | rust-367e783e6f66a4dba32decdc68a262953d2f3f1b.tar.gz rust-367e783e6f66a4dba32decdc68a262953d2f3f1b.zip | |
Auto merge of #56557 - pietroalbini:rollup, r=pietroalbini
Rollup of 11 pull requests Successful merges: - #56315 (Rustdoc inline macro reexport) - #56332 ([rustdoc] Specific crate search) - #56362 (Stabilise exhaustive integer patterns) - #56426 (libsyntax_pos: A few tweaks) - #56441 (rustbuild: Fix issues with compiler docs) - #56446 (pass the parameter environment to `traits::find_associated_item`) - #56500 (cleanup: remove static lifetimes from consts) - #56525 (Avoid extra copy and syscall in std::env::current_exe) - #56528 (Remove unused dependency (rustc_lint -> rustc_mir)) - #56548 (Optimized string FromIterator + Extend impls) - #56553 (Don't print the profiling summary to stdout when -Zprofile-json is set) Failed merges: r? @ghost
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/html/layout.rs | 18 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/static/down-arrow.svg | 1 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.js | 99 | ||||
| -rw-r--r-- | src/librustdoc/html/static/rustdoc.css | 28 | ||||
| -rw-r--r-- | src/librustdoc/html/static/themes/dark.css | 8 | ||||
| -rw-r--r-- | src/librustdoc/html/static/themes/light.css | 9 | ||||
| -rw-r--r-- | src/librustdoc/html/static_files.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 14 |
10 files changed, 158 insertions, 32 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5276683648d..310c369a4d0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, let stripped_typarams = gens.params.iter().filter_map(|param| match param.kind { ty::GenericParamDefKind::Lifetime => None, ty::GenericParamDefKind::Type { .. } => { - if param.name == keywords::SelfType.name().as_str() { + if param.name == keywords::SelfUpper.name().as_str() { assert_eq!(param.index, 0); return None; } @@ -3174,7 +3174,7 @@ fn qpath_to_string(p: &hir::QPath) -> String { if i > 0 { s.push_str("::"); } - if seg.ident.name != keywords::CrateRoot.name() { + if seg.ident.name != keywords::PathRoot.name() { s.push_str(&*seg.ident.as_str()); } } @@ -3726,7 +3726,7 @@ fn resolve_type(cx: &DocContext, hir::Float(float_ty) => return Primitive(float_ty.into()), }, Def::SelfTy(..) if path.segments.len() == 1 => { - return Generic(keywords::SelfType.name().to_string()); + return Generic(keywords::SelfUpper.name().to_string()); } Def::TyParam(..) if path.segments.len() == 1 => { return Generic(format!("{:#}", path)); diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 5263cfe7b0e..fa5d015e5b7 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -57,6 +57,9 @@ pub fn render<T: fmt::Display, S: fmt::Display>( {css_extension}\ {favicon}\ {in_header}\ + <style type=\"text/css\">\ + #crate-search{{background-image:url(\"{root_path}down-arrow{suffix}.svg\");}}\ + </style>\ </head>\ <body class=\"rustdoc {css_class}\">\ <!--[if lte IE 8]>\ @@ -81,11 +84,16 @@ pub fn render<T: fmt::Display, S: fmt::Display>( <nav class=\"sub\">\ <form class=\"search-form js-only\">\ <div class=\"search-container\">\ - <input class=\"search-input\" name=\"search\" \ - autocomplete=\"off\" \ - spellcheck=\"false\" \ - placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \ - type=\"search\">\ + <div>\ + <select id=\"crate-search\">\ + <option value=\"All crates\">All crates</option>\ + </select>\ + <input class=\"search-input\" name=\"search\" \ + autocomplete=\"off\" \ + spellcheck=\"false\" \ + placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \ + type=\"search\">\ + </div>\ <a id=\"settings-menu\" href=\"{root_path}settings.html\">\ <img src=\"{root_path}wheel{suffix}.svg\" width=\"18\" alt=\"Change settings\">\ </a>\ diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 1194df20ad6..6158815fb9a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -793,6 +793,8 @@ fn write_shared( static_files::BRUSH_SVG)?; write(cx.dst.join(&format!("wheel{}.svg", cx.shared.resource_suffix)), static_files::WHEEL_SVG)?; + write(cx.dst.join(&format!("down-arrow{}.svg", cx.shared.resource_suffix)), + static_files::DOWN_ARROW_SVG)?; write_minify(cx.dst.join(&format!("light{}.css", cx.shared.resource_suffix)), static_files::themes::LIGHT, options.enable_minification)?; @@ -1066,7 +1068,7 @@ themePicker.onblur = handleThemeButtonsBlur; &[(minifier::js::Keyword::Null, "N")]), &dst); } - try_err!(writeln!(&mut w, "initSearch(searchIndex);"), &dst); + try_err!(writeln!(&mut w, "initSearch(searchIndex);addSearchOptions(searchIndex);"), &dst); if options.enable_index_page { if let Some(index_page) = options.index_page.clone() { diff --git a/src/librustdoc/html/static/down-arrow.svg b/src/librustdoc/html/static/down-arrow.svg new file mode 100644 index 00000000000..a2d9a37dde0 --- /dev/null +++ b/src/librustdoc/html/static/down-arrow.svg @@ -0,0 +1 @@ +<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg height="128px" id="Layer_1" style="enable-background:new 0 0 128 128;" version="1.1" viewBox="0 0 128 128" width="128px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><line style="fill:none;stroke:#2F3435;stroke-width:12;stroke-linecap:square;stroke-miterlimit:10;" x1="111" x2="64" y1="40.5" y2="87.499"/><line style="fill:none;stroke:#2F3435;stroke-width:12;stroke-linecap:square;stroke-miterlimit:10;" x1="64" x2="17" y1="87.499" y2="40.5"/></g></svg> \ No newline at end of file diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 125277fc5d3..1869969a530 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -218,12 +218,14 @@ if (!String.prototype.endsWith) { // // So I guess you could say things are getting pretty interoperable. function getVirtualKey(ev) { - if ("key" in ev && typeof ev.key != "undefined") + if ("key" in ev && typeof ev.key != "undefined") { return ev.key; + } var c = ev.charCode || ev.keyCode; - if (c == 27) + if (c == 27) { return "Escape"; + } return String.fromCharCode(c); } @@ -431,12 +433,13 @@ if (!String.prototype.endsWith) { /** * Executes the query and builds an index of results - * @param {[Object]} query [The user query] - * @param {[type]} searchWords [The list of search words to query - * against] - * @return {[type]} [A search index of results] + * @param {[Object]} query [The user query] + * @param {[type]} searchWords [The list of search words to query + * against] + * @param {[type]} filterCrates [Crate to search in if defined] + * @return {[type]} [A search index of results] */ - function execQuery(query, searchWords) { + function execQuery(query, searchWords, filterCrates) { function itemTypeFromName(typename) { for (var i = 0; i < itemTypes.length; ++i) { if (itemTypes[i] === typename) { @@ -812,6 +815,9 @@ if (!String.prototype.endsWith) { { val = extractGenerics(val.substr(1, val.length - 2)); for (var i = 0; i < nSearchWords; ++i) { + if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { + continue; + } var in_args = findArg(searchIndex[i], val, true); var returned = checkReturned(searchIndex[i], val, true); var ty = searchIndex[i]; @@ -866,6 +872,9 @@ if (!String.prototype.endsWith) { var output = extractGenerics(parts[1]); for (var i = 0; i < nSearchWords; ++i) { + if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { + continue; + } var type = searchIndex[i].type; var ty = searchIndex[i]; if (!type) { @@ -937,11 +946,11 @@ if (!String.prototype.endsWith) { var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1); for (j = 0; j < nSearchWords; ++j) { - var lev_distance; var ty = searchIndex[j]; - if (!ty) { + if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) { continue; } + var lev_distance; var lev_add = 0; if (paths.length > 1) { var lev = checkPath(contains, paths[paths.length - 1], ty); @@ -1326,7 +1335,7 @@ if (!String.prototype.endsWith) { return '<div>' + text + ' <div class="count">(' + nbElems + ')</div></div>'; } - function showResults(results) { + function showResults(results, filterCrates) { if (results['others'].length === 1 && getCurrentValue('rustdoc-go-to-only-result') === "true") { var elem = document.createElement('a'); @@ -1344,8 +1353,13 @@ if (!String.prototype.endsWith) { var ret_in_args = addTab(results['in_args'], query, false); var ret_returned = addTab(results['returned'], query, false); + var filter = ""; + if (filterCrates !== undefined) { + filter = " (in <b>" + filterCrates + "</b> crate)"; + } + var output = '<h1>Results for ' + escape(query.query) + - (query.type ? ' (type: ' + escape(query.type) + ')' : '') + '</h1>' + + (query.type ? ' (type: ' + escape(query.type) + ')' : '') + filter + '</h1>' + '<div id="titles">' + makeTabHeader(0, "In Names", ret_others[1]) + makeTabHeader(1, "In Parameters", ret_in_args[1]) + @@ -1374,7 +1388,7 @@ if (!String.prototype.endsWith) { printTab(currentTab); } - function execSearch(query, searchWords) { + function execSearch(query, searchWords, filterCrates) { var queries = query.raw.split(","); var results = { 'in_args': [], @@ -1385,7 +1399,7 @@ if (!String.prototype.endsWith) { for (var i = 0; i < queries.length; ++i) { var query = queries[i].trim(); if (query.length !== 0) { - var tmp = execQuery(getQuery(query), searchWords); + var tmp = execQuery(getQuery(query), searchWords, filterCrates); results['in_args'].push(tmp['in_args']); results['returned'].push(tmp['returned']); @@ -1447,7 +1461,16 @@ if (!String.prototype.endsWith) { } } - function search(e) { + function getFilterCrates() { + var elem = document.getElementById("crate-search"); + + if (elem && elem.value !== "All crates" && rawSearchIndex.hasOwnProperty(elem.value)) { + return elem.value; + } + return undefined; + } + + function search(e, forced) { var params = getQueryStringParams(); var query = getQuery(search_input.value.trim()); @@ -1455,7 +1478,10 @@ if (!String.prototype.endsWith) { e.preventDefault(); } - if (query.query.length === 0 || query.id === currentResults) { + if (query.query.length === 0) { + return; + } + if (forced !== true && query.id === currentResults) { if (query.query.length > 0) { putBackSearch(search_input); } @@ -1475,7 +1501,8 @@ if (!String.prototype.endsWith) { } } - showResults(execSearch(query, index)); + var filterCrates = getFilterCrates(); + showResults(execSearch(query, index, filterCrates), filterCrates); } function buildIndex(rawSearchIndex) { @@ -1575,6 +1602,13 @@ if (!String.prototype.endsWith) { }; search_input.onpaste = search_input.onchange; + var selectCrate = document.getElementById('crate-search'); + if (selectCrate) { + selectCrate.onchange = function() { + search(undefined, true); + }; + } + // Push and pop states are used to add search results to the browser // history. if (browserSupportsHistoryApi()) { @@ -2323,6 +2357,39 @@ if (!String.prototype.endsWith) { if (window.location.hash && window.location.hash.length > 0) { expandSection(window.location.hash.replace(/^#/, '')); } + + function addSearchOptions(crates) { + var elem = document.getElementById('crate-search'); + + if (!elem) { + return; + } + var crates_text = []; + for (var crate in crates) { + if (crates.hasOwnProperty(crate)) { + crates_text.push(crate); + } + } + crates_text.sort(function(a, b) { + var lower_a = a.toLowerCase(); + var lower_b = b.toLowerCase(); + + if (lower_a < lower_b) { + return -1; + } else if (lower_a > lower_b) { + return 1; + } + return 0; + }); + for (var i = 0; i < crates_text.length; ++i) { + var option = document.createElement("option"); + option.value = crates_text[i]; + option.innerText = crates_text[i]; + elem.appendChild(option); + } + } + + window.addSearchOptions = addSearchOptions; }()); // Sets the focus on the search bar at the top of the page diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 83129d93a68..37d26a4cadc 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -620,13 +620,36 @@ a { .search-container { position: relative; } +.search-container > div { + display: inline-flex; + width: calc(100% - 34px); +} +#crate-search { + margin-top: 5px; + padding: 6px; + padding-right: 19px; + border: 0; + border-right: 0; + border-radius: 4px 0 0 4px; + outline: none; + cursor: pointer; + border-right: 1px solid; + -moz-appearance: none; + -webkit-appearance: none; + /* Removes default arrow from firefox */ + text-indent: 0.01px; + text-overflow: ""; + background-repeat: no-repeat; + background-color: transparent; + background-size: 16%; + background-position: calc(100% - 1px) 56%; +} .search-container > .top-button { position: absolute; right: 0; top: 10px; } .search-input { - width: calc(100% - 34px); /* Override Normalize.css: we have margins and do not want to overflow - the `moz` attribute is necessary until Firefox 29, too early to drop at this point */ @@ -634,13 +657,14 @@ a { box-sizing: border-box !important; outline: none; border: none; - border-radius: 1px; + border-radius: 0 1px 1px 0; margin-top: 5px; padding: 10px 16px; font-size: 17px; transition: border-color 300ms ease; transition: border-radius 300ms ease-in-out; transition: box-shadow 300ms ease-in-out; + width: 100%; } .search-input:focus { diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index 29388f096ee..2cd1a858089 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -182,9 +182,15 @@ a.test-arrow { color: #999; } +#crate-search { + color: #111; + background-color: #f0f0f0; + border-color: #000; +} + .search-input { color: #111; - box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; + box-shadow: 1px 0 0 1px #000, 0 0 0 2px transparent; background-color: #f0f0f0; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index d37cfa4142f..4cf35f64d19 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -182,9 +182,16 @@ a.test-arrow { color: #999; } +#crate-search { + color: #555; + background-color: white; + border-color: #e0e0e0; + box-shadow: 0px 0 0 1px #e0e0e0, 0 0 0 2px transparent; +} + .search-input { color: #555; - box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; + box-shadow: 1px 0 0 1px #e0e0e0, 0 0 0 2px transparent; background-color: white; } diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index ee29f15d686..a485facfac2 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -45,6 +45,9 @@ pub static BRUSH_SVG: &'static [u8] = include_bytes!("static/brush.svg"); /// The file contents of `wheel.svg`, the icon used for the settings button. pub static WHEEL_SVG: &'static [u8] = include_bytes!("static/wheel.svg"); +/// The file contents of `down-arrow.svg`, the icon used for the crate choice combobox. +pub static DOWN_ARROW_SVG: &'static [u8] = include_bytes!("static/down-arrow.svg"); + /// The contents of `COPYRIGHT.txt`, the license listing for files distributed with documentation /// output. pub static COPYRIGHT: &'static [u8] = include_bytes!("static/COPYRIGHT.txt"); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 5d221d3006f..31adb2e0369 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -100,7 +100,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { None); // attach the crate's exported macros to the top-level module: let macro_exports: Vec<_> = - krate.exported_macros.iter().map(|def| self.visit_local_macro(def)).collect(); + krate.exported_macros.iter().map(|def| self.visit_local_macro(def, None)).collect(); self.module.macros.extend(macro_exports); self.module.is_crate = true; @@ -376,6 +376,10 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { }); true } + Node::MacroDef(def) if !glob => { + om.macros.push(self.visit_local_macro(def, renamed)); + true + } _ => false, }; self.view_item_stack.remove(&def_node_id); @@ -593,7 +597,11 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { } // convert each exported_macro into a doc item - fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro { + fn visit_local_macro( + &self, + def: &hir::MacroDef, + renamed: Option<ast::Name> + ) -> Macro { debug!("visit_local_macro: {}", def.name); let tts = def.body.trees().collect::<Vec<_>>(); // Extract the spans of all matchers. They represent the "interface" of the macro. @@ -602,7 +610,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> { Macro { def_id: self.cx.tcx.hir.local_def_id(def.id), attrs: def.attrs.clone(), - name: def.name, + name: renamed.unwrap_or(def.name), whence: def.span, matchers, stab: self.stability(def.id), |
