Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #129140

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b18c7d8
Docs for Waker and LocalWaker: Add cross-refs in comment
ijackson Jul 22, 2024
c404406
LocalWaker docs: Make long-ago omitted but probably intended changes
ijackson Jul 22, 2024
2e7e619
bootstrap: fix trying to modify file times on read-only file on Windows
jieyouxu Aug 11, 2024
c4aa7a7
Port `run-make/libtest-json` to rmake
Zalathar Aug 13, 2024
fc733a6
Port `run-make/libtest-junit` to rmake
Zalathar Aug 13, 2024
99aad72
Add a comment explaining the return type of `Ty::kind`.
nnethercote Aug 14, 2024
8b990e3
Port the `sysroot-crates-are-unstable` Python script to rmake
Zalathar Aug 14, 2024
2e4d5bb
rewrite rlib-format-packed-bundled-libs to rmake
Oneirical Aug 12, 2024
51628fb
rewrite native-link-modifier-bundle to rmake
Oneirical Aug 12, 2024
9a95573
Add cautionary paragraph about noop wakers.
ijackson Aug 5, 2024
7d99549
crashes: more tests
matthiaskrgr Aug 15, 2024
7bdfa90
Rollup merge of #128064 - ijackson:noop-waker-doc, r=workingjubilee
workingjubilee Aug 16, 2024
4ed9ed3
Rollup merge of #128977 - jieyouxu:writable-file, r=Kobzol
workingjubilee Aug 16, 2024
2f60b7b
Rollup merge of #129018 - Oneirical:nmemonic-artifice, r=jieyouxu
workingjubilee Aug 16, 2024
48af62f
Rollup merge of #129037 - Zalathar:rmake-libtest, r=jieyouxu
workingjubilee Aug 16, 2024
ad5b750
Rollup merge of #129110 - nnethercote:Ty-kind-ret-ty-comment, r=jieyouxu
workingjubilee Aug 16, 2024
19fcd38
Rollup merge of #129111 - Zalathar:python-sysroot, r=jieyouxu
workingjubilee Aug 16, 2024
1853872
Rollup merge of #129135 - matthiaskrgr:ITKEEPSCRASHINGAAAAAAAAHH, r=c…
workingjubilee Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,10 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {

/// Type utilities
impl<'tcx> Ty<'tcx> {
// It would be nicer if this returned the value instead of a reference,
// like how `Predicate::kind` and `Region::kind` do. (It would result in
// many fewer subsequent dereferences.) But that gives a small but
// noticeable performance hit. See #126069 for details.
#[inline(always)]
pub fn kind(self) -> &'tcx TyKind<'tcx> {
self.0.0
Expand Down
20 changes: 19 additions & 1 deletion library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,18 @@ impl Waker {

/// Returns a reference to a `Waker` that does nothing when used.
///
// Note! Much of the documentation for this method is duplicated
// in the docs for `LocalWaker::noop`.
// If you edit it, consider editing the other copy too.
//
/// This is mostly useful for writing tests that need a [`Context`] to poll
/// some futures, but are not expecting those futures to wake the waker or
/// do not need to do anything specific if it happens.
///
/// More generally, using `Waker::noop()` to poll a future
/// means discarding the notification of when the future should be polled again.
/// So it should only be used when such a notification will not be needed to make progress.
///
/// If an owned `Waker` is needed, `clone()` this one.
///
/// # Examples
Expand Down Expand Up @@ -783,12 +791,22 @@ impl LocalWaker {
Self { waker }
}

/// Creates a new `LocalWaker` that does nothing when `wake` is called.
/// Returns a reference to a `LocalWaker` that does nothing when used.
///
// Note! Much of the documentation for this method is duplicated
// in the docs for `Waker::noop`.
// If you edit it, consider editing the other copy too.
//
/// This is mostly useful for writing tests that need a [`Context`] to poll
/// some futures, but are not expecting those futures to wake the waker or
/// do not need to do anything specific if it happens.
///
/// More generally, using `LocalWaker::noop()` to poll a future
/// means discarding the notification of when the future should be polled again,
/// So it should only be used when such a notification will not be needed to make progress.
///
/// If an owned `LocalWaker` is needed, `clone()` this one.
///
/// # Examples
///
/// ```
Expand Down
4 changes: 1 addition & 3 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,7 @@ download-rustc = false
let file_times = fs::FileTimes::new().set_accessed(now).set_modified(now);

let llvm_config = llvm_root.join("bin").join(exe("llvm-config", self.build));
let llvm_config_file = t!(File::options().write(true).open(llvm_config));

t!(llvm_config_file.set_times(file_times));
t!(crate::utils::helpers::set_file_times(llvm_config, file_times));

if self.should_fix_bins_and_dylibs() {
let llvm_lib = llvm_root.join("lib");
Expand Down
15 changes: 8 additions & 7 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ use crate::core::builder;
use crate::core::builder::{Builder, Kind};
use crate::core::config::{flags, DryRun, LldMode, LlvmLibunwind, Target, TargetSelection};
use crate::utils::exec::{command, BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode};
use crate::utils::helpers::{self, dir_is_empty, exe, libdir, mtime, output, symlink_dir};
use crate::utils::helpers::{
self, dir_is_empty, exe, libdir, mtime, output, set_file_times, symlink_dir,
};

mod core;
mod utils;
Expand Down Expand Up @@ -1792,21 +1794,20 @@ Executed at: {executed_at}"#,
}
}
if let Ok(()) = fs::hard_link(&src, dst) {
// Attempt to "easy copy" by creating a hard link
// (symlinks don't work on windows), but if that fails
// just fall back to a slow `copy` operation.
// Attempt to "easy copy" by creating a hard link (symlinks are priviledged on windows),
// but if that fails just fall back to a slow `copy` operation.
} else {
if let Err(e) = fs::copy(&src, dst) {
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
}
t!(fs::set_permissions(dst, metadata.permissions()));

// Restore file times because changing permissions on e.g. Linux using `chmod` can cause
// file access time to change.
let file_times = fs::FileTimes::new()
.set_accessed(t!(metadata.accessed()))
.set_modified(t!(metadata.modified()));

let dst_file = t!(fs::File::open(dst));
t!(dst_file.set_times(file_times));
t!(set_file_times(dst, file_times));
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,15 @@ pub fn get_closest_merge_base_commit(

Ok(output_result(git.as_command_mut())?.trim().to_owned())
}

/// Sets the file times for a given file at `path`.
pub fn set_file_times<P: AsRef<Path>>(path: P, times: fs::FileTimes) -> io::Result<()> {
// Windows requires file to be writable to modify file times. But on Linux CI the file does not
// need to be writable to modify file times and might be read-only.
let f = if cfg!(windows) {
fs::File::options().write(true).open(path)?
} else {
fs::File::open(path)?
};
f.set_times(times)
}
24 changes: 23 additions & 1 deletion src/bootstrap/src/utils/helpers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::io::Write;
use std::path::PathBuf;

use crate::utils::helpers::{
check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, symlink_dir,
check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, set_file_times,
symlink_dir,
};
use crate::{Config, Flags};

Expand Down Expand Up @@ -92,3 +93,24 @@ fn test_symlink_dir() {
#[cfg(not(windows))]
fs::remove_file(link_path).unwrap();
}

#[test]
fn test_set_file_times_sanity_check() {
let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]);
let tempfile = config.tempdir().join(".tmp-file");

{
File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap();
assert!(tempfile.exists());
}

// This might only fail on Windows (if file is default read-only then we try to modify file
// times).
let unix_epoch = std::time::SystemTime::UNIX_EPOCH;
let target_time = fs::FileTimes::new().set_accessed(unix_epoch).set_modified(unix_epoch);
set_file_times(&tempfile, target_time).unwrap();

let found_metadata = fs::metadata(tempfile).unwrap();
assert_eq!(found_metadata.accessed().unwrap(), unix_epoch);
assert_eq!(found_metadata.modified().unwrap(), unix_epoch)
}
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/external_deps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ impl LlvmAr {
self
}

/// Print the table of contents.
pub fn table_of_contents(&mut self) -> &mut Self {
self.cmd.arg("t");
self
}

/// Provide an output, then an input file. Bundled in one function, as llvm-ar has
/// no "--output"-style flag.
pub fn output_input(&mut self, out: impl AsRef<Path>, input: impl AsRef<Path>) -> &mut Self {
Expand Down
4 changes: 0 additions & 4 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ run-make/incr-add-rust-src-component/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/jobserver-error/Makefile
run-make/libs-through-symlinks/Makefile
run-make/libtest-json/Makefile
run-make/libtest-junit/Makefile
run-make/libtest-thread-limit/Makefile
run-make/macos-deployment-target/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/reproducible-build/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/split-debuginfo/Makefile
run-make/symbol-mangling-hashed/Makefile
run-make/translation/Makefile
Expand Down
11 changes: 11 additions & 0 deletions tests/crashes/128695.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ known-bug: rust-lang/rust#128695
//@ edition: 2021

use core::pin::{pin, Pin};

fn main() {
let fut = pin!(async {
let async_drop_fut = pin!(core::future::async_drop(async {}));
(async_drop_fut).await;
});
}
25 changes: 25 additions & 0 deletions tests/crashes/128810.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@ known-bug: rust-lang/rust#128810

#![feature(fn_delegation)]

use std::marker::PhantomData;

pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);

impl<'a> InvariantRef<'a, ()> {
pub const NEW: Self = InvariantRef::new(&());
}

trait Trait {
fn foo(&self) -> u8 { 0 }
fn bar(&self) -> u8 { 1 }
fn meh(&self) -> u8 { 2 }
}

struct Z(u8);

impl Trait for Z {
reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
}

fn main() { }
5 changes: 5 additions & 0 deletions tests/crashes/128848.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ known-bug: rust-lang/rust#128848

fn f<T>(a: T, b: T, c: T) {
f.call_once()
}
18 changes: 18 additions & 0 deletions tests/crashes/128870.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ known-bug: rust-lang/rust#128870
//@ compile-flags: -Zvalidate-mir

#[repr(packed)]
#[repr(u32)]
enum E {
A,
B,
C,
}

fn main() {
union InvalidTag {
int: u32,
e: E,
}
let _invalid_tag = InvalidTag { int: 4 };
}
16 changes: 16 additions & 0 deletions tests/crashes/129075.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: rust-lang/rust#129075
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes

struct Foo<T>([T; 2]);

impl<T: Default + Copy> Default for Foo<T> {
fn default(&mut self) -> Self {
Foo([Default::default(); 2])
}
}

fn field_array() {
let a: i32;
let b;
Foo([a, b]) = Default::default();
}
10 changes: 10 additions & 0 deletions tests/crashes/129095.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ known-bug: rust-lang/rust#129095
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir

pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
BYTES
}

pub fn main() {
assert_eq!(function_with_bytes::<b"AAAAb">(), &[0x41, 0x41, 0x41, 0x41]);
}
15 changes: 15 additions & 0 deletions tests/crashes/129099.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ known-bug: rust-lang/rust#129099

#![feature(type_alias_impl_trait)]

fn dyn_hoops<T: Sized>() -> dyn for<'a> Iterator<Item = impl Captures<'a>> {
loop {}
}

pub fn main() {
type Opaque = impl Sized;
fn define() -> Opaque {
let x: Opaque = dyn_hoops::<()>(0);
x
}
}
10 changes: 10 additions & 0 deletions tests/crashes/129109.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ known-bug: rust-lang/rust#129109
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir

extern "C" {
pub static mut symbol: [i8];
}

fn main() {
println!("C", unsafe { &symbol });
}
21 changes: 21 additions & 0 deletions tests/crashes/129127.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ known-bug: rust-lang/rust#129127
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir -Zcross-crate-inline-threshold=always




pub struct Rows<'a>();

impl<'a> Iterator for Rows<'a> {
type Item = ();

fn next() -> Option<Self::Item> {
let mut rows = Rows();
rows.map(|row| row).next()
}
}

fn main() {
let mut rows = Rows();
rows.next();
}
20 changes: 0 additions & 20 deletions tests/run-make/libtest-json/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion tests/run-make/libtest-json/output-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
{ "type": "test", "name": "c", "event": "ok" }
{ "type": "test", "event": "started", "name": "d" }
{ "type": "test", "name": "d", "event": "ignored", "message": "msg" }
{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": $TIME }
{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": "$EXEC_TIME" }
2 changes: 1 addition & 1 deletion tests/run-make/libtest-json/output-stdout-success.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
{ "type": "test", "name": "c", "event": "ok", "stdout": "thread 'c' panicked at f.rs:15:5:\nassertion failed: false\n" }
{ "type": "test", "event": "started", "name": "d" }
{ "type": "test", "name": "d", "event": "ignored", "message": "msg" }
{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": $TIME }
{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": "$EXEC_TIME" }
31 changes: 31 additions & 0 deletions tests/run-make/libtest-json/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Check libtest's JSON output against snapshots.

//@ ignore-cross-compile
//@ needs-unwind (test file contains #[should_panic] test)

use run_make_support::{cmd, diff, python_command, rustc};

fn main() {
rustc().arg("--test").input("f.rs").run();

run_tests(&[], "output-default.json");
run_tests(&["--show-output"], "output-stdout-success.json");
}

#[track_caller]
fn run_tests(extra_args: &[&str], expected_file: &str) {
let cmd_out = cmd("./f")
.env("RUST_BACKTRACE", "0")
.args(&["-Zunstable-options", "--test-threads=1", "--format=json"])
.args(extra_args)
.run_fail();
let test_stdout = &cmd_out.stdout_utf8();

python_command().arg("validate_json.py").stdin(test_stdout).run();

diff()
.expected_file(expected_file)
.actual_text("stdout", test_stdout)
.normalize(r#"(?<prefix>"exec_time": )[0-9.]+"#, r#"${prefix}"$$EXEC_TIME""#)
.run();
}
Loading
Loading