Skip to content

Commit

Permalink
Auto merge of #125624 - matthiaskrgr:rollup-560jx21, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #125339 (The number of tests does not depend on the architecture's pointer width)
 - #125539 (crashes: increment the number of tracked ones)
 - #125542 (Migrate rustdoc verify output files)
 - #125613 (Use `rmake` for `windows-` run-make tests)
 - #125616 (MIR validation: ensure that downcast projection is followed by field projection)

Failed merges:

 - #125573 (Migrate `run-make/allow-warnings-cmdline-stability` to `rmake.rs`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 27, 2024
2 parents b0f8618 + a3d4b5f commit 97ef6a8
Show file tree
Hide file tree
Showing 42 changed files with 539 additions and 107 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,8 @@ pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
/// element:
///
/// - [`Downcast`](ProjectionElem::Downcast): This projection sets the place's variant index to the
/// given one, and makes no other changes. A `Downcast` projection on a place with its variant
/// index already set is not well-formed.
/// given one, and makes no other changes. A `Downcast` projection must always be followed
/// immediately by a `Field` projection.
/// - [`Field`](ProjectionElem::Field): `Field` projections take their parent place and create a
/// place referring to one of the fields of the type. The resulting address is the parent
/// address, plus the offset of the field. The type becomes the type of the field. If the parent
Expand Down
26 changes: 23 additions & 3 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
if Some(adt_def.did()) == self.tcx.lang_items().dyn_metadata() {
self.fail(
location,
format!("You can't project to field {f:?} of `DynMetadata` because \
layout is weird and thinks it doesn't have fields."),
format!(
"You can't project to field {f:?} of `DynMetadata` because \
layout is weird and thinks it doesn't have fields."
),
);
}

Expand Down Expand Up @@ -839,7 +841,25 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
&& cntxt != PlaceContext::NonUse(NonUseContext::VarDebugInfo)
&& place.projection[1..].contains(&ProjectionElem::Deref)
{
self.fail(location, format!("{place:?}, has deref at the wrong place"));
self.fail(
location,
format!("place {place:?} has deref as a later projection (it is only permitted as the first projection)"),
);
}

// Ensure all downcast projections are followed by field projections.
let mut projections_iter = place.projection.iter();
while let Some(proj) = projections_iter.next() {
if matches!(proj, ProjectionElem::Downcast(..)) {
if !matches!(projections_iter.next(), Some(ProjectionElem::Field(..))) {
self.fail(
location,
format!(
"place {place:?} has `Downcast` projection not followed by `Field`"
),
);
}
}
}

self.super_place(place, cntxt, location);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/panic/mir-validation.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:LL:CC:
broken MIR in Item(DefId) (after phase change to runtime-optimized) at bb0[1]:
(*(_2.0: *mut i32)), has deref at the wrong place
place (*(_2.0: *mut i32)) has deref as a later projection (it is only permitted as the first projection)
stack backtrace:

error: the compiler unexpectedly panicked. this is a bug.
Expand Down
5 changes: 4 additions & 1 deletion src/tools/run-make-support/src/diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ impl Diff {
/// Specify the actual output for the diff from a file.
pub fn actual_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
let path = path.as_ref();
let content = std::fs::read_to_string(path).expect("failed to read file");
let content = match std::fs::read_to_string(path) {
Ok(c) => c,
Err(e) => panic!("failed to read `{}`: {:?}", path.display(), e),
};
let name = path.to_string_lossy().to_string();

self.actual = Some(content);
Expand Down
67 changes: 67 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub mod rustc;
pub mod rustdoc;

use std::env;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};

Expand Down Expand Up @@ -201,6 +203,71 @@ pub fn set_host_rpath(cmd: &mut Command) {
});
}

/// Copy a directory into another.
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
let dst = dst.as_ref();
if !dst.is_dir() {
fs::create_dir_all(&dst)?;
}
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?;
} else {
fs::copy(entry.path(), dst.join(entry.file_name()))?;
}
}
Ok(())
}

