Skip to content

Rollup of 4 pull requests #88009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 13, 2021
9 changes: 7 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#![feature(proc_macro_internals)]
#![feature(proc_macro_span)]
#![feature(try_blocks)]
#![recursion_limit = "256"]

#[macro_use]
extern crate rustc_macros;
Expand Down
25 changes: 21 additions & 4 deletions compiler/rustc_expand/src/placeholders.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::base::ExtCtxt;
use crate::expand::{AstFragment, AstFragmentKind};

use rustc_ast as ast;
Expand Down Expand Up @@ -174,12 +175,17 @@ pub fn placeholder(
}
}

#[derive(Default)]
pub struct PlaceholderExpander {
pub struct PlaceholderExpander<'a, 'b> {
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) {
fragment.mut_visit_with(self);
self.expanded_fragments.insert(id, fragment);
Expand All @@ -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()
Expand Down Expand Up @@ -354,4 +360,15 @@ impl MutVisitor for PlaceholderExpander {
_ => 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();
}
}
}
}
19 changes: 12 additions & 7 deletions compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
46 changes: 46 additions & 0 deletions src/test/rustdoc-gui/headers-color.goml
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/search-result-colors.goml
Original file line number Diff line number Diff line change
@@ -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...
Expand Down
13 changes: 12 additions & 1 deletion src/test/ui/command/command-create-pidfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/suggestions/for-i-in-vec.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
9 changes: 9 additions & 0 deletions src/test/ui/suggestions/for-i-in-vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
13 changes: 12 additions & 1 deletion src/test/ui/suggestions/for-i-in-vec.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ help: consider iterating over a slice of the `HashMap<i32, i32>`'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`.