Skip to content

Commit 885f27c

Browse files
committed
Auto merge of rust-lang#139845 - Zalathar:rollup-u5u5y1v, r=Zalathar
Rollup of 17 pull requests Successful merges: - rust-lang#138374 (Enable contracts for const functions) - rust-lang#138380 (ci: add runners for vanilla LLVM 20) - rust-lang#138393 (Allow const patterns of matches to contain pattern types) - rust-lang#139517 (std: sys: process: uefi: Use NULL stdin by default) - rust-lang#139554 (std: add Output::exit_ok) - rust-lang#139660 (compiletest: Add an experimental new executor to replace libtest) - rust-lang#139669 (Overhaul `AssocItem`) - rust-lang#139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file}) - rust-lang#139750 (std/thread: Use default stack size from menuconfig for NuttX) - rust-lang#139772 (Remove `hir::Map`) - rust-lang#139785 (Let CStrings be either 1 or 2 byte aligned.) - rust-lang#139789 (do not unnecessarily leak auto traits in item bounds) - rust-lang#139791 (drop global where-bounds before merging candidates) - rust-lang#139798 (normalize: prefer `ParamEnv` over `AliasBound` candidates) - rust-lang#139822 (Fix: Map EOPNOTSUPP to ErrorKind::Unsupported on Unix) - rust-lang#139833 (Fix some HIR pretty-printing problems) - rust-lang#139836 (Basic tests of MPMC receiver cloning) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 62e50de + a40f2d0 commit 885f27c

File tree

13 files changed

+280
-105
lines changed

13 files changed

+280
-105
lines changed

Diff for: core/src/contracts.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
33
pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_requires as requires};
44

5-
/// Emitted by rustc as a desugaring of `#[ensures(PRED)] fn foo() -> R { ... [return R;] ... }`
6-
/// into: `fn foo() { let _check = build_check_ensures(|ret| PRED) ... [return _check(R);] ... }`
7-
/// (including the implicit return of the tail expression, if any).
5+
/// This is an identity function used as part of the desugaring of the `#[ensures]` attribute.
6+
///
7+
/// This is an existing hack to allow users to omit the type of the return value in their ensures
8+
/// attribute.
9+
///
10+
/// Ideally, rustc should be able to generate the type annotation.
11+
/// The existing lowering logic makes it rather hard to add the explicit type annotation,
12+
/// while the function call is fairly straight forward.
813
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
14+
// Similar to `contract_check_requires`, we need to use the user-facing
15+
// `contracts` feature rather than the perma-unstable `contracts_internals`.
16+
// Const-checking doesn't honor allow_internal_unstable logic used by contract expansion.
17+
#[rustc_const_unstable(feature = "contracts", issue = "128044")]
918
#[lang = "contract_build_check_ensures"]
10-
#[track_caller]
11-
pub fn build_check_ensures<Ret, C>(cond: C) -> impl (Fn(Ret) -> Ret) + Copy
19+
pub const fn build_check_ensures<Ret, C>(cond: C) -> C
1220
where
13-
C: for<'a> Fn(&'a Ret) -> bool + Copy + 'static,
21+
C: Fn(&Ret) -> bool + Copy + 'static,
1422
{
15-
#[track_caller]
16-
move |ret| {
17-
crate::intrinsics::contract_check_ensures(&ret, cond);
18-
ret
19-
}
23+
cond
2024
}

Diff for: core/src/intrinsics/mod.rs