if let Err(e) = copy_dir_all_inner(&src, &dst) {
// Trying to give more context about what exactly caused the failure
panic!(
"failed to copy `{}` to `{}`: {:?}",
src.as_ref().display(),
dst.as_ref().display(),
e
);
}
}

/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
fn read_file(path: &Path) -> Vec<u8> {
match fs::read(path) {
Ok(c) => c,
Err(e) => panic!("Failed to read `{}`: {:?}", path.display(), e),
}
}

let dir2 = dir2.as_ref();
for entry in fs::read_dir(dir1).unwrap() {
let entry = entry.unwrap();
let entry_name = entry.file_name();
let path = entry.path();

if path.is_dir() {
recursive_diff(&path, &dir2.join(entry_name));
} else {
let path2 = dir2.join(entry_name);
let file1 = read_file(&path);
let file2 = read_file(&path2);

// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
// Why not using String? Because there might be minified files or even potentially
// binary ones, so that would display useless output.
assert!(
file1 == file2,
"`{}` and `{}` have different content",
path.display(),
path2.display(),
);
}
}
}

/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
///
Expand Down
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/llvm_readobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl LlvmReadobj {
self
}

/// Pass `--coff-imports` to display the Windows DLL imports
pub fn coff_imports(&mut self) -> &mut Self {
self.cmd.arg("--coff-imports");
self
}

