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 6 pull requests #96994

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5765819
Add test of temporaries inside format_args of core/std macros
dtolnay Apr 26, 2022
6f10c0a
Make write/print macros eagerly drop temporaries
dtolnay Apr 26, 2022
a03f15a
Bless tests following write/print macros change
dtolnay Apr 26, 2022
b2316c1
Add test skip support
chbaker0 Apr 27, 2022
4ce68c1
Clarify what values `BorrowedHandle`, `OwnedHandle` etc. can hold.
sunfishcode May 11, 2022
2bb7fdb
Also document that `as_raw_handle` may return NULL.
sunfishcode May 11, 2022
0a39e5a
Fix incorrect mentions of `OwnedFd` and `BorrowedFd` in Windows docs.
sunfishcode May 11, 2022
2f75b4a
HandleOrNull can hold null, and HandleOrInvalid can hold INVALID_HAND…
sunfishcode May 11, 2022
cdbfd3e
Add test of matches macro for trailing commas
May 11, 2022
c586bc3
Prevent unwinding when `-C panic=abort` is used regardless declared ABI
nbdd0121 May 11, 2022
516a7fa
Relax the wording about the meaning of -1.
sunfishcode May 12, 2022
275812a
Fix comment syntax.
sunfishcode May 12, 2022
a315bb4
Expand c-unwind-abi-panic-abort test
nbdd0121 May 12, 2022
d3fd6bf
rustdoc: fix GUI crash when searching for magic JS property values
notriddle May 12, 2022
eaf976c
Rollup merge of #96455 - dtolnay:writetmp, r=m-ou-se
GuillaumeGomez May 12, 2022
c7e56bb
Rollup merge of #96493 - chbaker0:issue-96342-fix, r=Mark-Simulacrum
GuillaumeGomez May 12, 2022
69581f8
Rollup merge of #96932 - sunfishcode:sunfishcode/document-borrowed-ha…
GuillaumeGomez May 12, 2022
77b003d
Rollup merge of #96948 - ludfo774:macro-trailing-comma-test, r=joshtr…
GuillaumeGomez May 12, 2022
8310eb8
Rollup merge of #96959 - nbdd0121:unwind, r=Amanieu
GuillaumeGomez May 12, 2022
c5ea430
Rollup merge of #96993 - notriddle:notriddle/prototype, r=GuillaumeGomez
GuillaumeGomez May 12, 2022
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
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,14 @@ pub fn fn_can_unwind<'tcx>(tcx: TyCtxt<'tcx>, fn_def_id: Option<DefId>, abi: Spe
return false;
}

// With `-C panic=abort`, all non-FFI functions are required to not unwind.
//
// Note that this is true regardless ABI specified on the function -- a `extern "C-unwind"`
// function defined in Rust is also required to abort.
if tcx.sess.panic_strategy() == PanicStrategy::Abort && !tcx.is_foreign_item(did) {
return false;
}

// With -Z panic-in-drop=abort, drop_in_place never unwinds.
//
// This is not part of `codegen_fn_attrs` as it can differ between crates
Expand Down
14 changes: 8 additions & 6 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,10 @@ macro_rules! r#try {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")]
macro_rules! write {
($dst:expr, $($arg:tt)*) => {
$dst.write_fmt($crate::format_args!($($arg)*))
};
($dst:expr, $($arg:tt)*) => {{
let result = $dst.write_fmt($crate::format_args!($($arg)*));
result
}};
}

/// Write formatted data into a buffer, with a newline appended.
Expand Down Expand Up @@ -553,9 +554,10 @@ macro_rules! writeln {
($dst:expr $(,)?) => {
$crate::write!($dst, "\n")
};
($dst:expr, $($arg:tt)*) => {
$dst.write_fmt($crate::format_args_nl!($($arg)*))
};
($dst:expr, $($arg:tt)*) => {{
let result = $dst.write_fmt($crate::format_args_nl!($($arg)*));
result
}};
}

