Skip to content

Commit 84b40fc

Browse files
committed
Auto merge of #125628 - matthiaskrgr:rollup-3zk9v3w, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #125339 (The number of tests does not depend on the architecture's pointer width) - #125542 (Migrate rustdoc verify output files) - #125616 (MIR validation: ensure that downcast projection is followed by field projection) - #125625 (Use grep to implement verify-line-endings) Failed merges: - #125573 (Migrate `run-make/allow-warnings-cmdline-stability` to `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f00b02e + 4966e1a commit 84b40fc

File tree

11 files changed

+168
-55
lines changed

11 files changed

+168
-55
lines changed

compiler/rustc_middle/src/mir/syntax.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
10081008
/// element:
10091009
///
10101010
/// - [`Downcast`](ProjectionElem::Downcast): This projection sets the place's variant index to the
1011-
/// given one, and makes no other changes. A `Downcast` projection on a place with its variant
1012-
/// index already set is not well-formed.
1011+
/// given one, and makes no other changes. A `Downcast` projection must always be followed
1012+
/// immediately by a `Field` projection.
10131013
/// - [`Field`](ProjectionElem::Field): `Field` projections take their parent place and create a
10141014
/// place referring to one of the fields of the type. The resulting address is the parent
10151015
/// address, plus the offset of the field. The type becomes the type of the field. If the parent

compiler/rustc_mir_transform/src/validate.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
689689
if Some(adt_def.did()) == self.tcx.lang_items().dyn_metadata() {
690690
self.fail(
691691
location,
692-
format!("You can't project to field {f:?} of `DynMetadata` because \
693-
layout is weird and thinks it doesn't have fields."),
692+
format!(
693+
"You can't project to field {f:?} of `DynMetadata` because \
694+
layout is weird and thinks it doesn't have fields."
695+
),
694696
);
695697
}
696698

@@ -839,7 +841,25 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
839841
&& cntxt != PlaceContext::NonUse(NonUseContext::VarDebugInfo)
840842
&& place.projection[1..].contains(&ProjectionElem::Deref)
841843
{
842-
self.fail(location, format!("{place:?}, has deref at the wrong place"));
844+
self.fail(
845+
location,
846+
format!("place {place:?} has deref as a later projection (it is only permitted as the first projection)"),
847+
);
848+
}
849+
850+
// Ensure all downcast projections are followed by field projections.
851+
let mut projections_iter = place.projection.iter();
852+
while let Some(proj) = projections_iter.next() {
853+
if matches!(proj, ProjectionElem::Downcast(..)) {
854+
if !matches!(projections_iter.next(), Some(ProjectionElem::Field(..))) {
855+
self.fail(
856+
location,
857+
format!(
858+
"place {place:?} has `Downcast` projection not followed by `Field`"
859+
),
860+
);
861+
}
862+
}
843863
}
844864

845865
self.super_place(place, cntxt, location);

src/ci/scripts/verify-line-endings.sh

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
# We check both in rust-lang/rust and in a submodule to make sure both are
55
# accurate. Submodules are checked out significantly later than the main
66
# repository in this script, so settings can (and do!) change between then.
7-
#
8-
# Linux (and maybe macOS) builders don't currently have dos2unix so just only
9-
# run this step on Windows.
107

118
set -euo pipefail
129
IFS=$'\n\t'
1310

1411
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
1512

16-
if isWindows; then
17-
# print out the git configuration so we can better investigate failures in
18-
# the following
19-
git config --list --show-origin
20-
dos2unix -ih Cargo.lock src/tools/rust-installer/install-template.sh
21-
endings=$(dos2unix -ic Cargo.lock src/tools/rust-installer/install-template.sh)
22-
# if endings has non-zero length, error out
23-
if [ -n "$endings" ]; then exit 1 ; fi
13+
# print out the git configuration so we can better investigate failures in
14+
# the following
15+
git config --list --show-origin
16+
# -U is necessary on Windows to stop grep automatically converting the line ending
17+
endings=$(grep -Ul $(printf '\r$') Cargo.lock src/tools/cargo/Cargo.lock) || true
18+
# if endings has non-zero length, error out
19+
if [[ -n $endings ]]; then
20+
echo "Error: found DOS line endings"
21+
# Print the files with DOS line endings
22+
echo "$endings"
23+
exit 1
2424
fi

src/tools/miri/tests/panic/mir-validation.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:LL:CC:
22
broken MIR in Item(DefId) (after phase change to runtime-optimized) at bb0[1]:
3-
(*(_2.0: *mut i32)), has deref at the wrong place
3+
place (*(_2.0: *mut i32)) has deref as a later projection (it is only permitted as the first projection)
44
stack backtrace:
55

66
error: the compiler unexpectedly panicked. this is a bug.

src/tools/run-make-support/src/diff/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ impl Diff {
5151
/// Specify the actual output for the diff from a file.
5252
pub fn actual_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
5353
let path = path.as_ref();
54-
let content = std::fs::read_to_string(path).expect("failed to read file");
54+
let content = match std::fs::read_to_string(path) {
55+
Ok(c) => c,
56+
Err(e) => panic!("failed to read `{}`: {:?}", path.display(), e),
57+
};
5558
let name = path.to_string_lossy().to_string();
5659

5760
self.actual = Some(content);

src/tools/run-make-support/src/lib.rs

+67
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub mod rustc;
1212
pub mod rustdoc;
1313

1414
use std::env;
15+
use std::fs;
16+
use std::io;
1517
use std::path::{Path, PathBuf};
1618
use std::process::{Command, Output};
1719

@@ -201,6 +203,71 @@ pub fn set_host_rpath(cmd: &mut Command) {
201203
});
202204
}
203205