/// Get the [`Output`][::std::process::Output] of the finished process.
#[track_caller]
pub fn command_output(&mut self) -> ::std::process::Output {
Expand Down
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ impl Rustc {
self
}

/// Specify the linker
pub fn linker(&mut self, linker: &str) -> &mut Self {
self.cmd.arg(format!("-Clinker={linker}"));
self
}

/// Get the [`Output`][::std::process::Output] of the finished process.
#[track_caller]
pub fn command_output(&mut self) -> ::std::process::Output {
Expand Down
7 changes: 7 additions & 0 deletions src/tools/run-make-support/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ impl Rustdoc {
self
}

/// Specify the output format.
pub fn output_format(&mut self, format: &str) -> &mut Self {
self.cmd.arg("--output-format");
self.cmd.arg(format);
self
}

#[track_caller]
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
let caller_location = std::panic::Location::caller();
Expand Down
6 changes: 0 additions & 6 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ run-make/issue-83112-incr-test-moved-file/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/issue-85019-moved-src-dir/Makefile
run-make/issue-85401-static-mir/Makefile
run-make/issue-85441/Makefile
run-make/issue-88756-default-output/Makefile
run-make/issue-97463-abi-param-passing/Makefile
run-make/jobserver-error/Makefile
Expand Down Expand Up @@ -226,7 +225,6 @@ run-make/rlib-format-packed-bundled-libs/Makefile
run-make/rmeta-preferred/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/rustdoc-io-error/Makefile
run-make/rustdoc-verify-output-files/Makefile
run-make/sanitizer-cdylib-link/Makefile
run-make/sanitizer-dylib-link/Makefile
run-make/sanitizer-staticlib-link/Makefile
Expand Down Expand Up @@ -277,8 +275,4 @@ run-make/volatile-intrinsics/Makefile
run-make/wasm-exceptions-nostd/Makefile
run-make/wasm-override-linker/Makefile
run-make/weird-output-filenames/Makefile
run-make/windows-binary-no-external-deps/Makefile
run-make/windows-safeseh/Makefile
run-make/windows-spawn/Makefile
run-make/windows-subsystem/Makefile
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
8 changes: 4 additions & 4 deletions src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use std::path::{Path, PathBuf};
// should all be 1000 or lower. Limits significantly smaller than 1000 are also
// desirable, because large numbers of files are unwieldy in general. See issue
// #73494.
const ENTRY_LIMIT: usize = 900;
const ENTRY_LIMIT: u32 = 900;
// FIXME: The following limits should be reduced eventually.

const ISSUES_ENTRY_LIMIT: usize = 1676;
const ISSUES_ENTRY_LIMIT: u32 = 1676;

const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
"rs", // test source files
Expand Down Expand Up @@ -53,7 +53,7 @@ const EXTENSION_EXCEPTION_PATHS: &[&str] = &[
];

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

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

let (mut max, mut max_issues) = (0usize, 0usize);
let (mut max, mut max_issues) = (0, 0);
for (dir_path, count) in directories {
let is_issues_dir = tests_path.join("ui/issues") == dir_path;
let (limit, maxcnt) = if is_issues_dir {
Expand Down
13 changes: 13 additions & 0 deletions tests/crashes/123255.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ known-bug: rust-lang/rust#123255
//@ edition:2021
#![crate_type = "lib"]

pub fn a() {}

mod handlers {
pub struct C(&());
pub fn c() -> impl Fn() -> C {
let a1 = ();
|| C((crate::a(), a1).into())
}
}
25 changes: 25 additions & 0 deletions tests/crashes/123276.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@ known-bug: rust-lang/rust#123276
//@ edition:2021

async fn create_task() {
_ = Some(async { bind(documentation_filter()) });
}

async fn bind<Fut, F: Filter<Future = Fut>>(_: F) {}

fn documentation_filter() -> impl Filter {
AndThen
}

trait Filter {
type Future;
}

struct AndThen;

impl Filter for AndThen
where
Foo: Filter,
{
type Future = ();
}
15 changes: 15 additions & 0 deletions tests/crashes/123887.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ known-bug: rust-lang/rust#123887
//@ compile-flags: -Clink-dead-code

#![feature(extern_types)]
#![feature(unsized_fn_params)]

extern "C" {
pub type ExternType;
}

impl ExternType {
pub fn f(self) {}
}

pub fn main() {}
5 changes: 5 additions & 0 deletions tests/crashes/125013-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ known-bug: rust-lang/rust#125013
//@ edition:2021
use io::{self as std};
use std::ops::Deref::{self as io};
pub fn main() {}
16 changes: 16 additions & 0 deletions tests/crashes/125013-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: rust-lang/rust#125013
//@ edition:2021
mod a {
pub mod b {
pub mod c {
pub trait D {}
}
}
}

use a::*;

use e as b;
use b::c::D as e;

fn main() { }
17 changes: 17 additions & 0 deletions tests/crashes/125014.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ known-bug: rust-lang/rust#125014
//@ compile-flags: -Znext-solver=coherence
#![feature(specialization)]

trait Foo {}

impl Foo for <u16 as Assoc>::Output {}

impl Foo for u32 {}

trait Assoc {
type Output;
}
impl Output for u32 {}
impl Assoc for <u16 as Assoc>::Output {
default type Output = bool;
}
12 changes: 12 additions & 0 deletions tests/crashes/125059.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ known-bug: rust-lang/rust#125059
#![feature(deref_patterns)]
#![allow(incomplete_features)]

fn simple_vec(vec: Vec<u32>) -> u32 {
(|| match Vec::<u32>::new() {
deref!([]) => 100,
_ => 2000,
})()
}

fn main() {}
6 changes: 6 additions & 0 deletions tests/crashes/125323.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ known-bug: rust-lang/rust#125323
fn main() {
for _ in 0..0 {
[(); loop {}];
}
}
3 changes: 3 additions & 0 deletions tests/crashes/125476.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ known-bug: rust-lang/rust#125476
pub struct Data([u8; usize::MAX >> 16]);
const _: &'static [Data] = &[];
10 changes: 10 additions & 0 deletions tests/crashes/125512.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ known-bug: rust-lang/rust#125512
//@ edition:2021
#![feature(object_safe_for_dispatch)]
trait B {
fn f(a: A) -> A;
}
trait A {
fn concrete(b: B) -> B;
}
fn main() {}
15 changes: 15 additions & 0 deletions tests/crashes/125553.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ known-bug: rust-lang/rust#125553
//@ edition:2021

#[derive(Copy, Clone)]
struct Foo((u32, u32));

fn main() {
type T = impl Copy(Copy, Clone)
let foo: T = Foo((1u32, 1u32));
let x = move || {
let derive = move || {
let Foo((a, b)) = foo;
};
};
}
Loading

0 comments on commit 97ef6a8

Please sign in to comment.