+48-6
Original file line numberDiff line numberDiff line change
@@ -3402,20 +3402,62 @@ pub const fn contract_checks() -> bool {
34023402
///
34033403
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
34043404
/// returns false.
3405-
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
3405+
///
3406+
/// Note that this function is a no-op during constant evaluation.
3407+
#[unstable(feature = "contracts_internals", issue = "128044")]
3408+
// Calls to this function get inserted by an AST expansion pass, which uses the equivalent of
3409+
// `#[allow_internal_unstable]` to allow using `contracts_internals` functions. Const-checking
3410+
// doesn't honor `#[allow_internal_unstable]`, so for the const feature gate we use the user-facing
3411+
// `contracts` feature rather than the perma-unstable `contracts_internals`
3412+
#[rustc_const_unstable(feature = "contracts", issue = "128044")]
34063413
#[lang = "contract_check_requires"]
34073414
#[rustc_intrinsic]
3408-
pub fn contract_check_requires<C: Fn() -> bool>(cond: C) {
3409-
if contract_checks() && !cond() {
3410-
// Emit no unwind panic in case this was a safety requirement.
3411-
crate::panicking::panic_nounwind("failed requires check");
3412-
}
3415+
pub const fn contract_check_requires<C: Fn() -> bool + Copy>(cond: C) {
3416+
const_eval_select!(
3417+
@capture[C: Fn() -> bool + Copy] { cond: C } :
3418+
if const {
3419+
// Do nothing
3420+
} else {
3421+
if contract_checks() && !cond() {
3422+
// Emit no unwind panic in case this was a safety requirement.
3423+
crate::panicking::panic_nounwind("failed requires check");
3424+
}
3425+
}
3426+
)
34133427
}
34143428

34153429
/// Check if the post-condition `cond` has been met.
34163430
///
34173431
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
34183432
/// returns false.
3433+
///
3434+
/// Note that this function is a no-op during constant evaluation.
3435+
#[cfg(not(bootstrap))]
3436+
#[unstable(feature = "contracts_internals", issue = "128044")]
3437+
// Similar to `contract_check_requires`, we need to use the user-facing
3438+
// `contracts` feature rather than the perma-unstable `contracts_internals`.
3439+
// Const-checking doesn't honor allow_internal_unstable logic used by contract expansion.
3440+
#[rustc_const_unstable(feature = "contracts", issue = "128044")]
3441+
#[lang = "contract_check_ensures"]
3442+
#[rustc_intrinsic]
3443+
pub const fn contract_check_ensures<C: Fn(&Ret) -> bool + Copy, Ret>(cond: C, ret: Ret) -> Ret {
3444+
const_eval_select!(
3445+
@capture[C: Fn(&Ret) -> bool + Copy, Ret] { cond: C, ret: Ret } -> Ret :
3446+
if const {
3447+
// Do nothing
3448+
ret
3449+
} else {
3450+
if contract_checks() && !cond(&ret) {
3451+
// Emit no unwind panic in case this was a safety requirement.
3452+
crate::panicking::panic_nounwind("failed ensures check");
3453+
}
3454+
ret
3455+
}
3456+
)
3457+
}
3458+
3459+
/// This is the old version of contract_check_ensures kept here for bootstrap only.
3460+
#[cfg(bootstrap)]
34193461
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
34203462
#[rustc_intrinsic]
34213463
pub fn contract_check_ensures<'a, Ret, C: Fn(&'a Ret) -> bool>(ret: &'a Ret, cond: C) {

Diff for: core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
#![feature(bstr)]
102102
#![feature(bstr_internals)]
103103
#![feature(cfg_match)]
104-
#![feature(closure_track_caller)]
105104
#![feature(const_carrying_mul_add)]
106105
#![feature(const_eval_select)]
107106
#![feature(core_intrinsics)]

Diff for: proc_macro/src/bridge/client.rs

-6
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ impl Clone for TokenStream {
111111
}
112112
}
113113

114-
impl Clone for SourceFile {
115-
fn clone(&self) -> Self {
116-
self.clone()
117-
}
118-
}
119-
120114
impl Span {
121115
pub(crate) fn def_site() -> Span {
122116
Bridge::with(|bridge| bridge.globals.def_site)

Diff for: proc_macro/src/bridge/mod.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,17 @@ macro_rules! with_api {
8181
$self: $S::TokenStream
8282
) -> Vec<TokenTree<$S::TokenStream, $S::Span, $S::Symbol>>;
8383
},
84-
SourceFile {
85-
fn drop($self: $S::SourceFile);
86-
fn clone($self: &$S::SourceFile) -> $S::SourceFile;
87-
fn eq($self: &$S::SourceFile, other: &$S::SourceFile) -> bool;
88-
fn path($self: &$S::SourceFile) -> String;
89-
fn is_real($self: &$S::SourceFile) -> bool;
90-
},
9184
Span {
9285
fn debug($self: $S::Span) -> String;
93-
fn source_file($self: $S::Span) -> $S::SourceFile;
9486
fn parent($self: $S::Span) -> Option<$S::Span>;
9587
fn source($self: $S::Span) -> $S::Span;
9688
fn byte_range($self: $S::Span) -> Range<usize>;
9789
fn start($self: $S::Span) -> $S::Span;
9890
fn end($self: $S::Span) -> $S::Span;
9991
fn line($self: $S::Span) -> usize;
10092
fn column($self: $S::Span) -> usize;
93+
fn file($self: $S::Span) -> String;
94+
fn local_file($self: $S::Span) -> Option<String>;
10195
fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
10296
fn subspan($self: $S::Span, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
10397
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
@@ -120,7 +114,6 @@ macro_rules! with_api_handle_types {
120114
'owned:
121115
FreeFunctions,
122116
TokenStream,
123-
SourceFile,
124117

125118
'interned:
126119
Span,

Diff for: proc_macro/src/bridge/server.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ with_api_handle_types!(define_server_handles);
8282
pub trait Types {
8383
type FreeFunctions: 'static;
8484
type TokenStream: 'static + Clone;
85-
type SourceFile: 'static + Clone;
8685
type Span: 'static + Copy + Eq + Hash;
8786
type Symbol: 'static;
8887
}

Diff for: proc_macro/src/lib.rs

+19-58
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,6 @@ impl Span {
491491
Span(bridge::client::Span::mixed_site())
492492
}
493493

494-
/// The original source file into which this span points.
495-
#[unstable(feature = "proc_macro_span", issue = "54725")]
496-
pub fn source_file(&self) -> SourceFile {
497-
SourceFile(self.0.source_file())
498-
}
499-
500494
/// The `Span` for the tokens in the previous macro expansion from which
501495
/// `self` was generated from, if any.
502496
#[unstable(feature = "proc_macro_span", issue = "54725")]
@@ -546,6 +540,25 @@ impl Span {
546540
self.0.column()
547541
}
548542

543+
/// The path to the source file in which this span occurs, for display purposes.
544+
///
545+
/// This might not correspond to a valid file system path.
546+
/// It might be remapped, or might be an artificial path such as `"<macro expansion>"`.
547+
#[unstable(feature = "proc_macro_span", issue = "54725")]
548+
pub fn file(&self) -> String {
549+
self.0.file()
550+
}
551+
552+
/// The path to the source file in which this span occurs on disk.
553+
///
554+
/// This is the actual path on disk. It is unaffected by path remapping.
555+
///
556+
/// This path should not be embedded in the output of the macro; prefer `file()` instead.
557+
#[unstable(feature = "proc_macro_span", issue = "54725")]
558+
pub fn local_file(&self) -> Option<PathBuf> {
559+
self.0.local_file().map(|s| PathBuf::from(s))
560+
}
561+
549562
/// Creates a new span encompassing `self` and `other`.
550563
///
551564
/// Returns `None` if `self` and `other` are from different files.
@@ -614,58 +627,6 @@ impl fmt::Debug for Span {
614627
}
615628
}
616629

617-
/// The source file of a given `Span`.
618-
#[unstable(feature = "proc_macro_span", issue = "54725")]
619-
#[derive(Clone)]
620-
pub struct SourceFile(bridge::client::SourceFile);
621-
622-
impl SourceFile {
623-
/// Gets the path to this source file.
624-
///
625-
/// ### Note
626-
/// If the code span associated with this `SourceFile` was generated by an external macro, this
627-
/// macro, this might not be an actual path on the filesystem. Use [`is_real`] to check.
628-
///
629-
/// Also note that even if `is_real` returns `true`, if `--remap-path-prefix` was passed on
630-
/// the command line, the path as given might not actually be valid.
631-
///
632-
/// [`is_real`]: Self::is_real
633-
#[unstable(feature = "proc_macro_span", issue = "54725")]
634-
pub fn path(&self) -> PathBuf {
635-
PathBuf::from(self.0.path())
636-
}
637-
638-
/// Returns `true` if this source file is a real source file, and not generated by an external
639-
/// macro's expansion.
640-
#[unstable(feature = "proc_macro_span", issue = "54725")]
641-
pub fn is_real(&self) -> bool {
642-
// This is a hack until intercrate spans are implemented and we can have real source files
643-
// for spans generated in external macros.
644-
// https://github.com/rust-lang/rust/pull/43604#issuecomment-333334368
645-
self.0.is_real()
646-
}
647-
}
648-
649-
#[unstable(feature = "proc_macro_span", issue = "54725")]
650-
impl fmt::Debug for SourceFile {
651-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
652-
f.debug_struct("SourceFile")
653-
.field("path", &self.path())
654-
.field("is_real", &self.is_real())
655-
.finish()
656-
}
657-
}
658-
659-
#[unstable(feature = "proc_macro_span", issue = "54725")]
660-
impl PartialEq for SourceFile {
661-
fn eq(&self, other: &Self) -> bool {
662-
self.0.eq(&other.0)
663-
}
664-
}
665-
666-
#[unstable(feature = "proc_macro_span", issue = "54725")]
667-
impl Eq for SourceFile {}
668-
669630
/// A single token or a delimited sequence of token trees (e.g., `[1, (), ..]`).
670631
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
671632
#[derive(Clone)]

Diff for: std/src/process.rs

+34
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,40 @@ pub struct Output {
12861286
pub stderr: Vec<u8>,
12871287
}
12881288

1289+
impl Output {
1290+
/// Returns an error if a nonzero exit status was received.
1291+
///
1292+
/// If the [`Command`] exited successfully,
1293+
/// `self` is returned.
1294+
///
1295+
/// This is equivalent to calling [`exit_ok`](ExitStatus::exit_ok)
1296+
/// on [`Output.status`](Output::status).
1297+
///
1298+
/// Note that this will throw away the [`Output::stderr`] field in the error case.
1299+
/// If the child process outputs useful informantion to stderr, you can:
1300+
/// * Use `cmd.stderr(Stdio::inherit())` to forward the
1301+
/// stderr child process to the parent's stderr,
1302+
/// usually printing it to console where the user can see it.
1303+
/// This is usually correct for command-line applications.
1304+
/// * Capture `stderr` using a custom error type.
1305+
/// This is usually correct for libraries.
1306+
///
1307+
/// # Examples
1308+
///
1309+
/// ```
1310+
/// #![feature(exit_status_error)]
1311+
/// # #[cfg(unix)] {
1312+
/// use std::process::Command;
1313+
/// assert!(Command::new("false").output().unwrap().exit_ok().is_err());
1314+
/// # }
1315+
/// ```
1316+
#[unstable(feature = "exit_status_error", issue = "84908")]
1317+
pub fn exit_ok(self) -> Result<Self, ExitStatusError> {
1318+
self.status.exit_ok()?;
1319+
Ok(self)
1320+
}
1321+
}
1322+
12891323
// If either stderr or stdout are valid utf8 strings it prints the valid
12901324
// strings, otherwise it prints the byte sequence instead
12911325
#[stable(feature = "process_output_debug", since = "1.7.0")]

Diff for: std/src/sys/pal/unix/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
274274
libc::ETXTBSY => ExecutableFileBusy,
275275
libc::EXDEV => CrossesDevices,
276276
libc::EINPROGRESS => InProgress,
277+
libc::EOPNOTSUPP => Unsupported,
277278

278279
libc::EACCES | libc::EPERM => PermissionDenied,
279280

Diff for: std/src/sys/pal/unix/thread.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ use crate::sys::weak::weak;
88
use crate::sys::{os, stack_overflow};
99
use crate::time::Duration;
1010
use crate::{cmp, io, ptr};
11-
#[cfg(not(any(target_os = "l4re", target_os = "vxworks", target_os = "espidf")))]
11+
#[cfg(not(any(
12+
target_os = "l4re",
13+
target_os = "vxworks",
14+
target_os = "espidf",
15+
target_os = "nuttx"
16+
)))]
1217
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
1318
#[cfg(target_os = "l4re")]
1419
pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024;
1520
#[cfg(target_os = "vxworks")]
1621
pub const DEFAULT_MIN_STACK_SIZE: usize = 256 * 1024;
17-
#[cfg(target_os = "espidf")]
18-
pub const DEFAULT_MIN_STACK_SIZE: usize = 0; // 0 indicates that the stack size configured in the ESP-IDF menuconfig system should be used
22+
#[cfg(any(target_os = "espidf", target_os = "nuttx"))]
23+
pub const DEFAULT_MIN_STACK_SIZE: usize = 0; // 0 indicates that the stack size configured in the ESP-IDF/NuttX menuconfig system should be used
1924

2025
#[cfg(target_os = "fuchsia")]
2126
mod zircon {
@@ -52,10 +57,10 @@ impl Thread {
5257
let mut attr: mem::MaybeUninit<libc::pthread_attr_t> = mem::MaybeUninit::uninit();
5358
assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0);
5459

55-
#[cfg(target_os = "espidf")]
60+
#[cfg(any(target_os = "espidf", target_os = "nuttx"))]
5661
if stack > 0 {
5762
// Only set the stack if a non-zero value is passed
58-
// 0 is used as an indication that the default stack size configured in the ESP-IDF menuconfig system should be used
63+
// 0 is used as an indication that the default stack size configured in the ESP-IDF/NuttX menuconfig system should be used
5964
assert_eq!(
6065
libc::pthread_attr_setstacksize(
6166
attr.as_mut_ptr(),
@@ -65,7 +70,7 @@ impl Thread {
6570
);
6671
}
6772

68-
#[cfg(not(target_os = "espidf"))]
73+
#[cfg(not(any(target_os = "espidf", target_os = "nuttx")))]
6974
{
7075
let stack_size = cmp::max(stack, min_stack_size(attr.as_ptr()));
7176

0 commit comments

Comments
 (0)