From 1899afa685a9b43cccff0869c2b210bd397306a6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 11 May 2020 18:13:51 +0300 Subject: [PATCH 1/8] rustc-book: Document `-Z strip=val` option --- .../unstable-book/src/compiler-flags/strip.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/doc/unstable-book/src/compiler-flags/strip.md diff --git a/src/doc/unstable-book/src/compiler-flags/strip.md b/src/doc/unstable-book/src/compiler-flags/strip.md new file mode 100644 index 0000000000000..52cb98113c0c1 --- /dev/null +++ b/src/doc/unstable-book/src/compiler-flags/strip.md @@ -0,0 +1,17 @@ +# `strip` + +The tracking issue for this feature is: [#72110](https://github.com/rust-lang/rust/issues/72110). + +------------------------ + +Option `-Z strip=val` controls stripping of debuginfo and similar auxiliary data from binaries +during linking. + +Supported values for this option are: + +- `none` - debuginfo and symbols (if they exist) are copied to the produced binary or separate files +depending on the target (e.g. `.pdb` files in case of MSVC). +- `debuginfo` - debuginfo sections and debuginfo symbols from the symbol table section +are stripped at link time and are not copied to the produced binary or separate files. +- `symbols` - same as `debuginfo`, but the rest of the symbol table section is stripped as well +if the linker supports it. From ed8478036c416694db5f51f6e43078a1c07532cf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 16 May 2020 17:51:16 +0200 Subject: [PATCH 2/8] Fix going back in history to a search result page on firefox --- src/librustdoc/html/static/main.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index a023d5a2d95f1..fffabcf79fe7c 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2703,3 +2703,9 @@ function focusSearchBar() { function defocusSearchBar() { getSearchInput().blur(); } + +// This is required in firefox. Explanations: when going back in the history, firefox doesn't re-run +// the JS, therefore preventing rustdoc from setting a few things required to be able to reload the +// previous search results (if you navigated to a search result with the keyboard, pressed enter on +// it to navigate to that result, and then came back to this page). +window.onunload = function(){}; From 9b2b8a5afa833795b66267684615497c9547878d Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 17 May 2020 15:51:01 -0400 Subject: [PATCH 3/8] Break tokens before checking if they are 'probably equal' Fixes #68489 When checking two `TokenStreams` to see if they are 'probably equal', we ignore the `IsJoint` information associated with each `TokenTree`. However, the `IsJoint` information determines whether adjacent tokens will be 'glued' (if possible) when construction the `TokenStream` - e.g. `[Gt Gt]` can be 'glued' to `BinOp(Shr)`. Since we are ignoring the `IsJoint` information, 'glued' and 'unglued' tokens are equivalent for determining if two `TokenStreams` are 'probably equal'. Therefore, we need to 'unglue' all tokens in the stream to avoid false negatives (which cause us to throw out the cached tokens, losing span information). --- src/librustc_ast/tokenstream.rs | 34 +++++++++++++++++-- src/test/ui/proc-macro/turbo-proc-macro.rs | 9 +++++ .../ui/proc-macro/turbo-proc-macro.stderr | 9 +++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/proc-macro/turbo-proc-macro.rs create mode 100644 src/test/ui/proc-macro/turbo-proc-macro.stderr diff --git a/src/librustc_ast/tokenstream.rs b/src/librustc_ast/tokenstream.rs index 916a5ff6f46f4..38483360c0664 100644 --- a/src/librustc_ast/tokenstream.rs +++ b/src/librustc_ast/tokenstream.rs @@ -338,8 +338,38 @@ impl TokenStream { true } - let mut t1 = self.trees().filter(semantic_tree); - let mut t2 = other.trees().filter(semantic_tree); + // When comparing two `TokenStream`s, we ignore the `IsJoint` information. + // + // However, `rustc_parse::lexer::tokentrees::TokenStreamBuilder` will + // use `Token.glue` on adjacent tokens with the proper `IsJoint`. + // Since we are ignoreing `IsJoint`, a 'glued' token (e.g. `BinOp(Shr)`) + // and its 'split'/'unglued' compoenents (e.g. `Gt, Gt`) are equivalent + // when determining if two `TokenStream`s are 'probably equal'. + // + // Therefore, we use `break_two_token_op` to convert all tokens + // to the 'unglued' form (if it exists). This ensures that two + // `TokenStream`s which differ only in how their tokens are glued + // will be considered 'probably equal', which allows us to keep spans. + // + // This is important when the original `TokenStream` contained + // extra spaces (e.g. `f :: < Vec < _ > > ( ) ;'). These extra spaces + // will be omitted when we pretty-print, which can cause the original + // and reparsed `TokenStream`s to differ in the assignment of `IsJoint`, + // leading to some tokens being 'glued' together in one stream but not + // the other. See #68489 for more details. + fn break_tokens(tree: TokenTree) -> impl Iterator { + if let TokenTree::Token(token) = &tree { + if let Some((first, second)) = token.kind.break_two_token_op() { + return SmallVec::from_buf([TokenTree::Token(Token::new(first, DUMMY_SP)), TokenTree::Token(Token::new(second, DUMMY_SP))]).into_iter() + } + } + let mut vec = SmallVec::<[_; 2]>::new(); + vec.push(tree); + vec.into_iter() + } + + let mut t1 = self.trees().filter(semantic_tree).flat_map(break_tokens); + let mut t2 = other.trees().filter(semantic_tree).flat_map(break_tokens); for (t1, t2) in t1.by_ref().zip(t2.by_ref()) { if !t1.probably_equal_for_proc_macro(&t2) { return false; diff --git a/src/test/ui/proc-macro/turbo-proc-macro.rs b/src/test/ui/proc-macro/turbo-proc-macro.rs new file mode 100644 index 0000000000000..a255955f38da0 --- /dev/null +++ b/src/test/ui/proc-macro/turbo-proc-macro.rs @@ -0,0 +1,9 @@ +// aux-build:test-macros.rs + +extern crate test_macros; + +#[test_macros::recollect_attr] +fn repro() { + f :: < Vec < _ > > ( ) ; //~ ERROR cannot find +} +fn main() {} diff --git a/src/test/ui/proc-macro/turbo-proc-macro.stderr b/src/test/ui/proc-macro/turbo-proc-macro.stderr new file mode 100644 index 0000000000000..85c93b9345c37 --- /dev/null +++ b/src/test/ui/proc-macro/turbo-proc-macro.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `f` in this scope + --> $DIR/turbo-proc-macro.rs:7:5 + | +LL | f :: < Vec < _ > > ( ) ; + | ^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. From fdc4522f80b75775cbcd05e216f36e2686ec291c Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 20 May 2020 00:11:05 +0100 Subject: [PATCH 4/8] Remove unused `StableHashingContext::node_to_hir_id` method --- src/librustc_middle/ich/hcx.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/librustc_middle/ich/hcx.rs b/src/librustc_middle/ich/hcx.rs index d58aa383667e4..69b4adb3a0e1d 100644 --- a/src/librustc_middle/ich/hcx.rs +++ b/src/librustc_middle/ich/hcx.rs @@ -135,11 +135,6 @@ impl<'a> StableHashingContext<'a> { self.definitions.def_path_hash(def_id) } - #[inline] - pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId { - self.definitions.node_id_to_hir_id(node_id) - } - #[inline] pub fn hash_bodies(&self) -> bool { self.hash_bodies From 4a8ccdcc0b518e3c1878ce0be888fd85521b2026 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 19 May 2020 19:45:58 -0400 Subject: [PATCH 5/8] Use a fixed-point iteration when breaking tokens Some tokens need to be broken in a loop until we reach 'unbreakable' tokens. --- src/librustc_ast/tokenstream.rs | 45 ++++++++++++++++--- src/test/ui/proc-macro/break-token-spans.rs | 16 +++++++ .../ui/proc-macro/break-token-spans.stderr | 21 +++++++++ src/test/ui/proc-macro/turbo-proc-macro.rs | 9 ---- .../ui/proc-macro/turbo-proc-macro.stderr | 9 ---- 5 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 src/test/ui/proc-macro/break-token-spans.rs create mode 100644 src/test/ui/proc-macro/break-token-spans.stderr delete mode 100644 src/test/ui/proc-macro/turbo-proc-macro.rs delete mode 100644 src/test/ui/proc-macro/turbo-proc-macro.stderr diff --git a/src/librustc_ast/tokenstream.rs b/src/librustc_ast/tokenstream.rs index 38483360c0664..075aaa7e5bc01 100644 --- a/src/librustc_ast/tokenstream.rs +++ b/src/librustc_ast/tokenstream.rs @@ -21,6 +21,8 @@ use rustc_macros::HashStable_Generic; use rustc_span::{Span, DUMMY_SP}; use smallvec::{smallvec, SmallVec}; +use log::debug; + use std::{iter, mem}; /// When the main rust parser encounters a syntax-extension invocation, it @@ -358,14 +360,47 @@ impl TokenStream { // leading to some tokens being 'glued' together in one stream but not // the other. See #68489 for more details. fn break_tokens(tree: TokenTree) -> impl Iterator { + // In almost all cases, we should have either zero or one levels + // of 'unglueing'. However, in some unusual cases, we may need + // to iterate breaking tokens mutliple times. For example: + // '[BinOpEq(Shr)] => [Gt, Ge] -> [Gt, Gt, Eq]' + let mut token_trees: SmallVec<[_; 2]>; if let TokenTree::Token(token) = &tree { - if let Some((first, second)) = token.kind.break_two_token_op() { - return SmallVec::from_buf([TokenTree::Token(Token::new(first, DUMMY_SP)), TokenTree::Token(Token::new(second, DUMMY_SP))]).into_iter() + let mut out = SmallVec::<[_; 2]>::new(); + out.push(token.clone()); + // Iterate to fixpoint: + // * We start off with 'out' containing our initial token, and `temp` empty + // * If we are able to break any tokens in `out`, then `out` will have + // at least one more element than 'temp', so we will try to break tokens + // again. + // * If we cannot break any tokens in 'out', we are done + loop { + let mut temp = SmallVec::<[_; 2]>::new(); + let mut changed = false; + + for token in out.into_iter() { + if let Some((first, second)) = token.kind.break_two_token_op() { + temp.push(Token::new(first, DUMMY_SP)); + temp.push(Token::new(second, DUMMY_SP)); + changed = true; + } else { + temp.push(token); + } + } + out = temp; + if !changed { + break; + } + } + token_trees = out.into_iter().map(|t| TokenTree::Token(t)).collect(); + if token_trees.len() != 1 { + debug!("break_tokens: broke {:?} to {:?}", tree, token_trees); } + } else { + token_trees = SmallVec::new(); + token_trees.push(tree); } - let mut vec = SmallVec::<[_; 2]>::new(); - vec.push(tree); - vec.into_iter() + token_trees.into_iter() } let mut t1 = self.trees().filter(semantic_tree).flat_map(break_tokens); diff --git a/src/test/ui/proc-macro/break-token-spans.rs b/src/test/ui/proc-macro/break-token-spans.rs new file mode 100644 index 0000000000000..ce8b9ebb4f9d2 --- /dev/null +++ b/src/test/ui/proc-macro/break-token-spans.rs @@ -0,0 +1,16 @@ +// aux-build:test-macros.rs +// Regression test for issues #68489 and #70987 +// Tests that we properly break tokens in `probably_equal_for_proc_macro` +// See #72306 +// +// Note that the weird spacing in this example is critical +// for testing the issue. + +extern crate test_macros; + +#[test_macros::recollect_attr] +fn repro() { + f :: < Vec < _ > > ( ) ; //~ ERROR cannot find + let a: Option>= true; //~ ERROR mismatched +} +fn main() {} diff --git a/src/test/ui/proc-macro/break-token-spans.stderr b/src/test/ui/proc-macro/break-token-spans.stderr new file mode 100644 index 0000000000000..caca973f252f7 --- /dev/null +++ b/src/test/ui/proc-macro/break-token-spans.stderr @@ -0,0 +1,21 @@ +error[E0425]: cannot find function `f` in this scope + --> $DIR/break-token-spans.rs:13:5 + | +LL | f :: < Vec < _ > > ( ) ; + | ^ not found in this scope + +error[E0308]: mismatched types + --> $DIR/break-token-spans.rs:14:32 + | +LL | let a: Option>= true; + | ------------------ ^^^^ expected enum `std::option::Option`, found `bool` + | | + | expected due to this + | + = note: expected enum `std::option::Option>` + found type `bool` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0425. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/proc-macro/turbo-proc-macro.rs b/src/test/ui/proc-macro/turbo-proc-macro.rs deleted file mode 100644 index a255955f38da0..0000000000000 --- a/src/test/ui/proc-macro/turbo-proc-macro.rs +++ /dev/null @@ -1,9 +0,0 @@ -// aux-build:test-macros.rs - -extern crate test_macros; - -#[test_macros::recollect_attr] -fn repro() { - f :: < Vec < _ > > ( ) ; //~ ERROR cannot find -} -fn main() {} diff --git a/src/test/ui/proc-macro/turbo-proc-macro.stderr b/src/test/ui/proc-macro/turbo-proc-macro.stderr deleted file mode 100644 index 85c93b9345c37..0000000000000 --- a/src/test/ui/proc-macro/turbo-proc-macro.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0425]: cannot find function `f` in this scope - --> $DIR/turbo-proc-macro.rs:7:5 - | -LL | f :: < Vec < _ > > ( ) ; - | ^ not found in this scope - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0425`. From 2fd504ce2f4d41fb32a660fe2f68a06756df5b2d Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 17 May 2020 15:22:47 +0100 Subject: [PATCH 6/8] Suggest installing VS Build Tools in more situations When MSVC's `link.exe` wasn't found but another `link.exe` was, the error message given can be impenetrable to many users. The usual suspect is GNU's `link` tool. In this case, inform the user that they may need to install VS build tools. This only applies when Microsoft's link tool is expected. Not `lld-link` or other MSVC compatible linkers. --- src/librustc_codegen_ssa/back/link.rs | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index ce158fb07da95..632ed9750643a 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -609,6 +609,55 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( .note(&format!("{:?}", &cmd)) .note(&escape_string(&output)) .emit(); + + // If MSVC's `link.exe` was expected but the return code + // is not a Microsoft LNK error then suggest a way to fix or + // install the Visual Studio build tools. + if let Some(code) = prog.status.code() { + if sess.target.target.options.is_like_msvc + && flavor == LinkerFlavor::Msvc + // Respect the command line override + && sess.opts.cg.linker.is_none() + // Match exactly "link.exe" + && linker_path.to_str() == Some("link.exe") + // All Microsoft `link.exe` linking error codes are + // four digit numbers in the range 1000 to 9999 inclusive + && (code < 1000 || code > 9999) + { + let is_vs_installed = windows_registry::find_vs_version().is_ok(); + let has_linker = windows_registry::find_tool( + &sess.opts.target_triple.triple(), + "link.exe", + ) + .is_some(); + + sess.note_without_error("`link.exe` returned an unexpected error"); + if is_vs_installed && has_linker { + // the linker is broken + sess.note_without_error( + "the Visual Studio build tools may need to be repaired \ + using the Visual Studio installer", + ); + sess.note_without_error( + "or a necessary component may be missing from the \ + \"C++ build tools\" workload", + ); + } else if is_vs_installed { + // the linker is not installed + sess.note_without_error( + "in the Visual Studio installer, ensure the \ + \"C++ build tools\" workload is selected", + ); + } else { + // visual studio is not installed + sess.note_without_error( + "you may need to install Visual Studio build tools with the \ + \"C++ build tools\" workload", + ); + } + } + } + sess.abort_if_errors(); } info!("linker stderr:\n{}", escape_string(&prog.stderr)); From 633293fc3a54247f4308507632040424356a9e19 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 20 May 2020 15:33:58 -0400 Subject: [PATCH 7/8] Fix tests --- src/test/ui/proc-macro/break-token-spans.rs | 2 +- src/test/ui/suggestions/issue-61963.rs | 1 + src/test/ui/suggestions/issue-61963.stderr | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/ui/proc-macro/break-token-spans.rs b/src/test/ui/proc-macro/break-token-spans.rs index ce8b9ebb4f9d2..59dc3b5043cd7 100644 --- a/src/test/ui/proc-macro/break-token-spans.rs +++ b/src/test/ui/proc-macro/break-token-spans.rs @@ -2,7 +2,7 @@ // Regression test for issues #68489 and #70987 // Tests that we properly break tokens in `probably_equal_for_proc_macro` // See #72306 -// +// // Note that the weird spacing in this example is critical // for testing the issue. diff --git a/src/test/ui/suggestions/issue-61963.rs b/src/test/ui/suggestions/issue-61963.rs index c9d738f5a283e..666fc965f02f5 100644 --- a/src/test/ui/suggestions/issue-61963.rs +++ b/src/test/ui/suggestions/issue-61963.rs @@ -16,6 +16,7 @@ pub struct Qux(T); #[dom_struct] pub struct Foo { + //~^ ERROR trait objects without an explicit `dyn` are deprecated [bare_trait_objects] qux: Qux>, bar: Box, //~^ ERROR trait objects without an explicit `dyn` are deprecated [bare_trait_objects] diff --git a/src/test/ui/suggestions/issue-61963.stderr b/src/test/ui/suggestions/issue-61963.stderr index 0e2eb7616cf9d..62ae5fa3fe54f 100644 --- a/src/test/ui/suggestions/issue-61963.stderr +++ b/src/test/ui/suggestions/issue-61963.stderr @@ -1,5 +1,5 @@ error: trait objects without an explicit `dyn` are deprecated - --> $DIR/issue-61963.rs:20:14 + --> $DIR/issue-61963.rs:21:14 | LL | bar: Box, | ^^^ help: use `dyn`: `dyn Bar` @@ -10,5 +10,11 @@ note: the lint level is defined here LL | #![deny(bare_trait_objects)] | ^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/issue-61963.rs:18:1 + | +LL | pub struct Foo { + | ^^^ help: use `dyn`: `dyn pub` + +error: aborting due to 2 previous errors From c7813ff7d242f7b7340e7bba02ae9dd452ea0f9e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 20 May 2020 23:09:19 +0300 Subject: [PATCH 8/8] llvm: Expose tiny code model to users --- src/doc/rustc/src/codegen-options/index.md | 2 +- src/librustc_codegen_llvm/lib.rs | 2 +- src/librustc_target/spec/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 9180f48bd9439..0b4bb05c1db23 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -21,7 +21,7 @@ specification. Supported values for this option are: - +- `tiny` - Tiny code model. - `small` - Small code model. This is the default model for majority of supported targets. - `kernel` - Kernel code model. - `medium` - Medium code model. diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 6afd4278451f7..55ee660d9f700 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -208,7 +208,7 @@ impl CodegenBackend for LlvmCodegenBackend { } PrintRequest::CodeModels => { println!("Available code models:"); - for name in &["small", "kernel", "medium", "large"] { + for name in &["tiny", "small", "kernel", "medium", "large"] { println!(" {}", name); } println!(); diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 41c2f1d93d2c4..8770e033e0596 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -322,7 +322,7 @@ impl FromStr for CodeModel { fn from_str(s: &str) -> Result { Ok(match s { - // "tiny" => CodeModel::Tiny, // Not exposed to users right now. + "tiny" => CodeModel::Tiny, "small" => CodeModel::Small, "kernel" => CodeModel::Kernel, "medium" => CodeModel::Medium,