Skip to content

Commit 5de331b

Browse files
committed
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
2 parents 2fc3c69 + f382d23 commit 5de331b

File tree

10 files changed

+129
-17
lines changed

10 files changed

+129
-17
lines changed

compiler/rustc_expand/src/expand.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
559559
self.cx.force_mode = orig_force_mode;
560560

561561
// Finally incorporate all the expanded macros into the input AST fragment.
562-
let mut placeholder_expander = PlaceholderExpander::default();
562+
let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
563563
while let Some(expanded_fragments) = expanded_fragments.pop() {
564564
for (expn_id, expanded_fragment) in expanded_fragments.into_iter().rev() {
565565
placeholder_expander
@@ -1341,9 +1341,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13411341
}
13421342
}
13431343

1344+
// The placeholder expander gives ids to statements, so we avoid folding the id here.
13441345
// We don't use `assign_id!` - it will be called when we visit statement's contents
13451346
// (e.g. an expression, item, or local)
1346-
let res = noop_flat_map_stmt(stmt, self);
1347+
let ast::Stmt { id, kind, span } = stmt;
1348+
let res = noop_flat_map_stmt_kind(kind, self)
1349+
.into_iter()
1350+
.map(|kind| ast::Stmt { id, kind, span })
1351+
.collect();
13471352

13481353
self.cx.current_expansion.is_trailing_mac = false;
13491354
res

compiler/rustc_expand/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![feature(proc_macro_internals)]
88
#![feature(proc_macro_span)]
99
#![feature(try_blocks)]
10-
#![recursion_limit = "256"]
1110

1211
#[macro_use]
1312
extern crate rustc_macros;

compiler/rustc_expand/src/placeholders.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::base::ExtCtxt;
12
use crate::expand::{AstFragment, AstFragmentKind};
23

34
use rustc_ast as ast;
@@ -174,12 +175,17 @@ pub fn placeholder(
174175
}
175176
}
176177

