Skip to content

Commit

Permalink
Auto merge of rust-lang#125280 - compiler-errors:rollup-401itda, r=co…
Browse files Browse the repository at this point in the history
…mpiler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#123709 (Update documentation related to the recent cmd.exe fix)
 - rust-lang#124304 (revise the interpretation of ReadDir for HermitOS)
 - rust-lang#124708 (Actually use the `#[do_not_recommend]` attribute if present)
 - rust-lang#125252 (Add `#[inline]` to float `Debug` fallback used by `cfg(no_fp_fmt_parse)`)
 - rust-lang#125261 (crashes: add more)
 - rust-lang#125270 (Followup fixes from rust-lang#123344)
 - rust-lang#125275 (Migrate `run-make/rustdoc-scrape-examples-test` to new `rmake.rs`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 19, 2024
2 parents 7d2a95b + e959fd6 commit 6982935
Show file tree
Hide file tree
Showing 42 changed files with 474 additions and 170 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,13 @@ pub enum UseTreeKind {
/// `use prefix` or `use prefix as rename`
Simple(Option<Ident>),
/// `use prefix::{...}`
///
/// The span represents the braces of the nested group and all elements within:
///
/// ```text
/// use foo::{bar, baz};
/// ^^^^^^^^^^
/// ```
Nested { items: ThinVec<(UseTree, NodeId)>, span: Span },
/// `use prefix::*`
Glob,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,21 @@ fn calc_unused_spans(

let mut unused_spans = Vec::new();
let mut to_remove = Vec::new();
let mut used_childs = 0;
let mut used_children = 0;
let mut contains_self = false;
let mut previous_unused = false;
for (pos, (use_tree, use_tree_id)) in nested.iter().enumerate() {
let remove = match calc_unused_spans(unused_import, use_tree, *use_tree_id) {
UnusedSpanResult::Used => {
used_childs += 1;
used_children += 1;
None
}
UnusedSpanResult::Unused { mut spans, remove } => {
unused_spans.append(&mut spans);
Some(remove)
}
UnusedSpanResult::PartialUnused { mut spans, remove: mut to_remove_extra } => {
used_childs += 1;
used_children += 1;
unused_spans.append(&mut spans);
to_remove.append(&mut to_remove_extra);
None
Expand All @@ -322,7 +322,7 @@ fn calc_unused_spans(
if let Some(remove) = remove {
let remove_span = if nested.len() == 1 {
remove
} else if pos == nested.len() - 1 || used_childs > 0 {
} else if pos == nested.len() - 1 || used_children > 0 {
// Delete everything from the end of the last import, to delete the
// previous comma
nested[pos - 1].0.span.shrink_to_hi().to(use_tree.span)
Expand All @@ -346,7 +346,7 @@ fn calc_unused_spans(
}
if unused_spans.is_empty() {
UnusedSpanResult::Used
} else if used_childs == 0 {
} else if used_children == 0 {
UnusedSpanResult::Unused { spans: unused_spans, remove: full_span }
} else {
// If there is only one remaining child that is used, the braces around the use
Expand All @@ -360,7 +360,7 @@ fn calc_unused_spans(
// `self`: `use foo::{self};` is valid Rust syntax, while `use foo::self;` errors
// out. We also cannot turn `use foo::{self}` into `use foo`, as the former doesn't
// import types with the same name as the module.
if used_childs == 1 && !contains_self {
if used_children == 1 && !contains_self {
// Left brace, from the start of the nested group to the first item.
to_remove.push(
tree_span.shrink_to_lo().to(nested.first().unwrap().0.span.shrink_to_lo()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) => {
let trait_predicate = bound_predicate.rebind(trait_predicate);
let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
let trait_predicate = self.apply_do_not_recommend(trait_predicate, &mut obligation);

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

fn apply_do_not_recommend(
&self,
mut trait_predicate: ty::Binder<'tcx, ty::TraitPredicate<'tcx>>,
obligation: &'_ mut PredicateObligation<'tcx>,
) -> ty::Binder<'tcx, ty::TraitPredicate<'tcx>> {
let mut base_cause = obligation.cause.code().clone();
loop {
if let ObligationCauseCode::ImplDerived(ref c) = base_cause {
if self.tcx.has_attr(c.impl_or_alias_def_id, sym::do_not_recommend) {
let code = (*c.derived.parent_code).clone();
obligation.cause.map_code(|_| code);
obligation.predicate = c.derived.parent_trait_pred.upcast(self.tcx);
trait_predicate = c.derived.parent_trait_pred.clone();
}
}
if let Some((parent_cause, _parent_pred)) = base_cause.parent() {
base_cause = parent_cause.clone();
} else {
break;
}
}

trait_predicate
}

fn emit_specialized_closure_kind_error(
&self,
obligation: &PredicateObligation<'tcx>,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/fmt/nofloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ macro_rules! floating {
($ty:ident) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for $ty {
#[inline]
fn fmt(&self, _fmt: &mut Formatter<'_>) -> Result {
panic!("floating point support is turned off");
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[allow(unused_extern_crates)]
#[stable(feature = "rust1", since = "1.0.0")]
pub extern crate hermit_abi as abi;
pub extern crate hermit_abi;

pub mod ffi;
pub mod io;
Expand Down
49 changes: 32 additions & 17 deletions library/std/src/os/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ pub trait CommandExt: Sealed {

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

/// Sets a raw attribute on the command, providing extended configuration options for Windows processes.
/// Set a raw attribute on the command, providing extended configuration options for Windows
/// processes.
///
/// This method allows you to specify custom attributes for a child process on Windows systems
/// using raw attribute values. Raw attributes provide extended configurability for process
/// creation, but their usage can be complex and potentially unsafe.
///
/// This method allows you to specify custom attributes for a child process on Windows systems using raw attribute values.
/// Raw attributes provide extended configurability for process creation, but their usage can be complex and potentially unsafe.
/// The `attribute` parameter specifies the raw attribute to be set, while the `value`
/// parameter holds the value associated with that attribute. Please refer to the
/// [`windows-rs` documentation] or the [Win32 API documentation] for detailed information
/// about available attributes and their meanings.
///
/// The `attribute` parameter specifies the raw attribute to be set, while the `value` parameter holds the value associated with that attribute.
/// 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.
/// [`windows-rs` documentation]: https://microsoft.github.io/windows-docs-rs/doc/windows/
/// [Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute
///
/// # Note
///
/// The maximum number of raw attributes is the value of [`u32::MAX`].
/// 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.
/// 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.
///
/// # Safety
///
/// 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.
/// 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.
///
/// # Example
///
/// The following example demonstrates how to create a child process with a specific parent process ID using a raw attribute.
/// The following example demonstrates how to create a child process with a specific parent
/// process ID using a raw attribute.
///
/// ```rust
/// #![feature(windows_process_extensions_raw_attribute)]
Expand Down Expand Up @@ -339,7 +352,9 @@ pub trait CommandExt: Sealed {
///
/// # Safety Note
///
/// 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.
/// 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.
#[unstable(feature = "windows_process_extensions_raw_attribute", issue = "114854")]
unsafe fn raw_attribute<T: Copy + Send + Sync + 'static>(
&mut self,
Expand Down
48 changes: 27 additions & 21 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
//!
//! # Windows argument splitting
//!
//! On Unix systems arguments are passed to a new process as an array of strings
//! but on Windows arguments are passed as a single commandline string and it's
//! On Unix systems arguments are passed to a new process as an array of strings,
//! but on Windows arguments are passed as a single commandline string and it is
//! up to the child process to parse it into an array. Therefore the parent and
//! child processes must agree on how the commandline string is encoded.
//!
Expand All @@ -107,26 +107,26 @@
//! * Use [`raw_arg`] to build a custom commandline. This bypasses the escaping
//! rules used by [`arg`] so should be used with due caution.
//!
//! `cmd.exe` and `.bat` use non-standard argument parsing and are especially
//! `cmd.exe` and `.bat` files use non-standard argument parsing and are especially
//! vulnerable to malicious input as they may be used to run arbitrary shell
//! commands. Untrusted arguments should be restricted as much as possible.
//! For examples on handling this see [`raw_arg`].
//!
//! ### Bat file special handling
//! ### Batch file special handling
//!
//! On Windows, `Command` uses the Windows API function [`CreateProcessW`] to
//! spawn new processes. An undocumented feature of this function is that,
//! spawn new processes. An undocumented feature of this function is that
//! when given a `.bat` file as the application to run, it will automatically
//! convert that into running `cmd.exe /c` with the bat file as the next argument.
//! convert that into running `cmd.exe /c` with the batch file as the next argument.
//!
//! For historical reasons Rust currently preserves this behaviour when using
//! [`Command::new`], and escapes the arguments according to `cmd.exe` rules.
//! Due to the complexity of `cmd.exe` argument handling, it might not be
//! possible to safely escape some special chars, and using them will result
//! possible to safely escape some special characters, and using them will result
//! in an error being returned at process spawn. The set of unescapeable
//! special chars might change between releases.
//! special characters might change between releases.
//!
//! Also note that running `.bat` scripts in this way may be removed in the
//! Also note that running batch scripts in this way may be removed in the
//! future and so should not be relied upon.
//!
//! [`spawn`]: Command::spawn
Expand Down Expand Up @@ -659,16 +659,19 @@ impl Command {
///
/// Note that the argument is not passed through a shell, but given
/// literally to the program. This means that shell syntax like quotes,
/// escaped characters, word splitting, glob patterns, variable substitution, etc.
/// have no effect.
/// escaped characters, word splitting, glob patterns, variable substitution,
/// etc. have no effect.
///
/// <div class="warning">
///
/// On Windows use caution with untrusted inputs. Most applications use the
/// standard convention for decoding arguments passed to them. These are safe to use with `arg`.
/// However some applications, such as `cmd.exe` and `.bat` files, use a non-standard way of decoding arguments
/// and are therefore vulnerable to malicious input.
/// In the case of `cmd.exe` this is especially important because a malicious argument can potentially run arbitrary shell commands.
/// On Windows, use caution with untrusted inputs. Most applications use the
/// standard convention for decoding arguments passed to them. These are safe to
/// use with `arg`. However, some applications such as `cmd.exe` and `.bat` files
/// use a non-standard way of decoding arguments. They are therefore vulnerable
/// to malicious input.
///
/// In the case of `cmd.exe` this is especially important because a malicious
/// argument can potentially run arbitrary shell commands.
///
/// See [Windows argument splitting][windows-args] for more details
/// or [`raw_arg`] for manually implementing non-standard argument encoding.
Expand Down Expand Up @@ -710,11 +713,14 @@ impl Command {
///
/// <div class="warning">
///
/// On Windows use caution with untrusted inputs. Most applications use the
/// standard convention for decoding arguments passed to them. These are safe to use with `args`.
/// However some applications, such as `cmd.exe` and `.bat` files, use a non-standard way of decoding arguments
/// and are therefore vulnerable to malicious input.
/// In the case of `cmd.exe` this is especially important because a malicious argument can potentially run arbitrary shell commands.
/// On Windows, use caution with untrusted inputs. Most applications use the
/// standard convention for decoding arguments passed to them. These are safe to
/// use with `arg`. However, some applications such as `cmd.exe` and `.bat` files
/// use a non-standard way of decoding arguments. They are therefore vulnerable
/// to malicious input.
///
/// In the case of `cmd.exe` this is especially important because a malicious
/// argument can potentially run arbitrary shell commands.
///
/// See [Windows argument splitting][windows-args] for more details
/// or [`raw_arg`] for manually implementing non-standard argument encoding.
Expand Down
10 changes: 5 additions & 5 deletions library/std/src/sys/pal/hermit/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use super::abi;
use super::hermit_abi;
use crate::alloc::{GlobalAlloc, Layout, System};
use crate::ptr;

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

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

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

#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
abi::free(ptr, layout.size(), layout.align())
hermit_abi::free(ptr, layout.size(), layout.align())
}

#[inline]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
abi::realloc(ptr, layout.size(), layout.align(), new_size)
hermit_abi::realloc(ptr, layout.size(), layout.align(), new_size)
}
}
12 changes: 7 additions & 5 deletions library/std/src/sys/pal/hermit/fd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![unstable(reason = "not public", issue = "none", feature = "fd")]

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

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

Expand All @@ -26,7 +27,8 @@ impl FileDesc {
}

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

Expand All @@ -49,8 +51,8 @@ impl FileDesc {
unsupported()
}

pub fn fstat(&self, stat: *mut abi::stat) -> io::Result<()> {
cvt(unsafe { abi::fstat(self.fd.as_raw_fd(), stat) })?;
pub fn fstat(&self, stat: *mut hermit_abi::stat) -> io::Result<()> {
cvt(unsafe { hermit_abi::fstat(self.fd.as_raw_fd(), stat) })?;
Ok(())
}
}
Expand Down
Loading

0 comments on commit 6982935

Please sign in to comment.