Skip to content

Commit d2731d8

Browse files
committed
Auto merge of rust-lang#82654 - JohnTitor:rollup-nkcdkzp, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#82309 (Propagate RUSTDOCFLAGS in the environment when documenting) - rust-lang#82403 (rustbuild: print out env vars on verbose rustc invocations) - rust-lang#82507 (Rename the `tidy` binary to `rust-tidy`) - rust-lang#82531 (Add GUI tests) - rust-lang#82532 (Add `build.print_step_rusage` to config.toml) - rust-lang#82543 (fix env var name in CI) - rust-lang#82622 (Propagate `--test-args` for `x.py test src/tools/cargo`) - rust-lang#82628 (Try to clarify GlobalAlloc::realloc documentation comment.) - rust-lang#82630 (Fix a typo in the `find_anon_type` doc) - rust-lang#82643 (Add more proc-macro attribute tests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 05c3001 + e2d8efb commit d2731d8

29 files changed

+2428
-391
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
run: "echo \"[CI_PR_NUMBER=$num]\""
6464
env:
6565
num: "${{ github.event.number }}"
66-
if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'"
66+
if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'"
6767
- name: add extra environment variables
6868
run: src/ci/scripts/setup-environment.sh
6969
env:
@@ -425,7 +425,7 @@ jobs:
425425
run: "echo \"[CI_PR_NUMBER=$num]\""
426426
env:
427427
num: "${{ github.event.number }}"
428-
if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'"
428+
if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'"
429429
- name: add extra environment variables
430430
run: src/ci/scripts/setup-environment.sh
431431
env:
@@ -532,7 +532,7 @@ jobs:
532532
run: "echo \"[CI_PR_NUMBER=$num]\""
533533
env:
534534
num: "${{ github.event.number }}"
535-
if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'"
535+
if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'"
536536
- name: add extra environment variables
537537
run: src/ci/scripts/setup-environment.sh
538538
env:

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::ty::{self, Region, TyCtxt};
1919
/// { x.push(y); }
2020
/// ```
2121
/// The function returns the nested type corresponding to the anonymous region
22-
/// for e.g., `&u8` and Vec<`&u8`.
22+
/// for e.g., `&u8` and `Vec<&u8>`.
2323
pub(crate) fn find_anon_type(
2424
tcx: TyCtxt<'tcx>,
2525
region: Region<'tcx>,

config.toml.example

+6
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ changelog-seen = 2
290290
# tracking over time)
291291
#print-step-timings = false
292292

293+
# Print out resource usage data for each rustbuild step, as defined by the Unix
294+
# struct rusage. (Note that this setting is completely unstable: the data it
295+
# captures, what platforms it supports, the format of its associated output, and
296+
# this setting's very existence, are all subject to change.)
297+
#print-step-rusage = false
298+
293299
# =============================================================================
294300
# General install configuration options
295301
# =============================================================================

library/core/src/alloc/global.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub unsafe trait GlobalAlloc {
122122
/// this allocator,
123123
///
124124
/// * `layout` must be the same layout that was used
125-
/// to allocate that block of memory,
125+
/// to allocate that block of memory.
126126
#[stable(feature = "global_alloc", since = "1.28.0")]
127127
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);
128128

@@ -167,7 +167,10 @@ pub unsafe trait GlobalAlloc {
167167
/// and should be considered unusable (unless of course it was
168168
/// transferred back to the caller again via the return value of
169169
/// this method). The new memory block is allocated with `layout`, but
170-
/// with the `size` updated to `new_size`.
170+
/// with the `size` updated to `new_size`. This new layout should be
171+
/// used when deallocating the new memory block with `dealloc`. The range
172+
/// `0..min(layout.size(), new_size)` of the new memory block is
173+
/// guaranteed to have the same values as the original block.
171174
///
172175
/// If this method returns null, then ownership of the memory
173176
/// block has not been transferred to this allocator, and the

src/bootstrap/bin/rustc.rs

+85-3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ fn main() {
139139
}
140140

141141
if verbose > 1 {
142+
let rust_env_vars =
143+
env::vars().filter(|(k, _)| k.starts_with("RUST") || k.starts_with("CARGO"));
144+
for (i, (k, v)) in rust_env_vars.enumerate() {
145+
eprintln!("rustc env[{}]: {:?}={:?}", i, k, v);
146+
}
147+
eprintln!("rustc working directory: {}", env::current_dir().unwrap().display());
142148
eprintln!(
143149
"rustc command: {:?}={:?} {:?}",
144150
bootstrap::util::dylib_path_var(),
@@ -155,16 +161,24 @@ fn main() {
155161
cmd.status().expect(&errmsg)
156162
};
157163

158-
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() {
164+
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some()
165+
|| env::var_os("RUSTC_PRINT_STEP_RUSAGE").is_some()
166+
{
159167
if let Some(crate_name) = crate_name {
160168
let dur = start.elapsed();
161169
let is_test = args.iter().any(|a| a == "--test");
170+
// If the user requested resource usage data, then
171+
// include that in addition to the timing output.
172+
let rusage_data =
173+
env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data());
162174
eprintln!(
163-
"[RUSTC-TIMING] {} test:{} {}.{:03}",
175+
"[RUSTC-TIMING] {} test:{} {}.{:03}{}{}",
164176
crate_name,
165177
is_test,
166178
dur.as_secs(),
167-
dur.subsec_millis()
179+
dur.subsec_millis(),
180+
if rusage_data.is_some() { " " } else { "" },
181+
rusage_data.unwrap_or(String::new()),
168182
);
169183
}
170184
}
@@ -192,3 +206,71 @@ fn main() {
192206
}
193207
}
194208
}
209+
210+
#[cfg(not(unix))]
211+
/// getrusage is not available on non-unix platforms. So for now, we do not
212+
/// bother trying to make a shim for it.
213+
fn format_rusage_data() -> Option<String> {
214+
None
215+
}
216+
217+
#[cfg(unix)]
218+
/// Tries to build a string with human readable data for several of the rusage
219+
/// fields. Note that we are focusing mainly on data that we believe to be
220+
/// supplied on Linux (the `rusage` struct has other fields in it but they are
221+
/// currently unsupported by Linux).
222+
fn format_rusage_data() -> Option<String> {
223+
let rusage: libc::rusage = unsafe {
224+
let mut recv = std::mem::zeroed();
225+
// -1 is RUSAGE_CHILDREN, which means to get the rusage for all children
226+
// (and grandchildren, etc) processes that have respectively terminated
227+
// and been waited for.
228+
let retval = libc::getrusage(-1, &mut recv);
229+
if retval != 0 {
230+
return None;
231+
}
232+
recv
233+
};
234+
// Mac OS X reports the maxrss in bytes, not kb.
235+
let divisor = if env::consts::OS == "macos" { 1024 } else { 1 };
236+
let maxrss = rusage.ru_maxrss + (divisor - 1) / divisor;
237+
238+
let mut init_str = format!(
239+
"user: {USER_SEC}.{USER_USEC:03} \
240+
sys: {SYS_SEC}.{SYS_USEC:03} \
241+
max rss (kb): {MAXRSS}",
242+
USER_SEC = rusage.ru_utime.tv_sec,
243+
USER_USEC = rusage.ru_utime.tv_usec,
244+
SYS_SEC = rusage.ru_stime.tv_sec,
245+
SYS_USEC = rusage.ru_stime.tv_usec,
246+
MAXRSS = maxrss
247+
);
248+
249+
// The remaining rusage stats vary in platform support. So we treat
250+
// uniformly zero values in each category as "not worth printing", since it
251+
// either means no events of that type occurred, or that the platform
252+
// does not support it.
253+
254+
let minflt = rusage.ru_minflt;
255+
let majflt = rusage.ru_majflt;
256+
if minflt != 0 || majflt != 0 {
257+
init_str.push_str(&format!(" page reclaims: {} page faults: {}", minflt, majflt));
258+
}
259+
260+
let inblock = rusage.ru_inblock;
261+
let oublock = rusage.ru_oublock;
262+
if inblock != 0 || oublock != 0 {
263+
init_str.push_str(&format!(" fs block inputs: {} fs block outputs: {}", inblock, oublock));
264+
}
265+
266+
let nvcsw = rusage.ru_nvcsw;
267+
let nivcsw = rusage.ru_nivcsw;
268+
if nvcsw != 0 || nivcsw != 0 {
269+
init_str.push_str(&format!(
270+
" voluntary ctxt switches: {} involuntary ctxt switches: {}",
271+
nvcsw, nivcsw
272+
));
273+
}
274+
275+
return Some(init_str);
276+
}

src/bootstrap/builder.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@ impl<'a> Builder<'a> {
939939
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
940940
// #71458.
941941
let mut rustdocflags = rustflags.clone();
942+
rustdocflags.propagate_cargo_env("RUSTDOCFLAGS");
943+
if stage == 0 {
944+
rustdocflags.env("RUSTDOCFLAGS_BOOTSTRAP");
945+
} else {
946+
rustdocflags.env("RUSTDOCFLAGS_NOT_BOOTSTRAP");
947+
}
942948

943949
if let Ok(s) = env::var("CARGOFLAGS") {
944950
cargo.args(s.split_whitespace());
@@ -1259,6 +1265,10 @@ impl<'a> Builder<'a> {
12591265
cargo.env("RUSTC_PRINT_STEP_TIMINGS", "1");
12601266
}
12611267

1268+
if self.config.print_step_rusage {
1269+
cargo.env("RUSTC_PRINT_STEP_RUSAGE", "1");
1270+
}
1271+
12621272
if self.config.backtrace_on_ice {
12631273
cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
12641274
}
@@ -1544,21 +1554,27 @@ impl<'a> Builder<'a> {
15441554
mod tests;
15451555

15461556
#[derive(Debug, Clone)]
1547-
struct Rustflags(String);
1557+
struct Rustflags(String, TargetSelection);
15481558

15491559
impl Rustflags {
15501560
fn new(target: TargetSelection) -> Rustflags {
1551-
let mut ret = Rustflags(String::new());
1561+
let mut ret = Rustflags(String::new(), target);
1562+
ret.propagate_cargo_env("RUSTFLAGS");
1563+
ret
1564+
}
15521565

1566+
/// By default, cargo will pick up on various variables in the environment. However, bootstrap
1567+
/// reuses those variables to pass additional flags to rustdoc, so by default they get overriden.
1568+
/// Explicitly add back any previous value in the environment.
1569+
///
1570+
/// `prefix` is usually `RUSTFLAGS` or `RUSTDOCFLAGS`.
1571+
fn propagate_cargo_env(&mut self, prefix: &str) {
15531572
// Inherit `RUSTFLAGS` by default ...
1554-
ret.env("RUSTFLAGS");
1573+
self.env(prefix);
15551574

1556-
// ... and also handle target-specific env RUSTFLAGS if they're
1557-
// configured.
1558-
let target_specific = format!("CARGO_TARGET_{}_RUSTFLAGS", crate::envify(&target.triple));
1559-
ret.env(&target_specific);
1560-
1561-
ret
1575+
// ... and also handle target-specific env RUSTFLAGS if they're configured.
1576+
let target_specific = format!("CARGO_TARGET_{}_{}", crate::envify(&self.1.triple), prefix);
1577+
self.env(&target_specific);
15621578
}
15631579

15641580
fn env(&mut self, env: &str) {

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub struct Config {
161161
pub verbose_tests: bool,
162162
pub save_toolstates: Option<PathBuf>,
163163
pub print_step_timings: bool,
164+
pub print_step_rusage: bool,
164165
pub missing_tools: bool,
165166

166167
// Fallback musl-root for all targets
@@ -380,6 +381,7 @@ struct Build {
380381
configure_args: Option<Vec<String>>,
381382
local_rebuild: Option<bool>,
382383
print_step_timings: Option<bool>,
384+
print_step_rusage: Option<bool>,
383385
check_stage: Option<u32>,
384386
doc_stage: Option<u32>,
385387
build_stage: Option<u32>,
@@ -679,6 +681,7 @@ impl Config {
679681
set(&mut config.configure_args, build.configure_args);
680682
set(&mut config.local_rebuild, build.local_rebuild);
681683
set(&mut config.print_step_timings, build.print_step_timings);
684+
set(&mut config.print_step_rusage, build.print_step_rusage);
682685

683686
// See https://github.com/rust-lang/compiler-team/issues/326
684687
config.stage = match config.cmd {

src/bootstrap/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl Step for Cargo {
212212
if !builder.fail_fast {
213213
cargo.arg("--no-fail-fast");
214214
}
215+
cargo.arg("--").args(builder.config.cmd.test_args());
215216

216217
// Don't run cross-compile tests, we may not have cross-compiled libstd libs
217218
// available.

src/bootstrap/tool.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Step for ToolBuild {
4747
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
4848
let compiler = self.compiler;
4949
let target = self.target;
50-
let tool = self.tool;
50+
let mut tool = self.tool;
5151
let path = self.path;
5252
let is_optional_tool = self.is_optional_tool;
5353

@@ -208,6 +208,12 @@ impl Step for ToolBuild {
208208
None
209209
}
210210
} else {
211+
// HACK(#82501): on Windows, the tools directory gets added to PATH when running tests, and
212+
// compiletest confuses HTML tidy with the in-tree tidy. Name the in-tree tidy something
213+
// different so the problem doesn't come up.
214+
if tool == "tidy" {
215+
tool = "rust-tidy";
216+
}
211217
let cargo_out =
212218
builder.cargo_out(compiler, self.mode, target).join(exe(tool, compiler.host));
213219
let bin = builder.tools_dir(compiler).join(exe(tool, compiler.host));

src/ci/github-actions/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ x--expand-yaml-anchors--remove:
110110
run: echo "[CI_PR_NUMBER=$num]"
111111
env:
112112
num: ${{ github.event.number }}
113-
if: success() && !env.SKIP_JOBS && github.event_name == 'pull_request'
113+
if: success() && !env.SKIP_JOB && github.event_name == 'pull_request'
114114

115115
- name: add extra environment variables
116116
run: src/ci/scripts/setup-environment.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test to ensure that you can click on the search input, whatever the width.
2+
// The PR which fixed it is: https://github.com/rust-lang/rust/pull/81592
3+
goto: file://|DOC_PATH|/index.html
4+
size: (463, 700)
5+
// We first check that the search input isn't already focused.
6+
assert-false: ("input.search-input:focus")
7+
click: "input.search-input"
8+
reload:
9+
size: (750, 700)
10+
click: "input.search-input"
11+
assert: ("input.search-input:focus")

src/test/rustdoc-gui/shortcuts.goml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Check that the various shortcuts are working.
2+
goto: file://|DOC_PATH|/index.html
3+
// We first check that the search input isn't already focused.
4+
assert-false: "input.search-input:focus"
5+
press-key: "s"
6+
assert: "input.search-input:focus"
7+
press-key: "Escape"
8+
assert-false: "input.search-input:focus"
9+
// We now check for the help popup.
10+
press-key: "?"
11+
assert: ("#help", {"display": "flex"})
12+
assert-false: "#help.hidden"
13+
press-key: "Escape"
14+
assert: ("#help.hidden", {"display": "none"})
15+
// Check for the themes list.
16+
assert: ("#theme-choices", {"display": "none"})
17+
press-key: "t"
18+
assert: ("#theme-choices", {"display": "block"})
19+
press-key: "t"
20+
// We ensure that 't' hides back the menu.
21+
assert: ("#theme-choices", {"display": "none"})
22+
press-key: "t"
23+
assert: ("#theme-choices", {"display": "block"})
24+
press-key: "Escape"
25+
// We ensure that 'Escape' hides the menu too.
26+
assert: ("#theme-choices", {"display": "none"})
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-pass
2+
// compile-flags: -Z span-debug --error-format human
3+
// aux-build:test-macros.rs
4+
5+
#![feature(stmt_expr_attributes)]
6+
#![feature(custom_inner_attributes)]
7+
#![feature(rustc_attrs)]
8+
9+
#![no_std] // Don't load unnecessary hygiene information from std
10+
extern crate std;
11+
12+
#[macro_use]
13+
extern crate test_macros;
14+
15+
trait MyTrait<T> {}
16+
struct MyStruct<const N: bool>;
17+
18+
#[print_attr]
19+
fn foo<T: MyTrait<MyStruct<{ true }>>>() {}
20+
21+
impl<T> MyTrait<T> for MyStruct<{true}> {
22+
#![print_attr]
23+
#![rustc_dummy]
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)