Skip to content

Commit f85ab54

Browse files
committed
Auto merge of #112184 - matthiaskrgr:rollup-tlh72el, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #111496 (Extra context for unreachable_pub lint) - #111802 (Make `x test --dry-run` less verbose) - #112133 (Migrate GUI colors test to original CSS color format) - #112146 (Fix `src/etc/pre-push.sh` when `build.locked-deps` is already set) - #112147 (add inline-const test for elided lifetimes being infer vars) - #112154 (Fix bug in utf16_to_utf8 for zero length strings) - #112155 (Improve CGU debug printing.) - #112173 (Mention GuillaumeGomez in case GUI tests are updated) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d59363a + d505702 commit f85ab54

File tree

11 files changed

+92
-37
lines changed

11 files changed

+92
-37
lines changed

compiler/rustc_lint/src/builtin.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,14 @@ declare_lint! {
13171317
///
13181318
/// ### Explanation
13191319
///
1320-
/// A bare `pub` visibility may be misleading if the item is not actually
1321-
/// publicly exported from the crate. The `pub(crate)` visibility is
1322-
/// recommended to be used instead, which more clearly expresses the intent
1323-
/// that the item is only visible within its own crate.
1320+
/// The `pub` keyword both expresses an intent for an item to be publicly available, and also
1321+
/// signals to the compiler to make the item publicly accessible. The intent can only be
1322+
/// satisfied, however, if all items which contain this item are *also* publicly accessible.
1323+
/// Thus, this lint serves to identify situations where the intent does not match the reality.
1324+
///
1325+
/// If you wish the item to be accessible elsewhere within the crate, but not outside it, the
1326+
/// `pub(crate)` visibility is recommended to be used instead. This more clearly expresses the
1327+
/// intent that the item is only visible within its own crate.
13241328
///
13251329
/// This lint is "allow" by default because it will trigger for a large
13261330
/// amount existing Rust code, and has some false-positives. Eventually it

compiler/rustc_middle/src/mir/mono.rs

+2
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ impl<'tcx> CodegenUnit<'tcx> {
291291
self.primary = true;
292292
}
293293

294+
/// The order of these items is non-determinstic.
294295
pub fn items(&self) -> &FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)> {
295296
&self.items
296297
}
297298

299+
/// The order of these items is non-determinstic.
298300
pub fn items_mut(&mut self) -> &mut FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)> {
299301
&mut self.items
300302
}

compiler/rustc_monomorphize/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(array_windows)]
2+
#![feature(is_sorted)]
23
#![recursion_limit = "256"]
34
#![allow(rustc::potential_query_instability)]
45
#![deny(rustc::untranslatable_diagnostic)]

compiler/rustc_monomorphize/src/partitioning.rs

+40-28
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,14 @@ struct PartitioningCx<'a, 'tcx> {
126126
}
127127

128128
struct PlacedRootMonoItems<'tcx> {
129+
/// The codegen units, sorted by name to make things deterministic.
129130
codegen_units: Vec<CodegenUnit<'tcx>>,
131+
130132
roots: FxHashSet<MonoItem<'tcx>>,
131133
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
132134
}
133135

136+
// The output CGUs are sorted by name.
134137
fn partition<'tcx, I>(
135138
tcx: TyCtxt<'tcx>,
136139
mono_items: &mut I,
@@ -143,6 +146,7 @@ where
143146
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning");
144147

145148
let cx = &PartitioningCx { tcx, target_cgu_count: max_cgu_count, inlining_map };
149+
146150
// In the first step, we place all regular monomorphizations into their
147151
// respective 'home' codegen unit. Regular monomorphizations are all
148152
// functions and statics defined in the local crate.
@@ -225,8 +229,8 @@ where
225229
dead_code_cgu.make_code_coverage_dead_code_cgu();
226230
}
227231

228-
// Finally, sort by codegen unit name, so that we get deterministic results.
229-
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
232+
// Ensure CGUs are sorted by name, so that we get deterministic results.
233+
assert!(codegen_units.is_sorted_by(|a, b| Some(a.name().as_str().cmp(b.name().as_str()))));
230234

231235
debug_dump(tcx, "FINAL", &codegen_units);
232236

@@ -301,27 +305,22 @@ where
301305
codegen_units.insert(codegen_unit_name, CodegenUnit::new(codegen_unit_name));
302306
}
303307

304-
let codegen_units = codegen_units.into_values().collect();
308+
let mut codegen_units: Vec<_> = codegen_units.into_values().collect();
309+
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
310+
305311
PlacedRootMonoItems { codegen_units, roots, internalization_candidates }
306312
}
307313