206+
/// Copy a directory into another.
207+
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
208+
fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
209+
let dst = dst.as_ref();
210+
if !dst.is_dir() {
211+
fs::create_dir_all(&dst)?;
212+
}
213+
for entry in fs::read_dir(src)? {
214+
let entry = entry?;
215+
let ty = entry.file_type()?;
216+
if ty.is_dir() {
217+
copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?;
218+
} else {
219+
fs::copy(entry.path(), dst.join(entry.file_name()))?;
220+
}
221+
}
222+
Ok(())
223+
}
224+
225+
if let Err(e) = copy_dir_all_inner(&src, &dst) {
226+
// Trying to give more context about what exactly caused the failure
227+
panic!(
228+
"failed to copy `{}` to `{}`: {:?}",
229+
src.as_ref().display(),
230+
dst.as_ref().display(),
231+
e
232+
);
233+
}
234+
}
235+
236+
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
237+
pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
238+
fn read_file(path: &Path) -> Vec<u8> {
239+
match fs::read(path) {
240+
Ok(c) => c,
241+
Err(e) => panic!("Failed to read `{}`: {:?}", path.display(), e),
242+
}
243+
}
244+
245+
let dir2 = dir2.as_ref();
246+
for entry in fs::read_dir(dir1).unwrap() {
247+
let entry = entry.unwrap();
248+
let entry_name = entry.file_name();
249+
let path = entry.path();
250+
251+
if path.is_dir() {
252+
recursive_diff(&path, &dir2.join(entry_name));
253+
} else {
254+
let path2 = dir2.join(entry_name);
255+
let file1 = read_file(&path);
256+
let file2 = read_file(&path2);
257+
258+
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
259+
// Why not using String? Because there might be minified files or even potentially
260+
// binary ones, so that would display useless output.
261+
assert!(
262+
file1 == file2,
263+
"`{}` and `{}` have different content",
264+
path.display(),
265+
path2.display(),
266+
);
267+
}
268+
}
269+
}
270+
204271
/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
205272
/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
206273
///

src/tools/run-make-support/src/rustdoc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ impl Rustdoc {
151151
self
152152
}
153153

