Skip to content

Commit 6982935

Browse files
committed
Auto merge of #125280 - compiler-errors:rollup-401itda, r=compiler-errors
Rollup of 7 pull requests Successful merges: - #123709 (Update documentation related to the recent cmd.exe fix) - #124304 (revise the interpretation of ReadDir for HermitOS) - #124708 (Actually use the `#[do_not_recommend]` attribute if present) - #125252 (Add `#[inline]` to float `Debug` fallback used by `cfg(no_fp_fmt_parse)`) - #125261 (crashes: add more) - #125270 (Followup fixes from #123344) - #125275 (Migrate `run-make/rustdoc-scrape-examples-test` to new `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7d2a95b + e959fd6 commit 6982935

File tree

42 files changed

+474
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+474
-170
lines changed

compiler/rustc_ast/src/ast.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,13 @@ pub enum UseTreeKind {
27332733
/// `use prefix` or `use prefix as rename`
27342734
Simple(Option<Ident>),
27352735
/// `use prefix::{...}`
2736+
///
2737+
/// The span represents the braces of the nested group and all elements within:
2738+
///
2739+
/// ```text
2740+
/// use foo::{bar, baz};
2741+
/// ^^^^^^^^^^
2742+
/// ```
27362743
Nested { items: ThinVec<(UseTree, NodeId)>, span: Span },
27372744
/// `use prefix::*`
27382745
Glob,

compiler/rustc_resolve/src/check_unused.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -299,21 +299,21 @@ fn calc_unused_spans(
299299

300300
let mut unused_spans = Vec::new();
301301
let mut to_remove = Vec::new();
302-
let mut used_childs = 0;
302+
let mut used_children = 0;
303303
let mut contains_self = false;
304304
let mut previous_unused = false;
305305
for (pos, (use_tree, use_tree_id)) in nested.iter().enumerate() {
306306
let remove = match calc_unused_spans(unused_import, use_tree, *use_tree_id) {
307307
UnusedSpanResult::Used => {
308-
used_childs += 1;
308+
used_children += 1;
309309
None
310310
}
311311
UnusedSpanResult::Unused { mut spans, remove } => {
312312
unused_spans.append(&mut spans);
313313
Some(remove)
314314
}
315315
UnusedSpanResult::PartialUnused { mut spans, remove: mut to_remove_extra } => {
316-
used_childs += 1;
316+
used_children += 1;
317317
unused_spans.append(&mut spans);
318318
to_remove.append(&mut to_remove_extra);
319319
None
@@ -322,7 +322,7 @@ fn calc_unused_spans(
322322
if let Some(remove) = remove {
323323
let remove_span = if nested.len() == 1 {
324324
remove
325-
} else if pos == nested.len() - 1 || used_childs > 0 {
325+
} else if pos == nested.len() - 1 || used_children > 0 {
326326
// Delete everything from the end of the last import, to delete the
327327
// previous comma
328328
nested[pos - 1].0.span.shrink_to_hi().to(use_tree.span)
@@ -346,7 +346,7 @@ fn calc_unused_spans(
346346
}
347347
if unused_spans.is_empty() {
348348
UnusedSpanResult::Used
349-
} else if used_childs == 0 {
349+
} else if used_children == 0 {
350350
UnusedSpanResult::Unused { spans: unused_spans, remove: full_span }
351351
} else {
352352
// If there is only one remaining child that is used, the braces around the use
@@ -360,7 +360,7 @@ fn calc_unused_spans(
360360
// `self`: `use foo::{self};` is valid Rust syntax, while `use foo::self;` errors
361361
// out. We also cannot turn `use foo::{self}` into `use foo`, as the former doesn't
362362
// import types with the same name as the module.
363-
if used_childs == 1 && !contains_self {
363+
if used_children == 1 && !contains_self {
364364
// Left brace, from the start of the nested group to the first item.
365365
to_remove.push(
366366
tree_span.shrink_to_lo().to(nested.first().unwrap().0.span.shrink_to_lo()),

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+26
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
422422
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) => {
423423
let trait_predicate = bound_predicate.rebind(trait_predicate);
424424
let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
425+
let trait_predicate = self.apply_do_not_recommend(trait_predicate, &mut obligation);
425426

426427
// Let's use the root obligation as the main message, when we care about the
427428
// most general case ("X doesn't implement Pattern<'_>") over the case that
@@ -1003,6 +1004,31 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10031004
err.emit()
10041005
}
10051006

1007+
fn apply_do_not_recommend(
1008+
&self,
1009+
mut trait_predicate: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
1010+
obligation: &'_ mut PredicateObligation<'tcx>,
1011+
) -> ty::Binder<'tcx, ty::TraitPredicate<'tcx>> {
1012+
let mut base_cause = obligation.cause.code().clone();
1013+
loop {
1014+
if let ObligationCauseCode::ImplDerived(ref c) = base_cause {
1015+
if self.tcx.has_attr(c.impl_or_alias_def_id, sym::do_not_recommend) {
1016+
let code = (*c.derived.parent_code).clone();
1017+
obligation.cause.map_code(|_| code);
1018+
obligation.predicate = c.derived.parent_trait_pred.upcast(self.tcx);
1019+
trait_predicate = c.derived.parent_trait_pred.clone();
1020+
}
1021+
}
1022+
if let Some((parent_cause, _parent_pred)) = base_cause.parent() {
1023+
base_cause = parent_cause.clone();
1024+
} else {
1025+
break;
1026+
}
1027+
}
1028+
1029+
trait_predicate
1030+
}
1031+
10061032
fn emit_specialized_closure_kind_error(
10071033
&self,
10081034
obligation: &PredicateObligation<'tcx>,

library/core/src/fmt/nofloat.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ macro_rules! floating {
44
($ty:ident) => {
55
#[stable(feature = "rust1", since = "1.0.0")]
66
impl Debug for $ty {
7+
#[inline]
78
fn fmt(&self, _fmt: &mut Formatter<'_>) -> Result {
89
panic!("floating point support is turned off");
910
}

library/std/src/os/hermit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#[allow(unused_extern_crates)]
44
#[stable(feature = "rust1", since = "1.0.0")]
5-
pub extern crate hermit_abi as abi;
5+
pub extern crate hermit_abi;
66

77
pub mod ffi;
88
pub mod io;

library/std/src/os/windows/process.rs

+32-17
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ pub trait CommandExt: Sealed {
199199

200200
/// Append literal text to the command line without any quoting or escaping.
201201
///
202-
/// This is useful for passing arguments to applications which doesn't follow
202+
/// This is useful for passing arguments to applications that don't follow
203203
/// the standard C run-time escaping rules, such as `cmd.exe /c`.
204204
///
205-
/// # Bat files
205+
/// # Batch files
206206
///
207-
/// Note the `cmd /c` command line has slightly different escaping rules then bat files
207+
/// Note the `cmd /c` command line has slightly different escaping rules than batch files
208208
/// themselves. If possible, it may be better to write complex arguments to a temporary
209-
/// .bat file, with appropriate escaping, and simply run that using:
209+
/// `.bat` file, with appropriate escaping, and simply run that using:
210210
///
211211
/// ```no_run
212212
/// # use std::process::Command;
@@ -217,7 +217,7 @@ pub trait CommandExt: Sealed {
217217
///
218218
/// # Example
219219
///
220-
/// Run a bat script using both trusted and untrusted arguments.
220+
/// Run a batch script using both trusted and untrusted arguments.
221221
///
222222
/// ```no_run
223223
/// #[cfg(windows)]
@@ -241,9 +241,10 @@ pub trait CommandExt: Sealed {
241241
/// if !user_name.chars().all(|c| c.is_alphanumeric()) {
242242
/// return Err(Error::new(ErrorKind::InvalidInput, "invalid user name"));
243243
/// }
244-
/// // now we've checked the user name, let's add that too.
245-
/// cmd_args.push(' ');
246-
/// cmd_args.push_str(&format!("--user {user_name}"));
244+
///
245+
/// // now we have validated the user name, let's add that too.
246+
/// cmd_args.push_str(" --user ");
247+
/// cmd_args.push_str(user_name);
247248
///
248249
/// // call cmd.exe and return the output
249250
/// Command::new("cmd.exe")
@@ -287,25 +288,37 @@ pub trait CommandExt: Sealed {
287288
#[unstable(feature = "windows_process_extensions_async_pipes", issue = "98289")]
288289
fn async_pipes(&mut self, always_async: bool) -> &mut process::Command;
289290

290-
/// Sets a raw attribute on the command, providing extended configuration options for Windows processes.
291+
/// Set a raw attribute on the command, providing extended configuration options for Windows
292+
/// processes.
293+
///
294+
/// This method allows you to specify custom attributes for a child process on Windows systems
295+
/// using raw attribute values. Raw attributes provide extended configurability for process
296+
/// creation, but their usage can be complex and potentially unsafe.
291297
///
292-
/// This method allows you to specify custom attributes for a child process on Windows systems using raw attribute values.
293-
/// Raw attributes provide extended configurability for process creation, but their usage can be complex and potentially unsafe.
298+
/// The `attribute` parameter specifies the raw attribute to be set, while the `value`
299+
/// parameter holds the value associated with that attribute. Please refer to the
300+
/// [`windows-rs` documentation] or the [Win32 API documentation] for detailed information
301+
/// about available attributes and their meanings.
294302
///
295-
/// The `attribute` parameter specifies the raw attribute to be set, while the `value` parameter holds the value associated with that attribute.
296-
/// Please refer to the [`windows-rs`](https://microsoft.github.io/windows-docs-rs/doc/windows/) documentation or the [`Win32 API documentation`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute) for detailed information about available attributes and their meanings.
303+
/// [`windows-rs` documentation]: https://microsoft.github.io/windows-docs-rs/doc/windows/
304+
/// [Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute
297305
///
298306
/// # Note
299307
///
300308
/// The maximum number of raw attributes is the value of [`u32::MAX`].
301-
/// If this limit is exceeded, the call to [`process::Command::spawn`] will return an `Error` indicating that the maximum number of attributes has been exceeded.
309+
/// If this limit is exceeded, the call to [`process::Command::spawn`] will return an `Error`
310+
/// indicating that the maximum number of attributes has been exceeded.
311+
///
302312
/// # Safety
303313
///
304-
/// The usage of raw attributes is potentially unsafe and should be done with caution. Incorrect attribute values or improper configuration can lead to unexpected behavior or errors.
314+
/// The usage of raw attributes is potentially unsafe and should be done with caution.
315+
/// Incorrect attribute values or improper configuration can lead to unexpected behavior or
316+
/// errors.
305317
///
306318
/// # Example
307319
///
308-
/// The following example demonstrates how to create a child process with a specific parent process ID using a raw attribute.
320+
/// The following example demonstrates how to create a child process with a specific parent
321+
/// process ID using a raw attribute.
309322
///
310323
/// ```rust
311324
/// #![feature(windows_process_extensions_raw_attribute)]
@@ -339,7 +352,9 @@ pub trait CommandExt: Sealed {
339352
///
340353
/// # Safety Note
341354
///
342-
/// Remember that improper use of raw attributes can lead to undefined behavior or security vulnerabilities. Always consult the documentation and ensure proper attribute values are used.
355+
/// Remember that improper use of raw attributes can lead to undefined behavior or security
356+
/// vulnerabilities. Always consult the documentation and ensure proper attribute values are
357+
/// used.
343358
#[unstable(feature = "windows_process_extensions_raw_attribute", issue = "114854")]
344359
unsafe fn raw_attribute<T: Copy + Send + Sync + 'static>(
345360
&mut self,

library/std/src/process.rs

+27-21
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
//!
9191
//! # Windows argument splitting
9292
//!
93-
//! On Unix systems arguments are passed to a new process as an array of strings
94-
//! but on Windows arguments are passed as a single commandline string and it's
93+
//! On Unix systems arguments are passed to a new process as an array of strings,
94+
//! but on Windows arguments are passed as a single commandline string and it is
9595
//! up to the child process to parse it into an array. Therefore the parent and
9696
//! child processes must agree on how the commandline string is encoded.
9797
//!
@@ -107,26 +107,26 @@
107107
//! * Use [`raw_arg`] to build a custom commandline. This bypasses the escaping
108108
//! rules used by [`arg`] so should be used with due caution.
109109
//!
110-
//! `cmd.exe` and `.bat` use non-standard argument parsing and are especially
110+
//! `cmd.exe` and `.bat` files use non-standard argument parsing and are especially
111111
//! vulnerable to malicious input as they may be used to run arbitrary shell
112112
//! commands. Untrusted arguments should be restricted as much as possible.
113113
//! For examples on handling this see [`raw_arg`].
114114
//!
115-
//! ### Bat file special handling
115+
//! ### Batch file special handling
116116
//!
117117
//! On Windows, `Command` uses the Windows API function [`CreateProcessW`] to
118-
//! spawn new processes. An undocumented feature of this function is that,
118+
//! spawn new processes. An undocumented feature of this function is that
119119
//! when given a `.bat` file as the application to run, it will automatically
120-
//! convert that into running `cmd.exe /c` with the bat file as the next argument.
120+
//! convert that into running `cmd.exe /c` with the batch file as the next argument.
121121
//!
122122
//! For historical reasons Rust currently preserves this behaviour when using
123123
//! [`Command::new`], and escapes the arguments according to `cmd.exe` rules.
124124
//! Due to the complexity of `cmd.exe` argument handling, it might not be
125-
//! possible to safely escape some special chars, and using them will result
125+
//! possible to safely escape some special characters, and using them will result
126126
//! in an error being returned at process spawn. The set of unescapeable
127-
//! special chars might change between releases.
127+
//! special characters might change between releases.
128128
//!
129-
//! Also note that running `.bat` scripts in this way may be removed in the
129+
//! Also note that running batch scripts in this way may be removed in the
130130
//! future and so should not be relied upon.
131131
//!
132132
//! [`spawn`]: Command::spawn
@@ -659,16 +659,19 @@ impl Command {
659659
///
660660
/// Note that the argument is not passed through a shell, but given
661661
/// literally to the program. This means that shell syntax like quotes,
662-
/// escaped characters, word splitting, glob patterns, variable substitution, etc.
663-
/// have no effect.
662+
/// escaped characters, word splitting, glob patterns, variable substitution,
663+
/// etc. have no effect.
664664
///
665665
/// <div class="warning">
666666
///
667-
/// On Windows use caution with untrusted inputs. Most applications use the
668-
/// standard convention for decoding arguments passed to them. These are safe to use with `arg`.
669-
/// However some applications, such as `cmd.exe` and `.bat` files, use a non-standard way of decoding arguments
670-
/// and are therefore vulnerable to malicious input.
671-
/// In the case of `cmd.exe` this is especially important because a malicious argument can potentially run arbitrary shell commands.
667+
/// On Windows, use caution with untrusted inputs. Most applications use the
668+
/// standard convention for decoding arguments passed to them. These are safe to
669+
/// use with `arg`. However, some applications such as `cmd.exe` and `.bat` files
670+
/// use a non-standard way of decoding arguments. They are therefore vulnerable
671+
/// to malicious input.
672+
///
673+
/// In the case of `cmd.exe` this is especially important because a malicious
674+
/// argument can potentially run arbitrary shell commands.
672675
///
673676
/// See [Windows argument splitting][windows-args] for more details
674677
/// or [`raw_arg`] for manually implementing non-standard argument encoding.
@@ -710,11 +713,14 @@ impl Command {
710713
///
711714
/// <div class="warning">
712715
///
713-
/// On Windows use caution with untrusted inputs. Most applications use the
714-
/// standard convention for decoding arguments passed to them. These are safe to use with `args`.
715-
/// However some applications, such as `cmd.exe` and `.bat` files, use a non-standard way of decoding arguments
716-
/// and are therefore vulnerable to malicious input.
717-
/// In the case of `cmd.exe` this is especially important because a malicious argument can potentially run arbitrary shell commands.
716+
/// On Windows, use caution with untrusted inputs. Most applications use the
717+
/// standard convention for decoding arguments passed to them. These are safe to
718+
/// use with `arg`. However, some applications such as `cmd.exe` and `.bat` files
719+
/// use a non-standard way of decoding arguments. They are therefore vulnerable
720+
/// to malicious input.
721+
///
722+
/// In the case of `cmd.exe` this is especially important because a malicious
723+
/// argument can potentially run arbitrary shell commands.
718724
///
719725
/// See [Windows argument splitting][windows-args] for more details
720726
/// or [`raw_arg`] for manually implementing non-standard argument encoding.
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use super::abi;
1+
use super::hermit_abi;
22
use crate::alloc::{GlobalAlloc, Layout, System};
33
use crate::ptr;
44

55
#[stable(feature = "alloc_system_type", since = "1.28.0")]
66
unsafe impl GlobalAlloc for System {
77
#[inline]
88
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
9-
abi::malloc(layout.size(), layout.align())
9+
hermit_abi::malloc(layout.size(), layout.align())
1010
}
1111

1212
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
13-
let addr = abi::malloc(layout.size(), layout.align());
13+
let addr = hermit_abi::malloc(layout.size(), layout.align());
1414

1515
if !addr.is_null() {
1616
ptr::write_bytes(addr, 0x00, layout.size());
@@ -21,11 +21,11 @@ unsafe impl GlobalAlloc for System {
2121

2222
#[inline]
2323
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
24-
abi::free(ptr, layout.size(), layout.align())
24+
hermit_abi::free(ptr, layout.size(), layout.align())
2525
}
2626

2727
#[inline]
2828
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
29-
abi::realloc(ptr, layout.size(), layout.align(), new_size)
29+
hermit_abi::realloc(ptr, layout.size(), layout.align(), new_size)
3030
}
3131
}

library/std/src/sys/pal/hermit/fd.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![unstable(reason = "not public", issue = "none", feature = "fd")]
22

3-
use super::abi;
3+
use super::hermit_abi;
44
use crate::io::{self, Read};
55
use crate::os::hermit::io::{FromRawFd, OwnedFd, RawFd};
66
use crate::sys::cvt;
@@ -16,7 +16,8 @@ pub struct FileDesc {
1616

1717
impl FileDesc {
1818
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
19-
let result = cvt(unsafe { abi::read(self.fd.as_raw_fd(), buf.as_mut_ptr(), buf.len()) })?;
19+
let result =
20+
cvt(unsafe { hermit_abi::read(self.fd.as_raw_fd(), buf.as_mut_ptr(), buf.len()) })?;
2021
Ok(result as usize)
2122
}
2223

@@ -26,7 +27,8 @@ impl FileDesc {
2627
}
2728

2829
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
29-
let result = cvt(unsafe { abi::write(self.fd.as_raw_fd(), buf.as_ptr(), buf.len()) })?;
30+
let result =
31+
cvt(unsafe { hermit_abi::write(self.fd.as_raw_fd(), buf.as_ptr(), buf.len()) })?;
3032
Ok(result as usize)
3133
}
3234

@@ -49,8 +51,8 @@ impl FileDesc {
4951
unsupported()
5052
}
5153

52-
pub fn fstat(&self, stat: *mut abi::stat) -> io::Result<()> {
53-
cvt(unsafe { abi::fstat(self.fd.as_raw_fd(), stat) })?;
54+
pub fn fstat(&self, stat: *mut hermit_abi::stat) -> io::Result<()> {
55+
cvt(unsafe { hermit_abi::fstat(self.fd.as_raw_fd(), stat) })?;
5456
Ok(())
5557
}
5658
}

0 commit comments

Comments
 (0)