Skip to content

Commit

Permalink
Auto merge of rust-lang#131355 - clubby789:old-tests, r=<try>
Browse files Browse the repository at this point in the history
Add tests for some old fixed issues

Closes rust-lang#30867
Closes rust-lang#30472
Closes rust-lang#28994
Closes rust-lang#26719 (and migrates the relevant test to the new run-make)
Closes rust-lang#23600

cc `@jieyouxu` for the run-make-support changes

try-job: x86_64-msvc
  • Loading branch information
bors committed Oct 7, 2024
2 parents baaf3e6 + 382365b commit a0df115
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 53 deletions.
24 changes: 24 additions & 0 deletions src/tools/run-make-support/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ macro_rules! impl_common_helpers {
self
}

/// Configuration for the child process’s standard input (stdin) handle.
///
/// See [`std::process::Command::stdin`].
pub fn stdin<T: Into<::std::process::Stdio>>(&mut self, cfg: T) -> &mut Self {
self.cmd.stdin(cfg);
self
}

/// Configuration for the child process’s standard output (stdout) handle.
///
/// See [`std::process::Command::stdout`].
pub fn stdout<T: Into<::std::process::Stdio>>(&mut self, cfg: T) -> &mut Self {
self.cmd.stdout(cfg);
self
}

/// Configuration for the child process’s standard error (stderr) handle.
///
/// See [`std::process::Command::stderr`].
pub fn stderr<T: Into<::std::process::Stdio>>(&mut self, cfg: T) -> &mut Self {
self.cmd.stderr(cfg);
self
}

/// Inspect what the underlying [`Command`] is up to the
/// current construction.
pub fn inspect<I>(&mut self, inspector: I) -> &mut Self
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
run-make/branch-protection-check-IBT/Makefile
run-make/cat-and-grep-sanity-check/Makefile
run-make/emit-to-stdout/Makefile
run-make/extern-fn-reachable/Makefile
run-make/incr-add-rust-src-component/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,6 @@ ui/consts/issue-70942-trait-vs-impl-mismatch.rs
ui/consts/issue-73976-monomorphic.rs
ui/consts/issue-73976-polymorphic.rs
ui/consts/issue-76064.rs
ui/consts/issue-77062-large-zst-array.rs
ui/consts/issue-78655.rs
ui/consts/issue-79137-monomorphic.rs
ui/consts/issue-79137-toogeneric.rs
Expand Down
51 changes: 0 additions & 51 deletions tests/run-make/emit-to-stdout/Makefile

This file was deleted.

73 changes: 73 additions & 0 deletions tests/run-make/emit-to-stdout/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//! If `-o -` or `--emit KIND=-` is provided, output should be written to stdout
//! instead. Binary output (`obj`, `llvm-bc`, `link` and `metadata`)
//! being written this way will result in an error if stdout is a tty.
//! Multiple output types going to stdout will trigger an error too,
//! as they would all be mixed together.
//!
//! See <https://github.com/rust-lang/rust/pull/111626>.
use std::fs::File;

use run_make_support::{diff, run_in_tmpdir, rustc};

// Test emitting text outputs to stdout works correctly
fn run_diff(name: &str, file_args: &[&str]) {
rustc().emit(format!("{name}={name}")).input("test.rs").args(file_args).run();
let out = rustc().emit(format!("{name}=-")).input("test.rs").run().stdout_utf8();
diff().expected_file(name).actual_text("stdout", &out).run();
}

// Test that emitting binary formats to a terminal gives the correct error
fn run_terminal_err_diff(name: &str) {
#[cfg(not(windows))]
let terminal = File::create("/dev/ptmx").unwrap();
// FIXME: If this test fails and the compiler does print to the console,
// then this will produce a lot of output.
// We should spawn a new console instead to print stdout.
#[cfg(windows)]
let terminal = File::options().read(true).write(true).open(r"\\.\CONOUT$").unwrap();

let err = File::create(name).unwrap();
rustc().emit(format!("{name}=-")).input("test.rs").stdout(terminal).stderr(err).run_fail();
diff().expected_file(format!("emit-{name}.stderr")).actual_file(name).run();
}