314+
// This function requires the CGUs to be sorted by name on input, and ensures
315+
// they are sorted by name on return, for deterministic behaviour.
308316
fn merge_codegen_units<'tcx>(
309317
cx: &PartitioningCx<'_, 'tcx>,
310318
codegen_units: &mut Vec<CodegenUnit<'tcx>>,
311319
) {
312320
assert!(cx.target_cgu_count >= 1);
313321

314-
// Note that at this point in time the `codegen_units` here may not be
315-
// in a deterministic order (but we know they're deterministically the
316-
// same set). We want this merging to produce a deterministic ordering
317-
// of codegen units from the input.
318-
//
319-
// Due to basically how we've implemented the merging below (merge the
320-
// two smallest into each other) we're sure to start off with a
321-
// deterministic order (sorted by name). This'll mean that if two cgus
322-
// have the same size the stable sort below will keep everything nice
323-
// and deterministic.
324-
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
322+
// A sorted order here ensures merging is deterministic.
323+
assert!(codegen_units.is_sorted_by(|a, b| Some(a.name().as_str().cmp(b.name().as_str()))));
325324

326325
// This map keeps track of what got merged into what.
327326
let mut cgu_contents: FxHashMap<Symbol, Vec<Symbol>> =
@@ -400,6 +399,9 @@ fn merge_codegen_units<'tcx>(
400399
cgu.set_name(numbered_codegen_unit_name);
401400
}
402401
}
402+
403+
// A sorted order here ensures what follows can be deterministic.
404+
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
403405
}
404406

