Skip to content

Commit

Permalink
Auto merge of rust-lang#124633 - matthiaskrgr:rollup-x4kyjp2, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#124345 (Enable `--check-cfg` by default in UI tests)
 - rust-lang#124412 (io safety: update Unix explanation to use `Arc`)
 - rust-lang#124441 (String.truncate comment microfix (greater or equal))
 - rust-lang#124604 (library/std: Remove unused `gimli-symbolize` feature)

Failed merges:

 - rust-lang#124607 (`rustc_expand` cleanups)
 - rust-lang#124613 (Allow fmt to run on rmake.rs test files)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 2, 2024
2 parents 79734f1 + d982c3a commit cc02b73
Show file tree
Hide file tree
Showing 111 changed files with 317 additions and 223 deletions.
2 changes: 1 addition & 1 deletion library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ impl String {

/// Shortens this `String` to the specified length.
///
/// If `new_len` is greater than the string's current length, this has no
/// If `new_len` is greater than or equal to the string's current length, this has no
/// effect.
///
/// Note that this method has no effect on the allocated capacity
Expand Down
2 changes: 0 additions & 2 deletions library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std'] }

[features]
backtrace = [
"gimli-symbolize",
'addr2line/rustc-dep-of-std',
'object/rustc-dep-of-std',
'miniz_oxide/rustc-dep-of-std',
]
gimli-symbolize = []

panic-unwind = ["panic_unwind"]
profiler = ["profiler_builtins"]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
//! its file descriptors with no operations being performed by any other part of the program.
//!
//! Note that exclusive ownership of a file descriptor does *not* imply exclusive ownership of the
//! underlying kernel object that the file descriptor references (also called "file description" on
//! underlying kernel object that the file descriptor references (also called "open file description" on
//! some operating systems). File descriptors basically work like [`Arc`]: when you receive an owned
//! file descriptor, you cannot know whether there are any other file descriptors that reference the
//! same kernel object. However, when you create a new kernel object, you know that you are holding
Expand Down
31 changes: 21 additions & 10 deletions library/std/src/os/unix/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//! | Type | Analogous to |
//! | ------------------ | ------------ |
//! | [`RawFd`] | `*const _` |
//! | [`BorrowedFd<'a>`] | `&'a _` |
//! | [`OwnedFd`] | `Box<_>` |
//! | [`BorrowedFd<'a>`] | `&'a Arc<_>` |
//! | [`OwnedFd`] | `Arc<_>` |
//!
//! Like raw pointers, `RawFd` values are primitive values. And in new code,
//! they should be considered unsafe to do I/O on (analogous to dereferencing
Expand All @@ -23,22 +23,31 @@
//! either by adding `unsafe` to APIs that dereference `RawFd` values, or by
//! using to `BorrowedFd` or `OwnedFd` instead.
//!
//! The use of `Arc` for borrowed/owned file descriptors may be surprising. Unix file descriptors
//! are mere references to internal kernel objects called "open file descriptions", and the same
//! open file description can be referenced by multiple file descriptors (e.g. if `dup` is used).
//! State such as the offset within the file is shared among all file descriptors that refer to the
//! same open file description, and the kernel internally does reference-counting to only close the
//! underlying resource once all file descriptors referencing it are closed. That's why `Arc` (and
//! not `Box`) is the closest Rust analogy to an "owned" file descriptor.
//!
//! Like references, `BorrowedFd` values are tied to a lifetime, to ensure
//! that they don't outlive the resource they point to. These are safe to
//! use. `BorrowedFd` values may be used in APIs which provide safe access to
//! any system call except for:
//!
//! - `close`, because that would end the dynamic lifetime of the resource
//! without ending the lifetime of the file descriptor.
//! without ending the lifetime of the file descriptor. (Equivalently:
//! an `&Arc<_>` cannot be `drop`ed.)
//!
//! - `dup2`/`dup3`, in the second argument, because this argument is
//! closed and assigned a new resource, which may break the assumptions
//! closed and assigned a new resource, which may break the assumptions of
//! other code using that file descriptor.
//!
//! `BorrowedFd` values may be used in APIs which provide safe access to `dup`
//! system calls, so types implementing `AsFd` or `From<OwnedFd>` should not
//! assume they always have exclusive access to the underlying file
//! description.
//! `BorrowedFd` values may be used in APIs which provide safe access to `dup` system calls, so code
//! working with `OwnedFd` cannot assume to have exclusive access to the underlying open file
//! description. (Equivalently: `&Arc` may be used in APIs that provide safe access to `clone`, so
//! code working with an `Arc` cannot assume that the reference count is 1.)
//!
//! `BorrowedFd` values may also be used with `mmap`, since `mmap` uses the
//! provided file descriptor in a manner similar to `dup` and does not require
Expand All @@ -52,8 +61,10 @@
//! take full responsibility for ensuring that safe Rust code cannot evoke
//! undefined behavior through it.
//!
//! Like boxes, `OwnedFd` values conceptually own the resource they point to,
//! and free (close) it when they are dropped.
//! Like `Arc`, `OwnedFd` values conceptually own one reference to the resource they point to,
//! and decrement the reference count when they are dropped (by calling `close`).
//! When the reference count reaches 0, the underlying open file description will be freed
//! by the kernel.
//!
//! See the [`io` module docs][io-safety] for a general explanation of I/O safety.
//!
Expand Down
7 changes: 7 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ pub struct TestProps {
pub llvm_cov_flags: Vec<String>,
/// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it.
pub filecheck_flags: Vec<String>,
/// Don't automatically insert any `--check-cfg` args
pub no_auto_check_cfg: bool,
}

mod directives {
Expand Down Expand Up @@ -249,6 +251,7 @@ mod directives {
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
pub const NO_AUTO_CHECK_CFG: &'static str = "no-auto-check-cfg";
// This isn't a real directive, just one that is probably mistyped often
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
}
Expand Down Expand Up @@ -304,6 +307,7 @@ impl TestProps {
remap_src_base: false,
llvm_cov_flags: vec![],
filecheck_flags: vec![],
no_auto_check_cfg: false,
}
}

Expand Down Expand Up @@ -567,6 +571,8 @@ impl TestProps {
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
self.filecheck_flags.extend(split_flags(&flags));
}

config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg);
},
);