fn main() {
run_in_tmpdir(|| {
run_diff("asm", &[]);
run_diff("llvm-ir", &[]);
run_diff("dep-info", &["-Zdep-info-omit-d-target=yes"]);
run_diff("mir", &[]);

run_terminal_err_diff("llvm-bc");
run_terminal_err_diff("obj");
run_terminal_err_diff("metadata");
run_terminal_err_diff("link");

// Test error for emitting multiple types to stdout
rustc()
.input("test.rs")
.emit("asm=-")
.emit("llvm-ir=-")
.emit("dep-info=-")
.emit("mir=-")
.stderr(File::create("multiple-types").unwrap())
.run_fail();
diff().expected_file("emit-multiple-types.stderr").actual_file("multiple-types").run();

// Same as above, but using `-o`
rustc()
.input("test.rs")
.output("-")
.emit("asm,llvm-ir,dep-info,mir")
.stderr(File::create("multiple-types-option-o").unwrap())
.run_fail();
diff()
.expected_file("emit-multiple-types.stderr")
.actual_file("multiple-types-option-o")
.run();

// Test that `-o -` redirected to a file works correctly (#26719)
rustc().input("test.rs").output("-").stdout(File::create("out-stdout").unwrap()).run();
});
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ build-pass
pub static FOO: [(); usize::MAX] = [(); usize::MAX];

fn main() {
let _ = &[(); usize::MAX];
Expand Down
32 changes: 32 additions & 0 deletions tests/ui/traits/assoc-type-hrtb-normalization-30472.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@ check-pass
//! Tests that associated type projections normalize properly in the presence of HRTBs.
//! Original issue: <https://github.com/rust-lang/rust/issues/30472>

pub trait MyFrom<T> {}
impl<T> MyFrom<T> for T {}

pub trait MyInto<T> {}
impl<T, U> MyInto<U> for T where U: MyFrom<T> {}


pub trait A<'self_> {
type T;
}
pub trait B: for<'self_> A<'self_> {
// Originally caused the `type U = usize` example below to fail with a type mismatch error
type U: for<'self_> MyFrom<<Self as A<'self_>>::T>;
}


pub struct M;
impl<'self_> A<'self_> for M {
type T = usize;
}

impl B for M {
type U = usize;
}


fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/traits/fn-pointer/hrtb-assoc-fn-traits-28994.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@ check-pass
//! Tests that a HRTB + FnOnce bound involving an associated type don't prevent
//! a function pointer from implementing `Fn` traits.
//! Test for <https://github.com/rust-lang/rust/issues/28994>
trait LifetimeToType<'a> {
type Out;
}

impl<'a> LifetimeToType<'a> for () {
type Out = &'a ();
}

fn id<'a>(val: &'a ()) -> <() as LifetimeToType<'a>>::Out {
val
}

fn assert_fn<F: for<'a> FnOnce(&'a ()) -> <() as LifetimeToType<'a>>::Out>(_func: F) { }

fn main() {
assert_fn(id);
}
14 changes: 14 additions & 0 deletions tests/ui/traits/hrtb-related-type-params-30867.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ check-pass
//! Tests that HRTB impl selection covers type parameters not directly related
//! to the trait.
//! Test for <https://github.com/rust-lang/rust/issues/30867>
#![crate_type = "lib"]

trait Unary<T> {}
impl<T, U, F: Fn(T) -> U> Unary<T> for F {}
fn unary<F: for<'a> Unary<&'a T>, T>() {}

pub fn test<F: for<'a> Fn(&'a i32) -> &'a i32>() {
unary::<F, i32>()
}

0 comments on commit a0df115

Please sign in to comment.