From bb398ca59447d8be1d9a9386de0f8ba2ecc3d9c1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 29 Apr 2022 15:23:25 +1000 Subject: [PATCH 01/12] Remove hacks in `make_token_stream`. `make_tokenstream` has three commented hacks, and a comment at the top referring to #67062. These hacks have no observable effect, at least as judged by running the test suite. The hacks were added in #82608, with an explanation [here](https://github.com/rust-lang/rust/pull/82608#issuecomment-812877329). It appears that one of the following is true: (a) they never did anything useful, (b) they do something useful but we have no test coverage for them, or (c) something has changed in the meantime that means they are no longer necessary. This commit removes the hacks and the comments, in the hope that (b) is not true. --- .../rustc_parse/src/parser/attr_wrapper.rs | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index a12621564ab70..66db5bf9d7cf2 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -388,12 +388,6 @@ impl<'a> Parser<'a> { /// Converts a flattened iterator of tokens (including open and close delimiter tokens) /// into a `TokenStream`, creating a `TokenTree::Delimited` for each matching pair /// of open and close delims. -// FIXME(#67062): Currently, we don't parse `Invisible`-delimited groups correctly, -// which can cause us to end up with mismatched `Invisible` delimiters in our -// captured tokens. This function contains several hacks to work around this - -// essentially, we throw away mismatched `Invisible` delimiters when we encounter them. -// Once we properly parse `Invisible` delimiters, they can be captured just like any -// other tokens, and these hacks can be removed. fn make_token_stream( mut iter: impl Iterator, break_last_token: bool, @@ -412,35 +406,10 @@ fn make_token_stream( stack.push(FrameData { open_delim_sp: Some((delim, span)), inner: vec![] }); } FlatToken::Token(Token { kind: TokenKind::CloseDelim(delim), span }) => { - // HACK: If we encounter a mismatched `Invisible` delimiter at the top - // level, just ignore it. - if matches!(delim, Delimiter::Invisible) - && (stack.len() == 1 - || !matches!( - stack.last_mut().unwrap().open_delim_sp.unwrap().0, - Delimiter::Invisible - )) - { - token_and_spacing = iter.next(); - continue; - } let frame_data = stack .pop() .unwrap_or_else(|| panic!("Token stack was empty for token: {:?}", token)); - // HACK: If our current frame has a mismatched opening `Invisible` delimiter, - // merge our current frame with the one above it. That is, transform - // `[ { < first second } third ]` into `[ { first second } third ]` - if !matches!(delim, Delimiter::Invisible) - && matches!(frame_data.open_delim_sp.unwrap().0, Delimiter::Invisible) - { - stack.last_mut().unwrap().inner.extend(frame_data.inner); - // Process our closing delimiter again, this time at the previous - // frame in the stack - token_and_spacing = Some((token, spacing)); - continue; - } - let (open_delim, open_sp) = frame_data.open_delim_sp.unwrap(); assert_eq!( open_delim, delim, @@ -472,13 +441,6 @@ fn make_token_stream( } token_and_spacing = iter.next(); } - // HACK: If we don't have a closing `Invisible` delimiter for our last - // frame, merge the frame with the top-level frame. That is, - // turn `< first second` into `first second` - if stack.len() == 2 && stack[1].open_delim_sp.unwrap().0 == Delimiter::Invisible { - let temp_buf = stack.pop().unwrap(); - stack.last_mut().unwrap().inner.extend(temp_buf.inner); - } let mut final_buf = stack.pop().expect("Missing final buf!"); if break_last_token { let (last_token, spacing) = final_buf.inner.pop().unwrap(); From bb4ecc3fd8d0d8c0fa490feba294e300185862e6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 9 May 2022 17:50:39 -0700 Subject: [PATCH 02/12] rustdoc: correct path to type alias methods --- src/librustdoc/formats/cache.rs | 3 ++- src/test/rustdoc-js-std/asrawfd.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js-std/asrawfd.js diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 30190138750ca..862f0ecd0de02 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -293,7 +293,8 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { ItemType::Trait | ItemType::Struct | ItemType::Union - | ItemType::Enum, + | ItemType::Enum + | ItemType::Typedef, )) => Some(&fqp[..fqp.len() - 1]), Some(..) => Some(&*self.cache.stack), None => None, diff --git a/src/test/rustdoc-js-std/asrawfd.js b/src/test/rustdoc-js-std/asrawfd.js new file mode 100644 index 0000000000000..37168fc493775 --- /dev/null +++ b/src/test/rustdoc-js-std/asrawfd.js @@ -0,0 +1,14 @@ +// exact-match + +const QUERY = 'RawFd::as_raw_fd'; + +const EXPECTED = { + 'others': [ + // Reproduction test for https://github.com/rust-lang/rust/issues/78724 + // Validate that type alias methods get the correct path. + { 'path': 'std::os::unix::io::AsRawFd', 'name': 'as_raw_fd' }, + { 'path': 'std::os::wasi::io::AsRawFd', 'name': 'as_raw_fd' }, + { 'path': 'std::os::linux::process::PidFd', 'name': 'as_raw_fd' }, + { 'path': 'std::os::unix::io::RawFd', 'name': 'as_raw_fd' }, + ], +}; From c7d5e40f7e2ea739c27a652ad6c9d990852500af Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 10 May 2022 20:52:01 +0900 Subject: [PATCH 03/12] Add regression test for #68408 --- .../dead-code/issue-68408-false-positive.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/ui/lint/dead-code/issue-68408-false-positive.rs diff --git a/src/test/ui/lint/dead-code/issue-68408-false-positive.rs b/src/test/ui/lint/dead-code/issue-68408-false-positive.rs new file mode 100644 index 0000000000000..7ee6b5d72889f --- /dev/null +++ b/src/test/ui/lint/dead-code/issue-68408-false-positive.rs @@ -0,0 +1,22 @@ +// check-pass + +// Make sure we don't have any false positives here. + +#![deny(dead_code)] + +enum X { + A { _a: () }, + B { _b: () }, +} +impl X { + fn a() -> X { + X::A { _a: () } + } + fn b() -> Self { + Self::B { _b: () } + } +} + +fn main() { + let (_, _) = (X::a(), X::b()); +} From f82b3a16d56801d7f94a0b917c2af3cca09acdd2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 May 2022 16:40:14 +0200 Subject: [PATCH 04/12] Fix JS error in source code pages --- src/librustdoc/html/static/js/source-script.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 92ecd200081b9..15e3bdf47b2b1 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -1,5 +1,5 @@ // From rust: -/* global search, sourcesIndex */ +/* global sourcesIndex */ // Local js definitions: /* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, browserSupportsHistoryApi */ @@ -69,7 +69,6 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { files.appendChild(file); } } - search.fullPath = fullPath; children.appendChild(files); parent.appendChild(name); parent.appendChild(children); From f9fc7ef0979bf2aafe6bfb67b3f112cfd4fee414 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 May 2022 16:40:32 +0200 Subject: [PATCH 05/12] Remove unused CSS rule --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index eb3ce37e313d0..0f4d842f4336d 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -331,7 +331,6 @@ li { nav.sub { position: relative; font-size: 1rem; - text-transform: uppercase; } .sub-container { From fe4fa53fa81fb0cc189974f700354672a90a6b07 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 May 2022 16:42:34 +0200 Subject: [PATCH 06/12] Clean up rustdoc GUI test --- src/test/rustdoc-gui/sidebar-source-code-display.goml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/rustdoc-gui/sidebar-source-code-display.goml b/src/test/rustdoc-gui/sidebar-source-code-display.goml index 377ee9c6eeff3..0066a38eaa540 100644 --- a/src/test/rustdoc-gui/sidebar-source-code-display.goml +++ b/src/test/rustdoc-gui/sidebar-source-code-display.goml @@ -15,6 +15,5 @@ assert-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1}) assert-css: (".sidebar > *:not(#sidebar-toggle)", {"visibility": "hidden", "opacity": 0}) // Let's expand the sidebar now. click: "#sidebar-toggle" -// Because of the transition CSS, better wait a second before checking. +// Because of the transition CSS, we check by using `wait-for-css` instead of `assert-css`. wait-for-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1}) -assert-css: (".sidebar > *:not(#sidebar-toggle)", {"visibility": "visible", "opacity": 1}) From d63f82e1efbfbe2344ffa3a47602faaee6429d04 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 10 May 2022 14:50:31 +0000 Subject: [PATCH 07/12] Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes --- compiler/rustc_middle/src/ty/fold.rs | 2 +- .../type-alias-impl-trait/constrain_inputs.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/type-alias-impl-trait/constrain_inputs.rs diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 896a8280551d2..a2a450d76f18a 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -1349,7 +1349,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector { // ignore the inputs to a projection, as they may not appear // in the normalized form if self.just_constrained { - if let ty::Projection(..) | ty::Opaque(..) = t.kind() { + if let ty::Projection(..) = t.kind() { return ControlFlow::CONTINUE; } } diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs.rs b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs new file mode 100644 index 0000000000000..c32174288ee68 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs @@ -0,0 +1,17 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +mod foo { + type Ty<'a> = impl Sized; + fn defining(s: &str) -> Ty<'_> { s } + fn execute(ty: Ty<'_>) -> &str { todo!() } +} + +mod bar { + type Ty<'a> = impl FnOnce() -> &'a str; + fn defining(s: &str) -> Ty<'_> { move || s } + fn execute(ty: Ty<'_>) -> &str { ty() } +} + +fn main() {} From 6257bd2f4ef748d9bad0c60d0df5201e824f4fde Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 10 May 2022 08:59:59 -0700 Subject: [PATCH 08/12] rustdoc: clean up method path index This removes a special case that doesn't seem to do anything any more. --- src/librustdoc/formats/cache.rs | 10 +--------- src/test/rustdoc-js/foreign-type-path.js | 9 +++++++++ src/test/rustdoc-js/foreign-type-path.rs | 13 +++++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/test/rustdoc-js/foreign-type-path.js create mode 100644 src/test/rustdoc-js/foreign-type-path.rs diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 862f0ecd0de02..9dc30d8a18925 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -288,15 +288,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { // for where the type was defined. On the other // hand, `paths` always has the right // information if present. - Some(&( - ref fqp, - ItemType::Trait - | ItemType::Struct - | ItemType::Union - | ItemType::Enum - | ItemType::Typedef, - )) => Some(&fqp[..fqp.len() - 1]), - Some(..) => Some(&*self.cache.stack), + Some(&(ref fqp, _)) => Some(&fqp[..fqp.len() - 1]), None => None, }; ((Some(*last), path), true) diff --git a/src/test/rustdoc-js/foreign-type-path.js b/src/test/rustdoc-js/foreign-type-path.js new file mode 100644 index 0000000000000..334761badcab1 --- /dev/null +++ b/src/test/rustdoc-js/foreign-type-path.js @@ -0,0 +1,9 @@ +const QUERY = 'MyForeignType::my_method'; + +const EXPECTED = { + 'others': [ + // Test case for https://github.com/rust-lang/rust/pull/96887#pullrequestreview-967154358 + // Validates that the parent path for a foreign type method is correct. + { 'path': 'foreign_type_path::aaaaaaa::MyForeignType', 'name': 'my_method' }, + ], +}; diff --git a/src/test/rustdoc-js/foreign-type-path.rs b/src/test/rustdoc-js/foreign-type-path.rs new file mode 100644 index 0000000000000..83400104ea77e --- /dev/null +++ b/src/test/rustdoc-js/foreign-type-path.rs @@ -0,0 +1,13 @@ +#![feature(extern_types)] + +pub mod aaaaaaa { + + extern { + pub type MyForeignType; + } + + impl MyForeignType { + pub fn my_method() {} + } + +} From e2dc3967fae1afb42614854a600c7e746d891bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 10 May 2022 20:42:45 +0200 Subject: [PATCH 09/12] simplify length count --- compiler/rustc_mir_transform/src/coverage/spans.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 5b7b343949c02..512d4daf3436b 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -485,7 +485,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> { }) { let merged_prefix_len = self.curr_original_span.lo() - self.curr().span.lo(); let after_macro_bang = - merged_prefix_len + BytePos(visible_macro.as_str().bytes().count() as u32 + 1); + merged_prefix_len + BytePos(visible_macro.as_str().len() as u32 + 1); let mut macro_name_cov = self.curr().clone(); self.curr_mut().span = self.curr().span.with_lo(self.curr().span.lo() + after_macro_bang); From aea3b22b069c27f8875d20977bef43178a4b6d87 Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 10 May 2022 18:29:35 -0300 Subject: [PATCH 10/12] Fix issue #95151 --- src/test/ui/rfc-2091-track-caller/macro-declaration.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/test/ui/rfc-2091-track-caller/macro-declaration.rs diff --git a/src/test/ui/rfc-2091-track-caller/macro-declaration.rs b/src/test/ui/rfc-2091-track-caller/macro-declaration.rs new file mode 100644 index 0000000000000..6ca09fac819d8 --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/macro-declaration.rs @@ -0,0 +1,10 @@ +// check-pass + +// See https://github.com/rust-lang/rust/issues/95151 +#[track_caller] +macro_rules! _foo { + () => {}; +} + +fn main() { +} From 9dc5ac8c4bbf56bd1cae1bcb4f8af245b4b2d67e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 10 May 2022 16:42:48 -0700 Subject: [PATCH 11/12] Ignore order This isn't an ordering test really, anyway... --- src/test/rustdoc-js-std/asrawfd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-js-std/asrawfd.js b/src/test/rustdoc-js-std/asrawfd.js index 37168fc493775..fd228a59099e9 100644 --- a/src/test/rustdoc-js-std/asrawfd.js +++ b/src/test/rustdoc-js-std/asrawfd.js @@ -1,4 +1,4 @@ -// exact-match +// ignore-order const QUERY = 'RawFd::as_raw_fd'; From 3cd8e9866d55ddd962e6bda92018cbf4bc9ee08f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 11 May 2022 10:14:49 +1000 Subject: [PATCH 12/12] Remove some unnecessary invisible delimiter checks. These seem to have no useful effect... they don't seem useful from a code inspection point of view, and they affect anything in the test suite. --- compiler/rustc_parse/src/parser/diagnostics.rs | 3 +-- src/tools/rustfmt/src/parse/macros/mod.rs | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index beffbdc5de410..369650edd57d0 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2109,8 +2109,7 @@ impl<'a> Parser<'a> { brace_depth -= 1; continue; } - } else if self.token == token::Eof || self.eat(&token::CloseDelim(Delimiter::Invisible)) - { + } else if self.token == token::Eof { return; } else { self.bump(); diff --git a/src/tools/rustfmt/src/parse/macros/mod.rs b/src/tools/rustfmt/src/parse/macros/mod.rs index d4dbf21f8cab7..67f3985926e2f 100644 --- a/src/tools/rustfmt/src/parse/macros/mod.rs +++ b/src/tools/rustfmt/src/parse/macros/mod.rs @@ -79,9 +79,7 @@ fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { for &keyword in RUST_KW.iter() { if parser.token.is_keyword(keyword) && parser.look_ahead(1, |t| { - t.kind == TokenKind::Eof - || t.kind == TokenKind::Comma - || t.kind == TokenKind::CloseDelim(Delimiter::Invisible) + t.kind == TokenKind::Eof || t.kind == TokenKind::Comma }) { parser.bump();