Expand Down Expand Up @@ -860,6 +866,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"needs-unwind",
"needs-wasmtime",
"needs-xray",
"no-auto-check-cfg",
"no-prefer-dynamic",
"normalize-stderr-32bit",
"normalize-stderr-64bit",
Expand Down
25 changes: 22 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,31 @@ impl<'test> TestCx<'test> {
}

fn set_revision_flags(&self, cmd: &mut Command) {
// Normalize revisions to be lowercase and replace `-`s with `_`s.
// Otherwise the `--cfg` flag is not valid.
let normalize_revision = |revision: &str| revision.to_lowercase().replace("-", "_");

if let Some(revision) = self.revision {
// Normalize revisions to be lowercase and replace `-`s with `_`s.
// Otherwise the `--cfg` flag is not valid.
let normalized_revision = revision.to_lowercase().replace("-", "_");
let normalized_revision = normalize_revision(revision);
cmd.args(&["--cfg", &normalized_revision]);
}

if !self.props.no_auto_check_cfg {
let mut check_cfg = String::with_capacity(25);

// Generate `cfg(FALSE, REV1, ..., REVN)` (for all possible revisions)
//
// For compatibility reason we consider the `FALSE` cfg to be expected
// since it is extensively used in the testsuite.
check_cfg.push_str("cfg(FALSE");
for revision in &self.props.revisions {
check_cfg.push_str(",");
check_cfg.push_str(&normalize_revision(&revision));
}
check_cfg.push_str(")");

cmd.args(&["--check-cfg", &check_cfg]);
}
}