/// Indicates unreachable code.
Expand Down
12 changes: 6 additions & 6 deletions library/std/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ macro_rules! panic {
#[cfg_attr(not(test), rustc_diagnostic_item = "print_macro")]
#[allow_internal_unstable(print_internals)]
macro_rules! print {
($($arg:tt)*) => {
$crate::io::_print($crate::format_args!($($arg)*))
};
($($arg:tt)*) => {{
$crate::io::_print($crate::format_args!($($arg)*));
}};
}

/// Prints to the standard output, with a newline.
Expand Down Expand Up @@ -133,9 +133,9 @@ macro_rules! println {
#[cfg_attr(not(test), rustc_diagnostic_item = "eprint_macro")]
#[allow_internal_unstable(print_internals)]
macro_rules! eprint {
($($arg:tt)*) => {
$crate::io::_eprint($crate::format_args!($($arg)*))
};
($($arg:tt)*) => {{
$crate::io::_eprint($crate::format_args!($($arg)*));
}};
}

/// Prints to the standard error, with a newline.
Expand Down
31 changes: 19 additions & 12 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
/// so it can be used in FFI in places where a handle is passed as an argument,
/// it is not captured or consumed.
///
/// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
/// sometimes a valid handle value. See [here] for the full story.
/// Note that it *may* have the value `-1`, which in `BorrowedHandle` always
/// represents a valid handle value, such as [the current process handle], and
/// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
/// [here] for the full story.
///
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
/// detached from processes, or when `windows_subsystem` is used.
Expand All @@ -33,6 +35,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
/// handle, which is then borrowed under the same lifetime.
///
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
#[derive(Copy, Clone)]
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
Expand All @@ -45,8 +48,10 @@ pub struct BorrowedHandle<'handle> {
///
/// This closes the handle on drop.
///
/// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
/// sometimes a valid handle value. See [here] for the full story.
/// Note that it *may* have the value `-1`, which in `OwnedHandle` always
/// represents a valid handle value, such as [the current process handle], and
/// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
/// [here] for the full story.
///
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
/// detached from processes, or when `windows_subsystem` is used.
Expand All @@ -59,6 +64,7 @@ pub struct BorrowedHandle<'handle> {
/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
///
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
pub struct OwnedHandle {
Expand All @@ -75,11 +81,13 @@ pub struct OwnedHandle {
/// `NULL`. This ensures that such FFI calls cannot start using the handle without
/// checking for `NULL` first.
///
/// This type considers any value other than `NULL` to be valid, including `INVALID_HANDLE_VALUE`.
/// This is because APIs that use `NULL` as their sentry value don't treat `INVALID_HANDLE_VALUE`
/// as special.
/// This type may hold any handle value that [`OwnedHandle`] may hold. As with `OwnedHandle`, when
/// it holds `-1`, that value is interpreted as a valid handle value, such as
/// [the current process handle], and not `INVALID_HANDLE_VALUE`.
///
/// If this holds a valid handle, it will close the handle on drop.
/// If this holds a non-null handle, it will close the handle on drop.
///
/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
#[derive(Debug)]
Expand All @@ -95,11 +103,10 @@ pub struct HandleOrNull(OwnedHandle);
/// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without
/// checking for `INVALID_HANDLE_VALUE` first.
///
/// This type considers any value other than `INVALID_HANDLE_VALUE` to be valid, including `NULL`.
/// This is because APIs that use `INVALID_HANDLE_VALUE` as their sentry value may return `NULL`
/// under `windows_subsystem = "windows"` or other situations where I/O devices are detached.
/// This type may hold any handle value that [`OwnedHandle`] may hold, except that when it holds
/// `-1`, that value is interpreted to mean `INVALID_HANDLE_VALUE`.
///
/// If this holds a valid handle, it will close the handle on drop.
/// If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop.
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
#[derive(Debug)]
Expand Down
7 changes: 7 additions & 0 deletions library/std/src/os/windows/io/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ pub trait AsRawHandle {
/// raw handle to the caller, and the handle is only guaranteed
/// to be valid while the original object has not yet been destroyed.
///
/// This function may return null, such as when called on [`Stdin`],
/// [`Stdout`], or [`Stderr`] when the console is detached.
///
/// However, borrowing is not strictly required. See [`AsHandle::as_handle`]
/// for an API which strictly borrows a handle.
///
/// [`Stdin`]: io::Stdin
/// [`Stdout`]: io::Stdout
/// [`Stderr`]: io::Stderr
#[stable(feature = "rust1", since = "1.0.0")]
fn as_raw_handle(&self) -> RawHandle;
}
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ mod dist {
config.stage = 0;
config.cmd = Subcommand::Test {
paths: vec!["library/std".into()],
skip: vec![],
test_args: vec![],
rustc_args: vec![],
fail_fast: true,
Expand Down Expand Up @@ -577,6 +578,7 @@ mod dist {
let mut config = configure(&["A"], &["A"]);
config.cmd = Subcommand::Test {
paths: vec![],
skip: vec![],
test_args: vec![],
rustc_args: vec![],
fail_fast: true,
Expand Down
21 changes: 19 additions & 2 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub enum Subcommand {
compare_mode: Option<String>,
pass: Option<String>,
run: Option<String>,
skip: Vec<String>,
test_args: Vec<String>,
rustc_args: Vec<String>,
fail_fast: bool,
Expand Down Expand Up @@ -261,6 +262,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
match subcommand {
Kind::Test => {
opts.optflag("", "no-fail-fast", "Run all tests regardless of failure");
opts.optmulti("", "skip", "skips tests matching SUBSTRING, if supported by test tool. May be passed multiple times", "SUBSTRING");
opts.optmulti(
"",
"test-args",
Expand Down Expand Up @@ -545,6 +547,7 @@ Arguments:
compare_mode: matches.opt_str("compare-mode"),
pass: matches.opt_str("pass"),
run: matches.opt_str("run"),
skip: matches.opt_strs("skip"),
test_args: matches.opt_strs("test-args"),
rustc_args: matches.opt_strs("rustc-args"),
fail_fast: !matches.opt_present("no-fail-fast"),
Expand Down Expand Up @@ -689,12 +692,26 @@ impl Subcommand {
}

pub fn test_args(&self) -> Vec<&str> {
let mut args = vec![];

match *self {
Subcommand::Test { ref skip, .. } => {
for s in skip {
args.push("--skip");
args.push(s.as_str());
}
}
_ => (),
};

match *self {
Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => {
test_args.iter().flat_map(|s| s.split_whitespace()).collect()
args.extend(test_args.iter().flat_map(|s| s.split_whitespace()))
}
_ => Vec::new(),
_ => (),
}

args
}

pub fn rustc_args(&self) -> Vec<&str> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ window.initSearch = rawSearchIndex => {
*/
let searchIndex;
let currentResults;
const ALIASES = {};
const ALIASES = Object.create(null);
const params = searchState.getQueryStringParams();

// Populate search bar with query string search term when provided,
Expand Down Expand Up @@ -1953,7 +1953,7 @@ window.initSearch = rawSearchIndex => {
}

if (aliases) {
ALIASES[crate] = {};
ALIASES[crate] = Object.create(null);
for (const alias_name in aliases) {
if (!hasOwnPropertyRustdoc(aliases, alias_name)) {
continue;
Expand Down
19 changes: 12 additions & 7 deletions src/test/codegen/unwind-abis/c-unwind-abi-panic-abort.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
// compile-flags: -C panic=abort

// Test that `nounwind` atributes are not applied to `C-unwind` extern functions
// even when the code is compiled with `panic=abort`.
// Test that `nounwind` atributes are also applied to extern `C-unwind` Rust functions
// when the code is compiled with `panic=abort`.

#![crate_type = "lib"]
#![feature(c_unwind)]

extern "C-unwind" {
fn may_unwind();
}

// CHECK: @rust_item_that_can_unwind() unnamed_addr #0
#[no_mangle]
pub unsafe extern "C-unwind" fn rust_item_that_can_unwind() {
// CHECK: call void @_ZN4core9panicking15panic_no_unwind
may_unwind();
}

extern "C-unwind" {
// CHECK: @may_unwind() unnamed_addr #1
fn may_unwind();
}

// Now, make sure that the LLVM attributes for this functions are correct. First, make
// sure that the first item is correctly marked with the `nounwind` attribute:
//
// CHECK-NOT: attributes #0 = { {{.*}}nounwind{{.*}} }
// CHECK: attributes #0 = { {{.*}}nounwind{{.*}} }
//
// Now, check that foreign item is correctly marked without the `nounwind` attribute.
// CHECK-NOT: attributes #1 = { {{.*}}nounwind{{.*}} }
16 changes: 16 additions & 0 deletions src/test/rustdoc-js/prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// exact-check

const QUERY = ['constructor', '__proto__'];

const EXPECTED = [
{
'others': [],
'returned': [],
'in_args': [],
},
{
'others': [],
'returned': [],
'in_args': [],
},
];
4 changes: 4 additions & 0 deletions src/test/rustdoc-js/prototype.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// The alias needed to be there to reproduce the bug
// that used to be here.
#[doc(alias="other_alias")]
pub fn something_else() {}
70 changes: 70 additions & 0 deletions src/test/ui/macros/format-args-temporaries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// check-pass

use std::fmt::{self, Display};

struct Mutex;

impl Mutex {
fn lock(&self) -> MutexGuard {
MutexGuard(self)
}
}

struct MutexGuard<'a>(&'a Mutex);

impl<'a> Drop for MutexGuard<'a> {
fn drop(&mut self) {
// Empty but this is a necessary part of the repro. Otherwise borrow
// checker is fine with 'a dangling at the time that MutexGuard goes out
// of scope.
}
}

impl<'a> MutexGuard<'a> {
fn write_fmt(&self, _args: fmt::Arguments) {}
}

impl<'a> Display for MutexGuard<'a> {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
Ok(())
}
}

fn main() {
let _write = {
let out = Mutex;
let mutex = Mutex;
write!(out.lock(), "{}", mutex.lock()) /* no semicolon */
};

let _writeln = {
let out = Mutex;
let mutex = Mutex;
writeln!(out.lock(), "{}", mutex.lock()) /* no semicolon */
};

let _print = {
let mutex = Mutex;
print!("{}", mutex.lock()) /* no semicolon */
};

let _println = {
let mutex = Mutex;
println!("{}", mutex.lock()) /* no semicolon */
};

let _eprint = {
let mutex = Mutex;
eprint!("{}", mutex.lock()) /* no semicolon */
};

let _eprintln = {
let mutex = Mutex;
eprintln!("{}", mutex.lock()) /* no semicolon */
};

let _panic = {
let mutex = Mutex;
panic!("{}", mutex.lock()) /* no semicolon */
};
}
6 changes: 6 additions & 0 deletions src/test/ui/macros/macro-comma-support-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ fn line() {
let _ = line!();
}

#[test]
fn matches() {
let _ = matches!(1, x if x > 0);
let _ = matches!(1, x if x > 0,);
}

#[test]
fn module_path() {
let _ = module_path!();
Expand Down
4 changes: 4 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ pub struct Config {
/// Only run tests that match these filters
pub filters: Vec<String>,

/// Skip tests tests matching these substrings. Corresponds to
/// `test::TestOpts::skip`. `filter_exact` does not apply to these flags.
pub skip: Vec<String>,

/// Exactly match the filter, rather than a substring
pub filter_exact: bool,

Expand Down
Loading