405407
/// For symbol internalization, we need to know whether a symbol/mono-item is
@@ -859,36 +861,46 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit
859861
_ => Visibility::Hidden,
860862
}
861863
}
864+
862865
fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<'tcx>]) {
863866
let dump = move || {
864867
use std::fmt::Write;
865868

866869
let num_cgus = cgus.len();
867-
let max = cgus.iter().map(|cgu| cgu.size_estimate()).max().unwrap();
868-
let min = cgus.iter().map(|cgu| cgu.size_estimate()).min().unwrap();
869-
let ratio = max as f64 / min as f64;
870+
let num_items: usize = cgus.iter().map(|cgu| cgu.items().len()).sum();
871+
let total_size: usize = cgus.iter().map(|cgu| cgu.size_estimate()).sum();
872+
let max_size = cgus.iter().map(|cgu| cgu.size_estimate()).max().unwrap();
873+
let min_size = cgus.iter().map(|cgu| cgu.size_estimate()).min().unwrap();
874+
let max_min_size_ratio = max_size as f64 / min_size as f64;
870875

871876
let s = &mut String::new();
872877
let _ = writeln!(
873878
s,
874-
"{label} ({num_cgus} CodegenUnits, max={max}, min={min}, max/min={ratio:.1}):"
879+
"{label} ({num_items} items, total_size={total_size}; {num_cgus} CGUs, \
880+
max_size={max_size}, min_size={min_size}, max_size/min_size={max_min_size_ratio:.1}):"
875881
);
876-
for cgu in cgus {
877-
let _ =
878-
writeln!(s, "CodegenUnit {} estimated size {}:", cgu.name(), cgu.size_estimate());
882+
for (i, cgu) in cgus.iter().enumerate() {
883+
let num_items = cgu.items().len();
884+
let _ = writeln!(
885+
s,
886+
"- CGU[{i}] {} ({num_items} items, size={}):",
887+
cgu.name(),
888+
cgu.size_estimate()
889+
);
879890

880-
for (mono_item, linkage) in cgu.items() {
881-
let symbol_name = mono_item.symbol_name(tcx).name;
891+
// The order of `cgu.items()` is non-deterministic; sort it by name
892+
// to give deterministic output.
893+
let mut items: Vec<_> = cgu.items().iter().collect();
894+
items.sort_by_key(|(item, _)| item.symbol_name(tcx).name);
895+
for (item, linkage) in items {
896+
let symbol_name = item.symbol_name(tcx).name;
882897
let symbol_hash_start = symbol_name.rfind('h');
883898
let symbol_hash = symbol_hash_start.map_or("<no hash>", |i| &symbol_name[i..]);
884899

900+
let size = item.size_estimate(tcx);
885901
let _ = with_no_trimmed_paths!(writeln!(
886902
s,
887-
" - {} [{:?}] [{}] estimated size {}",
888-
mono_item,
889-
linkage,
890-
symbol_hash,
891-
mono_item.size_estimate(tcx)
903+
" - {item} [{linkage:?}] [{symbol_hash}] (size={size})"
892904
));
893905
}
894906

library/std/src/sys/windows/stdio.rs

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use crate::sys::cvt;
1111
use crate::sys::handle::Handle;
1212
use core::str::utf8_char_width;
1313

14+
#[cfg(test)]
15+
mod tests;
16+
1417
// Don't cache handles but get them fresh for every read/write. This allows us to track changes to
1518
// the value over time (such as if a process calls `SetStdHandle` while it's running). See #40490.
1619
pub struct Stdin {
@@ -383,6 +386,10 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result<usize> {
383386
debug_assert!(utf16.len() <= c::c_int::MAX as usize);
384387
debug_assert!(utf8.len() <= c::c_int::MAX as usize);
385388

389+
if utf16.is_empty() {
390+
return Ok(0);
391+
}
392+
386393
let result = unsafe {
387394
c::WideCharToMultiByte(
388395
c::CP_UTF8, // CodePage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use super::utf16_to_utf8;
2+
3+
#[test]
4+
fn zero_size_read() {
5+
assert_eq!(utf16_to_utf8(&[], &mut []).unwrap(), 0);
6+
}

src/bootstrap/test.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,14 @@ impl Step for BookTest {
17721772
///
17731773
/// This uses the `rustdoc` that sits next to `compiler`.
17741774
fn run(self, builder: &Builder<'_>) {
1775+
let host = self.compiler.host;
1776+
let _guard = builder.msg(
1777+
Kind::Test,
1778+
self.compiler.stage,
1779+
&format!("book {}", self.name),
1780+
host,
1781+
host,
1782+
);
17751783
// External docs are different from local because:
17761784
// - Some books need pre-processing by mdbook before being tested.
17771785
// - They need to save their state to toolstate.
@@ -1963,7 +1971,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
19631971
}
19641972
}
19651973

1966-
builder.info(&format!("doc tests for: {}", markdown.display()));
1974+
builder.verbose(&format!("doc tests for: {}", markdown.display()));
19671975
let mut cmd = builder.rustdoc_cmd(compiler);
19681976
builder.add_rust_test_threads(&mut cmd);
19691977
// allow for unstable options such as new editions

src/etc/pre-push.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ ROOT_DIR="$(git rev-parse --show-toplevel)"
1414
echo "Running pre-push script $ROOT_DIR/x test tidy"
1515

1616
cd "$ROOT_DIR"
17-
CARGOFLAGS="--locked" ./x test tidy
17+
./x test tidy --set build.locked-deps=true

tests/rustdoc-gui/theme-in-history.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ set-local-storage: {
77
}
88
// We reload the page so the local storage settings are being used.
99
reload:
10-
assert-css: ("body", { "background-color": "rgb(53, 53, 53)" })
10+
assert-css: ("body", { "background-color": "#353535" })
1111
assert-local-storage: { "rustdoc-theme": "dark" }
1212

1313
// Now we go to the settings page.
1414
go-to: "file://" + |DOC_PATH| + "/settings.html"
1515
wait-for: "#settings"
1616
// We change the theme to "light".
1717
click: "#theme-light"
18-
wait-for-css: ("body", { "background-color": "rgb(255, 255, 255)" })
18+
wait-for-css: ("body", { "background-color": "white" })
1919
assert-local-storage: { "rustdoc-theme": "light" }
2020

2121
// We go back in history.
2222
history-go-back:
2323
// Confirm that we're not on the settings page.
2424
assert-false: "#settings"
2525
// Check that the current theme is still "light".
26-
assert-css: ("body", { "background-color": "rgb(255, 255, 255)" })
26+
assert-css: ("body", { "background-color": "white" })
2727
assert-local-storage: { "rustdoc-theme": "light" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
3+
#![feature(inline_const)]
4+
5+
fn main() {
6+
let _my_usize = const {
7+
let a = 10_usize;
8+
let b: &'_ usize = &a;
9+
*b
10+
};
11+
}

triagebot.toml

+4
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ cc = [
387387
message = "Some changes occurred in HTML/CSS themes."
388388
cc = ["@GuillaumeGomez"]
389389

390+
[mentions."tests/rustdoc-gui/"]
391+
message = "Some changes occurred in GUI tests."
392+
cc = ["@GuillaumeGomez"]
393+
390394
[mentions."src/librustdoc/html/static/css/themes/ayu.css"]
391395
message = "A change occurred in the Ayu theme."
392396
cc = ["@Cldfire"]

0 commit comments

Comments
 (0)