From a0bf7d2cd3751de2b49ec66701aaa7cc41345c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 5 Aug 2021 06:41:08 -0700 Subject: [PATCH 1/4] Avoid ICE caused by suggestion When suggesting dereferencing something that can be iterable in a `for` loop, erase lifetimes and use a fresh `ty::ParamEnv` to avoid 'region constraints already solved' panic. Fix #87657. --- .../borrow_check/diagnostics/move_errors.rs | 19 ++++++++++++------- src/test/ui/suggestions/for-i-in-vec.fixed | 9 +++++++++ src/test/ui/suggestions/for-i-in-vec.rs | 9 +++++++++ src/test/ui/suggestions/for-i-in-vec.stderr | 13 ++++++++++++- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs index 2be23159bf563..66e06325fa982 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs @@ -1,4 +1,5 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::*; use rustc_middle::ty; use rustc_span::source_map::DesugaringKind; @@ -409,13 +410,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ); } else if matches!(span.desugaring_kind(), Some(DesugaringKind::ForLoop(_))) { let suggest = match self.infcx.tcx.get_diagnostic_item(sym::IntoIterator) { - Some(def_id) => type_known_to_meet_bound_modulo_regions( - &self.infcx, - self.param_env, - self.infcx.tcx.mk_imm_ref(self.infcx.tcx.lifetimes.re_erased, ty), - def_id, - DUMMY_SP, - ), + Some(def_id) => self.infcx.tcx.infer_ctxt().enter(|infcx| { + type_known_to_meet_bound_modulo_regions( + &infcx, + self.param_env, + infcx + .tcx + .mk_imm_ref(infcx.tcx.lifetimes.re_erased, infcx.tcx.erase_regions(ty)), + def_id, + DUMMY_SP, + ) + }), _ => false, }; if suggest { diff --git a/src/test/ui/suggestions/for-i-in-vec.fixed b/src/test/ui/suggestions/for-i-in-vec.fixed index 223ddf0f0ad2a..4f2007befffa1 100644 --- a/src/test/ui/suggestions/for-i-in-vec.fixed +++ b/src/test/ui/suggestions/for-i-in-vec.fixed @@ -15,4 +15,13 @@ impl Foo { } } +const LOADERS: &Vec<&'static u8> = &Vec::new(); + +pub fn break_code() -> Option<&'static u8> { + for loader in &*LOADERS { //~ ERROR cannot move out of a shared reference + return Some(loader); + } + None +} + fn main() {} diff --git a/src/test/ui/suggestions/for-i-in-vec.rs b/src/test/ui/suggestions/for-i-in-vec.rs index 7942698cc8eff..55fc7ad4e373d 100644 --- a/src/test/ui/suggestions/for-i-in-vec.rs +++ b/src/test/ui/suggestions/for-i-in-vec.rs @@ -15,4 +15,13 @@ impl Foo { } } +const LOADERS: &Vec<&'static u8> = &Vec::new(); + +pub fn break_code() -> Option<&'static u8> { + for loader in *LOADERS { //~ ERROR cannot move out of a shared reference + return Some(loader); + } + None +} + fn main() {} diff --git a/src/test/ui/suggestions/for-i-in-vec.stderr b/src/test/ui/suggestions/for-i-in-vec.stderr index 49cee6abc4eb4..c39363f762bdd 100644 --- a/src/test/ui/suggestions/for-i-in-vec.stderr +++ b/src/test/ui/suggestions/for-i-in-vec.stderr @@ -20,6 +20,17 @@ help: consider iterating over a slice of the `HashMap`'s content LL | for _ in &self.h { | + -error: aborting due to 2 previous errors +error[E0507]: cannot move out of a shared reference + --> $DIR/for-i-in-vec.rs:21:19 + | +LL | for loader in *LOADERS { + | ^^^^^^^^ move occurs because value has type `Vec<&u8>`, which does not implement the `Copy` trait + | +help: consider iterating over a slice of the `Vec<&u8>`'s content + | +LL | for loader in &*LOADERS { + | + + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0507`. From 7a7d2d1779d47cba5686136047e591346ca9f097 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 12 Aug 2021 11:28:06 +0200 Subject: [PATCH 2/4] fix command-create-pidfd test inside unprivileged docker containers --- src/test/ui/command/command-create-pidfd.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/ui/command/command-create-pidfd.rs b/src/test/ui/command/command-create-pidfd.rs index 93321ac536ab9..4df443c66d65b 100644 --- a/src/test/ui/command/command-create-pidfd.rs +++ b/src/test/ui/command/command-create-pidfd.rs @@ -15,7 +15,18 @@ fn has_clone3() -> bool { let err = (res == -1) .then(|| Error::last_os_error()) .expect("probe syscall should not succeed"); - err.raw_os_error() != Some(libc::ENOSYS) + + // If the `clone3` syscall is not implemented in the current kernel version it should return an + // `ENOSYS` error. Docker also blocks the whole syscall inside unprivileged containers, and + // returns `EPERM` (instead of `ENOSYS`) when a program tries to invoke the syscall. Because of + // that we need to check for *both* `ENOSYS` and `EPERM`. + // + // Note that Docker's behavior is breaking other projects (notably glibc), so they're planning + // to update their filtering to return `ENOSYS` in a future release: + // + // https://github.com/moby/moby/issues/42680 + // + err.raw_os_error() != Some(libc::ENOSYS) && err.raw_os_error() != Some(libc::EPERM) } fn main() { From cfc3fee952589dc5140a25dfe28b07f5d4fd7aa0 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 12 Aug 2021 08:23:56 -0500 Subject: [PATCH 3/4] Revert "Rollup merge of #87779 - Aaron1011:stmt-ast-id, r=petrochenkov" Fixes #87877 This change interacts badly with `noop_flat_map_stmt`, which synthesizes multiple statements with the same `NodeId`. I'm working on a better fix that will still allow us to remove this special case. For now, let's revert the change to fix the ICE. This reverts commit a4262cc9841d91d48ef994b36eab323e615a7083, reversing changes made to 8ee962f88e1be7e29482b13c7776c26b98a93bf7. --- compiler/rustc_expand/src/expand.rs | 9 ++++++-- compiler/rustc_expand/src/lib.rs | 1 - compiler/rustc_expand/src/placeholders.rs | 25 +++++++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 3629e668fa9f8..09beda3348374 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -559,7 +559,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { self.cx.force_mode = orig_force_mode; // Finally incorporate all the expanded macros into the input AST fragment. - let mut placeholder_expander = PlaceholderExpander::default(); + let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic); while let Some(expanded_fragments) = expanded_fragments.pop() { for (expn_id, expanded_fragment) in expanded_fragments.into_iter().rev() { placeholder_expander @@ -1341,9 +1341,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } } + // The placeholder expander gives ids to statements, so we avoid folding the id here. // We don't use `assign_id!` - it will be called when we visit statement's contents // (e.g. an expression, item, or local) - let res = noop_flat_map_stmt(stmt, self); + let ast::Stmt { id, kind, span } = stmt; + let res = noop_flat_map_stmt_kind(kind, self) + .into_iter() + .map(|kind| ast::Stmt { id, kind, span }) + .collect(); self.cx.current_expansion.is_trailing_mac = false; res diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index 43287984050d4..efed41de23a89 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -7,7 +7,6 @@ #![feature(proc_macro_internals)] #![feature(proc_macro_span)] #![feature(try_blocks)] -#![recursion_limit = "256"] #[macro_use] extern crate rustc_macros; diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 8e78fcbb8dbc1..6586ba138fb99 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -1,3 +1,4 @@ +use crate::base::ExtCtxt; use crate::expand::{AstFragment, AstFragmentKind}; use rustc_ast as ast; @@ -174,12 +175,17 @@ pub fn placeholder( } } -#[derive(Default)] -pub struct PlaceholderExpander { +pub struct PlaceholderExpander<'a, 'b> { expanded_fragments: FxHashMap, + cx: &'a mut ExtCtxt<'b>, + monotonic: bool, } -impl PlaceholderExpander { +impl<'a, 'b> PlaceholderExpander<'a, 'b> { + pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self { + PlaceholderExpander { cx, expanded_fragments: FxHashMap::default(), monotonic } + } + pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) { fragment.mut_visit_with(self); self.expanded_fragments.insert(id, fragment); @@ -190,7 +196,7 @@ impl PlaceholderExpander { } } -impl MutVisitor for PlaceholderExpander { +impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> { fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { if arm.is_placeholder { self.remove(arm.id).make_arms() @@ -354,4 +360,15 @@ impl MutVisitor for PlaceholderExpander { _ => noop_visit_ty(ty, self), } } + + fn visit_block(&mut self, block: &mut P) { + noop_visit_block(block, self); + + for stmt in block.stmts.iter_mut() { + if self.monotonic { + assert_eq!(stmt.id, ast::DUMMY_NODE_ID); + stmt.id = self.cx.resolver.next_node_id(); + } + } + } } From a3d3df4ba674aab0fd71744e6d0bdccc0c4c8ae4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 13 Aug 2021 14:23:13 +0200 Subject: [PATCH 4/4] Add rustdoc GUI test for headers --- src/test/rustdoc-gui/headers-color.goml | 46 +++++++++++++++++++ .../rustdoc-gui/search-result-colors.goml | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-gui/headers-color.goml diff --git a/src/test/rustdoc-gui/headers-color.goml b/src/test/rustdoc-gui/headers-color.goml new file mode 100644 index 0000000000000..b5be31bd2cc0a --- /dev/null +++ b/src/test/rustdoc-gui/headers-color.goml @@ -0,0 +1,46 @@ +// This test check for headers text and background colors for the different themes. +goto: file://|DOC_PATH|/test_docs/struct.Foo.html + +// This is needed so that the text color is computed. +show-text: true + +// Ayu theme +local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"} +reload: + +assert-css: (".impl", {"color": "rgb(197, 197, 197)", "background-color": "rgba(0, 0, 0, 0)"}, ALL) +assert-css: (".impl .code-header", {"color": "rgb(230, 225, 207)", "background-color": "rgb(15, 20, 25)"}, ALL) + +goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl +assert-css: ("#impl", {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"}) + +goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use +assert-css: ("#method\.must_use", {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"}, ALL) + +// Dark theme +local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"} +goto: file://|DOC_PATH|/test_docs/struct.Foo.html + +assert-css: (".impl", {"color": "rgb(221, 221, 221)", "background-color": "rgba(0, 0, 0, 0)"}, ALL) +assert-css: (".impl .code-header", {"color": "rgb(221, 221, 221)", "background-color": "rgb(53, 53, 53)"}, ALL) + +goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl +assert-css: ("#impl", {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"}) + +goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use +assert-css: ("#method\.must_use", {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"}, ALL) + +// Light theme +local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} +reload: + +goto: file://|DOC_PATH|/test_docs/struct.Foo.html + +assert-css: (".impl", {"color": "rgb(0, 0, 0)", "background-color": "rgba(0, 0, 0, 0)"}, ALL) +assert-css: (".impl .code-header", {"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"}, ALL) + +goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl +assert-css: ("#impl", {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"}) + +goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use +assert-css: ("#method\.must_use", {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"}, ALL) diff --git a/src/test/rustdoc-gui/search-result-colors.goml b/src/test/rustdoc-gui/search-result-colors.goml index 6ed62006151a2..daf8bc9dea350 100644 --- a/src/test/rustdoc-gui/search-result-colors.goml +++ b/src/test/rustdoc-gui/search-result-colors.goml @@ -1,5 +1,5 @@ goto: file://|DOC_PATH|/test_docs/index.html -// We set the theme so we're sure that the corect values will be used, whatever the computer +// We set the theme so we're sure that the correct values will be used, whatever the computer // this test is running on. local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"} // If the text isn't displayed, the browser doesn't compute color style correctly...