Auto merge of #88009 - GuillaumeGomez:rollup-f194yyk, r=GuillaumeGomez

Rollup of 4 pull requests

Successful merges:

 - #87795 (Avoid ICE caused by suggestion)
 - #87966 (Fix `command-create-pidfd` test inside unprivileged Docker containers)
 - #87969 (Revert "Rollup merge of #87779 - Aaron1011:stmt-ast-id, r=petrochenkov")
 - #88005 (Add rustdoc GUI test for headers)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2021-08-13 14:16:12 +00:00
commit 5de331ba40
10 changed files with 129 additions and 17 deletions

View File

@ -559,7 +559,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
self.cx.force_mode = orig_force_mode; self.cx.force_mode = orig_force_mode;
// Finally incorporate all the expanded macros into the input AST fragment. // 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() { while let Some(expanded_fragments) = expanded_fragments.pop() {
for (expn_id, expanded_fragment) in expanded_fragments.into_iter().rev() { for (expn_id, expanded_fragment) in expanded_fragments.into_iter().rev() {
placeholder_expander 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 // We don't use `assign_id!` - it will be called when we visit statement's contents
// (e.g. an expression, item, or local) // (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; self.cx.current_expansion.is_trailing_mac = false;
res res

View File

@ -7,7 +7,6 @@
#![feature(proc_macro_internals)] #![feature(proc_macro_internals)]
#![feature(proc_macro_span)] #![feature(proc_macro_span)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![recursion_limit = "256"]
#[macro_use] #[macro_use]
extern crate rustc_macros; extern crate rustc_macros;

View File

@ -1,3 +1,4 @@
use crate::base::ExtCtxt;
use crate::expand::{AstFragment, AstFragmentKind}; use crate::expand::{AstFragment, AstFragmentKind};
use rustc_ast as ast; use rustc_ast as ast;
@ -174,12 +175,17 @@ pub fn placeholder(
} }
} }
#[derive(Default)] pub struct PlaceholderExpander<'a, 'b> {
pub struct PlaceholderExpander {
expanded_fragments: FxHashMap<ast::NodeId, AstFragment>, expanded_fragments: FxHashMap<ast::NodeId, AstFragment>,
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) { pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) {
fragment.mut_visit_with(self); fragment.mut_visit_with(self);
self.expanded_fragments.insert(id, fragment); 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]> { fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
if arm.is_placeholder { if arm.is_placeholder {
self.remove(arm.id).make_arms() self.remove(arm.id).make_arms()
@ -354,4 +360,15 @@ impl MutVisitor for PlaceholderExpander {
_ => noop_visit_ty(ty, self), _ => noop_visit_ty(ty, self),
} }
} }
fn visit_block(&mut self, block: &mut P<ast::Block>) {
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();
}
}
}
} }

View File

@ -1,4 +1,5 @@
use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_span::source_map::DesugaringKind; 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(_))) { } else if matches!(span.desugaring_kind(), Some(DesugaringKind::ForLoop(_))) {
let suggest = match self.infcx.tcx.get_diagnostic_item(sym::IntoIterator) { let suggest = match self.infcx.tcx.get_diagnostic_item(sym::IntoIterator) {
Some(def_id) => type_known_to_meet_bound_modulo_regions( Some(def_id) => self.infcx.tcx.infer_ctxt().enter(|infcx| {
&self.infcx, type_known_to_meet_bound_modulo_regions(
self.param_env, &infcx,
self.infcx.tcx.mk_imm_ref(self.infcx.tcx.lifetimes.re_erased, ty), self.param_env,
def_id, infcx
DUMMY_SP, .tcx
), .mk_imm_ref(infcx.tcx.lifetimes.re_erased, infcx.tcx.erase_regions(ty)),
def_id,
DUMMY_SP,
)
}),
_ => false, _ => false,
}; };
if suggest { if suggest {

View File

@ -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)

View File

@ -1,5 +1,5 @@
goto: file://|DOC_PATH|/test_docs/index.html 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. // this test is running on.
local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"} 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... // If the text isn't displayed, the browser doesn't compute color style correctly...

View File

@ -15,7 +15,18 @@ fn has_clone3() -> bool {
let err = (res == -1) let err = (res == -1)
.then(|| Error::last_os_error()) .then(|| Error::last_os_error())
.expect("probe syscall should not succeed"); .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() { fn main() {

View File

@ -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() {} fn main() {}

View File

@ -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() {} fn main() {}

View File

@ -20,6 +20,17 @@ help: consider iterating over a slice of the `HashMap<i32, i32>`'s content
LL | for _ in &self.h { 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`. For more information about this error, try `rustc --explain E0507`.