177-
#[derive(Default)]
178-
pub struct PlaceholderExpander {
178+
pub struct PlaceholderExpander<'a, 'b> {
179179
expanded_fragments: FxHashMap<ast::NodeId, AstFragment>,
180+
cx: &'a mut ExtCtxt<'b>,
181+
monotonic: bool,
180182
}
181183

182-
impl PlaceholderExpander {
184+
impl<'a, 'b> PlaceholderExpander<'a, 'b> {
185+
pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self {
186+
PlaceholderExpander { cx, expanded_fragments: FxHashMap::default(), monotonic }
187+
}
188+
183189
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) {
184190
fragment.mut_visit_with(self);
185191
self.expanded_fragments.insert(id, fragment);
@@ -190,7 +196,7 @@ impl PlaceholderExpander {
190196
}
191197
}
192198

193-
impl MutVisitor for PlaceholderExpander {
199+
impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
194200
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
195201
if arm.is_placeholder {
196202
self.remove(arm.id).make_arms()
@@ -354,4 +360,15 @@ impl MutVisitor for PlaceholderExpander {
354360
_ => noop_visit_ty(ty, self),
355361
}
356362
}
363+
364+
fn visit_block(&mut self, block: &mut P<ast::Block>) {
365+
noop_visit_block(block, self);
366+
367+
for stmt in block.stmts.iter_mut() {
368+
if self.monotonic {
369+
assert_eq!(stmt.id, ast::DUMMY_NODE_ID);
370+
stmt.id = self.cx.resolver.next_node_id();
371+
}
372+
}
373+
}
357374
}

compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_errors::{Applicability, DiagnosticBuilder};
2+
use rustc_infer::infer::TyCtxtInferExt;
23
use rustc_middle::mir::*;
34
use rustc_middle::ty;
45
use rustc_span::source_map::DesugaringKind;
@@ -409,13 +410,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
409410
);
410411
} else if matches!(span.desugaring_kind(), Some(DesugaringKind::ForLoop(_))) {
411412
let suggest = match self.infcx.tcx.get_diagnostic_item(sym::IntoIterator) {
412-
Some(def_id) => type_known_to_meet_bound_modulo_regions(
413-
&self.infcx,
414-
self.param_env,
415-
self.infcx.tcx.mk_imm_ref(self.infcx.tcx.lifetimes.re_erased, ty),
416-
def_id,
417-
DUMMY_SP,
418-
),
413+
Some(def_id) => self.infcx.tcx.infer_ctxt().enter(|infcx| {
414+
type_known_to_meet_bound_modulo_regions(
415+
&infcx,
416+
self.param_env,
417+
infcx
418+
.tcx
419+
.mk_imm_ref(infcx.tcx.lifetimes.re_erased, infcx.tcx.erase_regions(ty)),
420+
def_id,
421+
DUMMY_SP,
422+
)
423+
}),
419424
_ => false,
420425
};
421426
if suggest {
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This test check for headers text and background colors for the different themes.
2+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
3+
4+
// This is needed so that the text color is computed.
5+
show-text: true
6+
7+
// Ayu theme
8+
local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"}
9+
reload:
10+
11+
assert-css: (".impl", {"color": "rgb(197, 197, 197)", "background-color": "rgba(0, 0, 0, 0)"}, ALL)
12+
assert-css: (".impl .code-header", {"color": "rgb(230, 225, 207)", "background-color": "rgb(15, 20, 25)"}, ALL)
13+
14+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl
15+
assert-css: ("#impl", {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"})
16+
17+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
18+
assert-css: ("#method\.must_use", {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"}, ALL)
19+
20+
// Dark theme
21+
local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"}
22+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
23+
24+
assert-css: (".impl", {"color": "rgb(221, 221, 221)", "background-color": "rgba(0, 0, 0, 0)"}, ALL)
25+
assert-css: (".impl .code-header", {"color": "rgb(221, 221, 221)", "background-color": "rgb(53, 53, 53)"}, ALL)
26+
27+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl
28+
assert-css: ("#impl", {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"})
29+
30+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
31+
assert-css: ("#method\.must_use", {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"}, ALL)
32+
33+
// Light theme
34+
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
35+
reload:
36+
37+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
38+
39+
assert-css: (".impl", {"color": "rgb(0, 0, 0)", "background-color": "rgba(0, 0, 0, 0)"}, ALL)
40+
assert-css: (".impl .code-header", {"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"}, ALL)
41+
42+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl
43+
assert-css: ("#impl", {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"})
44+
45+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
46+
assert-css: ("#method\.must_use", {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"}, ALL)

src/test/rustdoc-gui/search-result-colors.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
goto: file://|DOC_PATH|/test_docs/index.html
2-
// We set the theme so we're sure that the corect values will be used, whatever the computer
2+
// We set the theme so we're sure that the correct values will be used, whatever the computer
33
// this test is running on.
44
local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"}
55
// If the text isn't displayed, the browser doesn't compute color style correctly...

src/test/ui/command/command-create-pidfd.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@ fn has_clone3() -> bool {
1515
let err = (res == -1)
1616
.then(|| Error::last_os_error())
1717
.expect("probe syscall should not succeed");
18-
err.raw_os_error() != Some(libc::ENOSYS)
18+
19+
// If the `clone3` syscall is not implemented in the current kernel version it should return an
20+
// `ENOSYS` error. Docker also blocks the whole syscall inside unprivileged containers, and
21+
// returns `EPERM` (instead of `ENOSYS`) when a program tries to invoke the syscall. Because of
22+
// that we need to check for *both* `ENOSYS` and `EPERM`.
23+
//
24+
// Note that Docker's behavior is breaking other projects (notably glibc), so they're planning
25+
// to update their filtering to return `ENOSYS` in a future release:
26+
//
27+
// https://github.com/moby/moby/issues/42680
28+
//
29+
err.raw_os_error() != Some(libc::ENOSYS) && err.raw_os_error() != Some(libc::EPERM)
1930
}
2031

2132
fn main() {

src/test/ui/suggestions/for-i-in-vec.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ impl Foo {
1515
}
1616
}
1717

18+
const LOADERS: &Vec<&'static u8> = &Vec::new();
19+
20+
pub fn break_code() -> Option<&'static u8> {
21+
for loader in &*LOADERS { //~ ERROR cannot move out of a shared reference
22+
return Some(loader);
23+
}
24+
None
25+
}
26+
1827
fn main() {}

src/test/ui/suggestions/for-i-in-vec.rs

+9
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ impl Foo {
1515
}
1616
}
1717

18+
const LOADERS: &Vec<&'static u8> = &Vec::new();
19+
20+
pub fn break_code() -> Option<&'static u8> {
21+
for loader in *LOADERS { //~ ERROR cannot move out of a shared reference
22+
return Some(loader);
23+
}
24+
None
25+
}
26+
1827
fn main() {}

src/test/ui/suggestions/for-i-in-vec.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ help: consider iterating over a slice of the `HashMap<i32, i32>`'s content
2020
LL | for _ in &self.h {
2121
| +
2222

23-
error: aborting due to 2 previous errors
23+
error[E0507]: cannot move out of a shared reference
24+
--> $DIR/for-i-in-vec.rs:21:19
25+
|
26+
LL | for loader in *LOADERS {
27+
| ^^^^^^^^ move occurs because value has type `Vec<&u8>`, which does not implement the `Copy` trait
28+
|
29+
help: consider iterating over a slice of the `Vec<&u8>`'s content
30+
|
31+
LL | for loader in &*LOADERS {
32+
| +
33+
34+
error: aborting due to 3 previous errors
2435

2536
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)