154+
/// Specify the output format.
155+
pub fn output_format(&mut self, format: &str) -> &mut Self {
156+
self.cmd.arg("--output-format");
157+
self.cmd.arg(format);
158+
self
159+
}
160+
154161
#[track_caller]
155162
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
156163
let caller_location = std::panic::Location::caller();

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ run-make/rlib-format-packed-bundled-libs/Makefile
226226
run-make/rmeta-preferred/Makefile
227227
run-make/rustc-macro-dep-files/Makefile
228228
run-make/rustdoc-io-error/Makefile
229-
run-make/rustdoc-verify-output-files/Makefile
230229
run-make/sanitizer-cdylib-link/Makefile
231230
run-make/sanitizer-dylib-link/Makefile
232231
run-make/sanitizer-staticlib-link/Makefile

src/tools/tidy/src/ui_tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use std::path::{Path, PathBuf};
1212
// should all be 1000 or lower. Limits significantly smaller than 1000 are also
1313
// desirable, because large numbers of files are unwieldy in general. See issue
1414
// #73494.
15-
const ENTRY_LIMIT: usize = 900;
15+
const ENTRY_LIMIT: u32 = 900;
1616
// FIXME: The following limits should be reduced eventually.
1717

18-
const ISSUES_ENTRY_LIMIT: usize = 1676;
18+
const ISSUES_ENTRY_LIMIT: u32 = 1676;
1919

2020
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
2121
"rs", // test source files
@@ -53,7 +53,7 @@ const EXTENSION_EXCEPTION_PATHS: &[&str] = &[
5353
];
5454

5555
fn check_entries(tests_path: &Path, bad: &mut bool) {
56-
let mut directories: HashMap<PathBuf, usize> = HashMap::new();
56+
let mut directories: HashMap<PathBuf, u32> = HashMap::new();
5757

5858
for dir in Walk::new(&tests_path.join("ui")) {
5959
if let Ok(entry) = dir {
@@ -62,7 +62,7 @@ fn check_entries(tests_path: &Path, bad: &mut bool) {
6262
}
6363
}
6464

65-
let (mut max, mut max_issues) = (0usize, 0usize);
65+
let (mut max, mut max_issues) = (0, 0);
6666
for (dir_path, count) in directories {
6767
let is_issues_dir = tests_path.join("ui/issues") == dir_path;
6868
let (limit, maxcnt) = if is_issues_dir {

tests/run-make/rustdoc-verify-output-files/Makefile

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::fs::copy;
2+
use std::path::{Path, PathBuf};
3+
4+
use run_make_support::{copy_dir_all, recursive_diff, rustdoc, tmp_dir};
5+
6+
#[derive(PartialEq)]
7+
enum JsonOutput {
8+
Yes,
9+
No,
10+
}
11+
12+
fn generate_docs(out_dir: &Path, json_output: JsonOutput) {
13+
let mut rustdoc = rustdoc();
14+
rustdoc.input("src/lib.rs").crate_name("foobar").crate_type("lib").out_dir(&out_dir);
15+
if json_output == JsonOutput::Yes {
16+
rustdoc.arg("-Zunstable-options").output_format("json");
17+
}
18+
rustdoc.run();
19+
}
20+
21+
fn main() {
22+
let out_dir = tmp_dir().join("rustdoc");
23+
let tmp_out_dir = tmp_dir().join("tmp-rustdoc");
24+
25+
// Generate HTML docs.
26+
generate_docs(&out_dir, JsonOutput::No);
27+
28+
// Copy first output for to check if it's exactly same after second compilation.
29+
copy_dir_all(&out_dir, &tmp_out_dir);
30+
31+
// Generate html docs once again on same output.
32+
generate_docs(&out_dir, JsonOutput::No);
33+
34+
// Generate json doc on the same output.
35+
generate_docs(&out_dir, JsonOutput::Yes);
36+
37+
// Check if expected json file is generated.
38+
assert!(out_dir.join("foobar.json").is_file());
39+
40+
// Copy first json output to check if it's exactly same after second compilation.
41+
copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")).unwrap();
42+
43+
// Generate json doc on the same output.
44+
generate_docs(&out_dir, JsonOutput::Yes);
45+
46+
// Check if all docs(including both json and html formats) are still the same after multiple
47+
// compilations.
48+
recursive_diff(&out_dir, &tmp_out_dir);
49+
}

0 commit comments

Comments
 (0)