From 5676bd51aeaa6b05735dc888a2e41770a4d7b162 Mon Sep 17 00:00:00 2001 From: Midas Lambrichts Date: Fri, 26 Mar 2021 23:16:22 +0100 Subject: [PATCH 1/6] Break when there is a mismatch in the type count When other errors are generated, there can be a mismatch between the amount of input types in MIR, and the amount in the function itself. Break from the comparative loop if this is the case to prevent out-of-bounds. --- .../rustc_mir/src/borrow_check/type_check/input_output.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs index 77d9136622458..1bb447d105781 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs @@ -70,6 +70,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // Equate expected input tys with those in the MIR. for (argument_index, &normalized_input_ty) in normalized_input_tys.iter().enumerate() { + if argument_index + 1 >= body.local_decls.len() { + self.tcx() + .sess + .delay_span_bug(body.span, "found more normalized_input_ty than local_decls"); + break; + } // In MIR, argument N is stored in local N+1. let local = Local::new(argument_index + 1); From 828179d687e0e6d75a1816c45bc866445d057e04 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 31 Mar 2021 22:13:47 +0200 Subject: [PATCH 2/6] Add a button to copy the "use statement" --- src/librustdoc/html/markdown.rs | 1 + src/librustdoc/html/render/print_item.rs | 1 + src/librustdoc/html/static/main.js | 25 +++++++++++++++++++++ src/librustdoc/html/static/noscript.css | 5 +++++ src/librustdoc/html/static/rustdoc.css | 23 +++++++++++++------ src/librustdoc/html/static/themes/ayu.css | 5 +++-- src/librustdoc/html/static/themes/dark.css | 5 +++-- src/librustdoc/html/static/themes/light.css | 5 +++-- 8 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index b39f9f878921a..eecdf6fe0ce8c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -1354,6 +1354,7 @@ fn init_id_map() -> FxHashMap { map.insert("default-settings".to_owned(), 1); map.insert("rustdoc-vars".to_owned(), 1); map.insert("sidebar-vars".to_owned(), 1); + map.insert("copy-path".to_owned(), 1); // This is the list of IDs used by rustdoc sections. map.insert("fields".to_owned(), 1); map.insert("variants".to_owned(), 1); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index cc93e55fc676e..25314f87eb5ae 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -73,6 +73,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) } } write!(buf, "{}", item.type_(), item.name.as_ref().unwrap()); + write!(buf, ""); buf.write_str(""); // in-band buf.write_str(""); diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index da2952bbebdbe..f2e62ee7b6b5e 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -3061,3 +3061,28 @@ function hideThemeButtonState() { window.onhashchange = onHashChange; setupSearchLoader(); }()); + +function copy_path(but) { + var parent = but.parentElement; + var path = []; + + onEach(parent.childNodes, function(child) { + if (child.tagName === 'A') { + path.push(child.textContent); + } + }); + + var el = document.createElement('textarea'); + el.value = 'use ' + path.join('::') + ';'; + el.setAttribute('readonly', ''); + // To not make it appear on the screen. + el.style.position = 'absolute'; + el.style.left = '-9999px'; + + document.body.appendChild(el); + el.select(); + document.execCommand('copy'); + document.body.removeChild(el); + + but.textContent = '✓'; +} diff --git a/src/librustdoc/html/static/noscript.css b/src/librustdoc/html/static/noscript.css index c9fed989ec04a..4d3332877c0d5 100644 --- a/src/librustdoc/html/static/noscript.css +++ b/src/librustdoc/html/static/noscript.css @@ -33,3 +33,8 @@ rules. /* Since there is no toggle (the "[-]") when JS is disabled, no need for this margin either. */ margin-left: 0 !important; } + +#copy-path { + /* It requires JS to work so no need to display it in this case. */ + display: none; +} diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 6c90fd7c9eed8..6b2edf60f1519 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1316,20 +1316,29 @@ h4 > .notable-traits { outline: none; } +#theme-picker, #settings-menu, .help-button, #copy-path { + padding: 4px; + width: 27px; + height: 29px; + border: 1px solid; + border-radius: 3px; + cursor: pointer; +} + .help-button { right: 30px; font-family: "Fira Sans", Arial, sans-serif; text-align: center; font-size: 17px; + padding-top: 2px; } -#theme-picker, #settings-menu, .help-button { - padding: 4px; - width: 27px; - height: 29px; - border: 1px solid; - border-radius: 3px; - cursor: pointer; +#copy-path { + height: 30px; + font-size: 18px; + margin-left: 10px; + padding: 0 6px; + width: 28px; } #theme-choices { diff --git a/src/librustdoc/html/static/themes/ayu.css b/src/librustdoc/html/static/themes/ayu.css index 7374aee71f8f8..b24f4035ca868 100644 --- a/src/librustdoc/html/static/themes/ayu.css +++ b/src/librustdoc/html/static/themes/ayu.css @@ -498,7 +498,7 @@ kbd { box-shadow-color: #c6cbd1; } -#theme-picker, #settings-menu, .help-button { +#theme-picker, #settings-menu, .help-button, #copy-path { border-color: #5c6773; background-color: #0f1419; color: #fff; @@ -510,7 +510,8 @@ kbd { #theme-picker:hover, #theme-picker:focus, #settings-menu:hover, #settings-menu:focus, -.help-button:hover, .help-button:focus { +.help-button:hover, .help-button:focus, +#copy-path:hover, #copy-path:focus { border-color: #e0e0e0; } diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index cf2d28bb43feb..e863ed03f5156 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -388,7 +388,7 @@ kbd { box-shadow-color: #c6cbd1; } -#theme-picker, #settings-menu, .help-button { +#theme-picker, #settings-menu, .help-button, #copy-path { border-color: #e0e0e0; background: #f0f0f0; color: #000; @@ -396,7 +396,8 @@ kbd { #theme-picker:hover, #theme-picker:focus, #settings-menu:hover, #settings-menu:focus, -.help-button:hover, .help-button:focus { +.help-button:hover, .help-button:focus, +#copy-path:hover, #copy-path:focus { border-color: #ffb900; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index 7bf6793809c90..9335dd96d299a 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -380,14 +380,15 @@ kbd { box-shadow-color: #c6cbd1; } -#theme-picker, #settings-menu, .help-button { +#theme-picker, #settings-menu, .help-button, #copy-path { border-color: #e0e0e0; background-color: #fff; } #theme-picker:hover, #theme-picker:focus, #settings-menu:hover, #settings-menu:focus, -.help-button:hover, .help-button:focus { +.help-button:hover, .help-button:focus, +#copy-path:hover, #copy-path:focus { border-color: #717171; } From 2e4215cb72a256b4843323ea5c9f1552e2c13a43 Mon Sep 17 00:00:00 2001 From: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> Date: Thu, 1 Apr 2021 00:52:02 -0400 Subject: [PATCH 3/6] Fix minor typo in once.rs --- library/std/src/sync/once.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index 2e5f843fc43cb..a24a5cb2ae39f 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -471,7 +471,7 @@ fn wait(state_and_queue: &AtomicUsize, mut current_state: usize) { // If the managing thread happens to signal and unpark us before we // can park ourselves, the result could be this thread never gets // unparked. Luckily `park` comes with the guarantee that if it got - // an `unpark` just before on an unparked thread is does not park. + // an `unpark` just before on an unparked thread it does not park. thread::park(); } break; From a38d3cb17aed86e9cf977b571926954224c43869 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 1 Apr 2021 20:43:44 +0900 Subject: [PATCH 4/6] Add my new email address to .mailmap --- .mailmap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index 3f23aed31a833..1019710dc9793 100644 --- a/.mailmap +++ b/.mailmap @@ -286,7 +286,7 @@ Xuefeng Wu Xuefeng Wu Xuefeng Wu XuefengWu York Xiang Youngsoo Son -Yuki Okushi +Yuki Okushi Zach Pomerantz Zack Corr Zack Slayton From 2d813b26092ac67933de06009e2eede04b056923 Mon Sep 17 00:00:00 2001 From: Midas Lambrichts Date: Thu, 1 Apr 2021 20:54:57 +0200 Subject: [PATCH 5/6] Add a test that triggers the out-of-bounds ICE. Add a test that has the right input to trigger an out-of-bounds error when in MIR the local_decls and the normalized_input_tys don't match in amount. --- .../issue-83499-input-output-iteration-ice.rs | 10 +++++++++ ...ue-83499-input-output-iteration-ice.stderr | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/ui/mir/issue-83499-input-output-iteration-ice.rs create mode 100644 src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr diff --git a/src/test/ui/mir/issue-83499-input-output-iteration-ice.rs b/src/test/ui/mir/issue-83499-input-output-iteration-ice.rs new file mode 100644 index 0000000000000..4d404d015ec0b --- /dev/null +++ b/src/test/ui/mir/issue-83499-input-output-iteration-ice.rs @@ -0,0 +1,10 @@ +// Test that when in MIR the amount of local_decls and amount of normalized_input_tys don't match +// that an out-of-bounds access does not occur. +#![feature(c_variadic)] + +fn main() {} + +fn foo(_: Bar, ...) -> impl {} +//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~| ERROR cannot find type `Bar` in this scope +//~| ERROR at least one trait must be specified diff --git a/src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr b/src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr new file mode 100644 index 0000000000000..eb172684899cf --- /dev/null +++ b/src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr @@ -0,0 +1,21 @@ +error: only foreign or `unsafe extern "C" functions may be C-variadic + --> $DIR/issue-83499-input-output-iteration-ice.rs:7:16 + | +LL | fn foo(_: Bar, ...) -> impl {} + | ^^^ + +error: at least one trait must be specified + --> $DIR/issue-83499-input-output-iteration-ice.rs:7:24 + | +LL | fn foo(_: Bar, ...) -> impl {} + | ^^^^ + +error[E0412]: cannot find type `Bar` in this scope + --> $DIR/issue-83499-input-output-iteration-ice.rs:7:11 + | +LL | fn foo(_: Bar, ...) -> impl {} + | ^^^ not found in this scope + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0412`. From f13135070cf8b973673f2383e283e3d8af26a794 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 1 Apr 2021 21:55:06 +0200 Subject: [PATCH 6/6] Add test to ensure search tabs behaviour --- ...rch-tab-selection-if-current-is-empty.goml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml diff --git a/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml b/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml new file mode 100644 index 0000000000000..a4df102d245be --- /dev/null +++ b/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml @@ -0,0 +1,21 @@ +goto: file://|DOC_PATH|/index.html +write: (".search-input", "Foo") +// Waiting for the search results to appear... +wait-for: "#titles" +assert: ("#titles > button:nth-of-type(1)", "class", "selected") + +// To go back to the original "state" +goto: file://|DOC_PATH|/index.html +write: (".search-input", "-> String") +// Waiting for the search results to appear... +wait-for: "#titles" +// With this search, only the last tab shouldn't be empty so it should be selected. +assert: ("#titles > button:nth-of-type(3)", "class", "selected") + +// To go back to the original "state" +goto: file://|DOC_PATH|/index.html +write: (".search-input", "-> Something") +// Waiting for the search results to appear... +wait-for: "#titles" +// With this search, all the tabs are empty so the first one should remain selected. +assert: ("#titles > button:nth-of-type(1)", "class", "selected")