fn typecheck_source(&self, src: String) -> ProcRes {
Expand Down
6 changes: 3 additions & 3 deletions tests/rustdoc-ui/argfile/commandline-argfile.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Check to see if we can get parameters from an @argsfile file
//
//@ check-pass
//@ compile-flags: --cfg cmdline_set @{{src-base}}/argfile/commandline-argfile.args
//@ compile-flags: --cfg cmdline_set --check-cfg=cfg(cmdline_set,unbroken)
//@ compile-flags: @{{src-base}}/argfile/commandline-argfile.args

#[cfg(not(cmdline_set))]
compile_error!("cmdline_set not set");

#[cfg(not(unbroken))]
compile_error!("unbroken not set");

fn main() {
}
fn main() {}
6 changes: 3 additions & 3 deletions tests/ui/argfile/commandline-argfile.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Check to see if we can get parameters from an @argsfile file
//
//@ build-pass
//@ compile-flags: --cfg cmdline_set @{{src-base}}/argfile/commandline-argfile.args
//@ compile-flags: --cfg cmdline_set --check-cfg=cfg(cmdline_set,unbroken)
//@ compile-flags: @{{src-base}}/argfile/commandline-argfile.args

#[cfg(not(cmdline_set))]
compile_error!("cmdline_set not set");

#[cfg(not(unbroken))]
compile_error!("unbroken not set");

fn main() {
}
fn main() {}
3 changes: 2 additions & 1 deletion tests/ui/cfg/cfg-in-crate-1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
//@ compile-flags: --cfg bar -D warnings
//@ compile-flags: --cfg bar --check-cfg=cfg(bar) -D warnings

#![cfg(bar)]

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/cfg/cfg-macros-foo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ compile-flags: --cfg foo
//@ compile-flags: --cfg foo --check-cfg=cfg(foo)

// check that cfg correctly chooses between the macro impls (see also
// cfg-macros-notfoo.rs)
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/cfg/cfg-path-error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ check-fail

#![allow(unexpected_cfgs)] // invalid cfgs

#[cfg(any(foo, foo::bar))]
//~^ERROR `cfg` predicate key must be an identifier
fn foo1() {}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/cfg/cfg-path-error.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:3:16
--> $DIR/cfg-path-error.rs:5:16
|
LL | #[cfg(any(foo, foo::bar))]
| ^^^^^^^^

error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:7:11
--> $DIR/cfg-path-error.rs:9:11
|
LL | #[cfg(any(foo::bar, foo))]
| ^^^^^^^^

error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:11:16
--> $DIR/cfg-path-error.rs:13:16
|
LL | #[cfg(all(foo, foo::bar))]
| ^^^^^^^^

error: `cfg` predicate key must be an identifier
--> $DIR/cfg-path-error.rs:15:11
--> $DIR/cfg-path-error.rs:17:11
|
LL | #[cfg(all(foo::bar, foo))]
| ^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/cfg/cfg_attr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//@ run-pass
//@ compile-flags:--cfg set1 --cfg set2
#![allow(dead_code)]

#![allow(dead_code, unexpected_cfgs)]

use std::fmt::Debug;

struct NotDebugable;
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/cfg/cfgs-on-items.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//@ run-pass
//@ compile-flags: --cfg fooA --cfg fooB
//@ compile-flags: --cfg fooA --cfg fooB --check-cfg=cfg(fooA,fooB,fooC,bar)

// fooA AND !bar

#[cfg(all(fooA, not(bar)))]
fn foo1() -> isize { 1 }

Expand Down
3 changes: 3 additions & 0 deletions tests/ui/cfg/diagnostics-not-a-def.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![feature(lint_reasons)]

pub mod inner {
#[expect(unexpected_cfgs)]
pub fn i_am_here() {
#[cfg(feature = "another one that doesn't exist")]
loop {}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cfg/diagnostics-not-a-def.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0425]: cannot find function `i_am_not` in module `inner`
--> $DIR/diagnostics-not-a-def.rs:11:12
--> $DIR/diagnostics-not-a-def.rs:14:12
|
LL | inner::i_am_not();
| ^^^^^^^^ not found in `inner`
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/cfg/diagnostics-same-crate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unexpected_cfgs)] // since we want to recognize them as unexpected

pub mod inner {
#[cfg(FALSE)]
pub fn uwu() {}
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/cfg/diagnostics-same-crate.stderr
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
error[E0432]: unresolved import `super::inner::doesnt_exist`
--> $DIR/diagnostics-same-crate.rs:28:9
--> $DIR/diagnostics-same-crate.rs:30:9
|
LL | use super::inner::doesnt_exist;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `doesnt_exist` in `inner`
|
note: found an item that was configured out
--> $DIR/diagnostics-same-crate.rs:7:13
--> $DIR/diagnostics-same-crate.rs:9:13
|
LL | pub mod doesnt_exist {
| ^^^^^^^^^^^^

error[E0432]: unresolved import `super::inner::doesnt_exist`
--> $DIR/diagnostics-same-crate.rs:31:23
--> $DIR/diagnostics-same-crate.rs:33:23
|
LL | use super::inner::doesnt_exist::hi;
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
note: found an item that was configured out
--> $DIR/diagnostics-same-crate.rs:7:13
--> $DIR/diagnostics-same-crate.rs:9:13
|
LL | pub mod doesnt_exist {
| ^^^^^^^^^^^^

error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
--> $DIR/diagnostics-same-crate.rs:50:12
--> $DIR/diagnostics-same-crate.rs:52:12
|
LL | inner::doesnt_exist::hello();
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
note: found an item that was configured out
--> $DIR/diagnostics-same-crate.rs:7:13
--> $DIR/diagnostics-same-crate.rs:9:13
|
LL | pub mod doesnt_exist {
| ^^^^^^^^^^^^

error[E0425]: cannot find function `uwu` in module `inner`
--> $DIR/diagnostics-same-crate.rs:45:12
--> $DIR/diagnostics-same-crate.rs:47:12
|
LL | inner::uwu();
| ^^^ not found in `inner`
|
note: found an item that was configured out
--> $DIR/diagnostics-same-crate.rs:3:12
--> $DIR/diagnostics-same-crate.rs:5:12
|
LL | pub fn uwu() {}
| ^^^

error[E0425]: cannot find function `meow` in module `inner::right`
--> $DIR/diagnostics-same-crate.rs:54:19
--> $DIR/diagnostics-same-crate.rs:56:19
|
LL | inner::right::meow();
| ^^^^ not found in `inner::right`
|
note: found an item that was configured out
--> $DIR/diagnostics-same-crate.rs:22:16
--> $DIR/diagnostics-same-crate.rs:24:16
|
LL | pub fn meow() {}
| ^^^^
= note: the item is gated behind the `what-a-cool-feature` feature

error[E0425]: cannot find function `uwu` in this scope
--> $DIR/diagnostics-same-crate.rs:41:5
--> $DIR/diagnostics-same-crate.rs:43:5
|
LL | uwu();
| ^^^ not found in this scope

error[E0425]: cannot find function `vanished` in this scope
--> $DIR/diagnostics-same-crate.rs:61:5
--> $DIR/diagnostics-same-crate.rs:63:5
|
LL | vanished();
| ^^^^^^^^ not found in this scope
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/cfg/expanded-cfg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ check-pass

#![allow(unexpected_cfgs)] // since we different cfgs

macro_rules! mac {
{} => {
#[cfg(attr)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ check-fail
//@ compile-flags:--cfg foo
//@ compile-flags:--cfg foo --check-cfg=cfg(foo)

#![cfg_attr(foo, crate_type="bin")]
//~^ERROR `crate_type` within
Expand Down
Loading

0 comments on commit cc02b73

Please sign in to comment.