Skip to content

Commit cc02b73

Browse files
committed
Auto merge of rust-lang#124633 - matthiaskrgr:rollup-x4kyjp2, r=matthiaskrgr
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
2 parents 79734f1 + d982c3a commit cc02b73

File tree

111 files changed

+317
-223
lines changed

Some content is hidden

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

111 files changed

+317
-223
lines changed

library/alloc/src/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ impl String {
13821382

13831383
/// Shortens this `String` to the specified length.
13841384
///
1385-
/// If `new_len` is greater than the string's current length, this has no
1385+
/// If `new_len` is greater than or equal to the string's current length, this has no
13861386
/// effect.
13871387
///
13881388
/// Note that this method has no effect on the allocated capacity

library/std/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std'] }
6464

6565
[features]
6666
backtrace = [
67-
"gimli-symbolize",
6867
'addr2line/rustc-dep-of-std',
6968
'object/rustc-dep-of-std',
7069
'miniz_oxide/rustc-dep-of-std',
7170
]
72-
gimli-symbolize = []
7371

7472
panic-unwind = ["panic_unwind"]
7573
profiler = ["profiler_builtins"]

library/std/src/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
//! its file descriptors with no operations being performed by any other part of the program.
267267
//!
268268
//! Note that exclusive ownership of a file descriptor does *not* imply exclusive ownership of the
269-
//! underlying kernel object that the file descriptor references (also called "file description" on
269+
//! underlying kernel object that the file descriptor references (also called "open file description" on
270270
//! some operating systems). File descriptors basically work like [`Arc`]: when you receive an owned
271271
//! file descriptor, you cannot know whether there are any other file descriptors that reference the
272272
//! same kernel object. However, when you create a new kernel object, you know that you are holding

library/std/src/os/unix/io/mod.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
//! | Type | Analogous to |
1313
//! | ------------------ | ------------ |
1414
//! | [`RawFd`] | `*const _` |
15-
//! | [`BorrowedFd<'a>`] | `&'a _` |
16-
//! | [`OwnedFd`] | `Box<_>` |
15+
//! | [`BorrowedFd<'a>`] | `&'a Arc<_>` |
16+
//! | [`OwnedFd`] | `Arc<_>` |
1717
//!
1818
//! Like raw pointers, `RawFd` values are primitive values. And in new code,
1919
//! they should be considered unsafe to do I/O on (analogous to dereferencing
@@ -23,22 +23,31 @@
2323
//! either by adding `unsafe` to APIs that dereference `RawFd` values, or by
2424
//! using to `BorrowedFd` or `OwnedFd` instead.
2525
//!
26+
//! The use of `Arc` for borrowed/owned file descriptors may be surprising. Unix file descriptors
27+
//! are mere references to internal kernel objects called "open file descriptions", and the same
28+
//! open file description can be referenced by multiple file descriptors (e.g. if `dup` is used).
29+
//! State such as the offset within the file is shared among all file descriptors that refer to the
30+
//! same open file description, and the kernel internally does reference-counting to only close the
31+
//! underlying resource once all file descriptors referencing it are closed. That's why `Arc` (and
32+
//! not `Box`) is the closest Rust analogy to an "owned" file descriptor.
33+
//!
2634
//! Like references, `BorrowedFd` values are tied to a lifetime, to ensure
2735
//! that they don't outlive the resource they point to. These are safe to
2836
//! use. `BorrowedFd` values may be used in APIs which provide safe access to
2937
//! any system call except for:
3038
//!
3139
//! - `close`, because that would end the dynamic lifetime of the resource
32-
//! without ending the lifetime of the file descriptor.
40+
//! without ending the lifetime of the file descriptor. (Equivalently:
41+
//! an `&Arc<_>` cannot be `drop`ed.)
3342
//!
3443
//! - `dup2`/`dup3`, in the second argument, because this argument is
35-
//! closed and assigned a new resource, which may break the assumptions
44+
//! closed and assigned a new resource, which may break the assumptions of
3645
//! other code using that file descriptor.
3746
//!
38-
//! `BorrowedFd` values may be used in APIs which provide safe access to `dup`
39-
//! system calls, so types implementing `AsFd` or `From<OwnedFd>` should not
40-
//! assume they always have exclusive access to the underlying file
41-
//! description.
47+
//! `BorrowedFd` values may be used in APIs which provide safe access to `dup` system calls, so code
48+
//! working with `OwnedFd` cannot assume to have exclusive access to the underlying open file
49+
//! description. (Equivalently: `&Arc` may be used in APIs that provide safe access to `clone`, so
50+
//! code working with an `Arc` cannot assume that the reference count is 1.)
4251
//!
4352
//! `BorrowedFd` values may also be used with `mmap`, since `mmap` uses the
4453
//! provided file descriptor in a manner similar to `dup` and does not require
@@ -52,8 +61,10 @@
5261
//! take full responsibility for ensuring that safe Rust code cannot evoke
5362
//! undefined behavior through it.
5463
//!
55-
//! Like boxes, `OwnedFd` values conceptually own the resource they point to,
56-
//! and free (close) it when they are dropped.
64+
//! Like `Arc`, `OwnedFd` values conceptually own one reference to the resource they point to,
65+
//! and decrement the reference count when they are dropped (by calling `close`).
66+
//! When the reference count reaches 0, the underlying open file description will be freed
67+
//! by the kernel.
5768
//!
5869
//! See the [`io` module docs][io-safety] for a general explanation of I/O safety.
5970
//!

src/tools/compiletest/src/header.rs

+7
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ pub struct TestProps {
208208
pub llvm_cov_flags: Vec<String>,
209209
/// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it.
210210
pub filecheck_flags: Vec<String>,
211+
/// Don't automatically insert any `--check-cfg` args
212+
pub no_auto_check_cfg: bool,
211213
}
212214

213215
mod directives {
@@ -249,6 +251,7 @@ mod directives {
249251
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
250252
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
251253
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
254+
pub const NO_AUTO_CHECK_CFG: &'static str = "no-auto-check-cfg";
252255
// This isn't a real directive, just one that is probably mistyped often
253256
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
254257
}
@@ -304,6 +307,7 @@ impl TestProps {
304307
remap_src_base: false,
305308
llvm_cov_flags: vec![],
306309
filecheck_flags: vec![],
310+
no_auto_check_cfg: false,
307311
}
308312
}
309313

@@ -567,6 +571,8 @@ impl TestProps {
567571
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
568572
self.filecheck_flags.extend(split_flags(&flags));
569573
}
574+
575+
config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg);
570576
},
571577
);
572578

@@ -860,6 +866,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
860866
"needs-unwind",
861867
"needs-wasmtime",
862868
"needs-xray",
869+
"no-auto-check-cfg",
863870
"no-prefer-dynamic",
864871
"normalize-stderr-32bit",
865872
"normalize-stderr-64bit",

src/tools/compiletest/src/runtest.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,31 @@ impl<'test> TestCx<'test> {
10281028
}
10291029

10301030
fn set_revision_flags(&self, cmd: &mut Command) {
1031+
// Normalize revisions to be lowercase and replace `-`s with `_`s.
1032+
// Otherwise the `--cfg` flag is not valid.
1033+
let normalize_revision = |revision: &str| revision.to_lowercase().replace("-", "_");
1034+
10311035
if let Some(revision) = self.revision {
1032-
// Normalize revisions to be lowercase and replace `-`s with `_`s.
1033-
// Otherwise the `--cfg` flag is not valid.
1034-
let normalized_revision = revision.to_lowercase().replace("-", "_");
1036+
let normalized_revision = normalize_revision(revision);
10351037
cmd.args(&["--cfg", &normalized_revision]);
10361038
}
1039+
1040+
if !self.props.no_auto_check_cfg {
1041+
let mut check_cfg = String::with_capacity(25);
1042+
1043+
// Generate `cfg(FALSE, REV1, ..., REVN)` (for all possible revisions)
1044+
//
1045+
// For compatibility reason we consider the `FALSE` cfg to be expected
1046+
// since it is extensively used in the testsuite.
1047+
check_cfg.push_str("cfg(FALSE");
1048+
for revision in &self.props.revisions {
1049+
check_cfg.push_str(",");
1050+
check_cfg.push_str(&normalize_revision(&revision));
1051+
}
1052+
check_cfg.push_str(")");
1053+
1054+
cmd.args(&["--check-cfg", &check_cfg]);
1055+
}
10371056
}
10381057

10391058
fn typecheck_source(&self, src: String) -> ProcRes {
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Check to see if we can get parameters from an @argsfile file
22
//
33
//@ check-pass
4-
//@ compile-flags: --cfg cmdline_set @{{src-base}}/argfile/commandline-argfile.args
4+
//@ compile-flags: --cfg cmdline_set --check-cfg=cfg(cmdline_set,unbroken)
5+
//@ compile-flags: @{{src-base}}/argfile/commandline-argfile.args
56

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

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

12-
fn main() {
13-
}
13+
fn main() {}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Check to see if we can get parameters from an @argsfile file
22
//
33
//@ build-pass
4-
//@ compile-flags: --cfg cmdline_set @{{src-base}}/argfile/commandline-argfile.args
4+
//@ compile-flags: --cfg cmdline_set --check-cfg=cfg(cmdline_set,unbroken)
5+
//@ compile-flags: @{{src-base}}/argfile/commandline-argfile.args
56

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

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

12-
fn main() {
13-
}
13+
fn main() {}

tests/ui/cfg/cfg-in-crate-1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ run-pass
2-
//@ compile-flags: --cfg bar -D warnings
2+
//@ compile-flags: --cfg bar --check-cfg=cfg(bar) -D warnings
3+
34
#![cfg(bar)]
45

56
fn main() {}

tests/ui/cfg/cfg-macros-foo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
//@ compile-flags: --cfg foo
2+
//@ compile-flags: --cfg foo --check-cfg=cfg(foo)
33

44
// check that cfg correctly chooses between the macro impls (see also
55
// cfg-macros-notfoo.rs)

tests/ui/cfg/cfg-path-error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ check-fail
22

3+
#![allow(unexpected_cfgs)] // invalid cfgs
4+
35
#[cfg(any(foo, foo::bar))]
46
//~^ERROR `cfg` predicate key must be an identifier
57
fn foo1() {}

tests/ui/cfg/cfg-path-error.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: `cfg` predicate key must be an identifier
2-
--> $DIR/cfg-path-error.rs:3:16
2+
--> $DIR/cfg-path-error.rs:5:16
33
|
44
LL | #[cfg(any(foo, foo::bar))]
55
| ^^^^^^^^
66

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

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

1919
error: `cfg` predicate key must be an identifier
20-
--> $DIR/cfg-path-error.rs:15:11
20+
--> $DIR/cfg-path-error.rs:17:11
2121
|
2222
LL | #[cfg(all(foo::bar, foo))]
2323
| ^^^^^^^^

tests/ui/cfg/cfg_attr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ run-pass
22
//@ compile-flags:--cfg set1 --cfg set2
3-
#![allow(dead_code)]
3+
4+
#![allow(dead_code, unexpected_cfgs)]
5+
46
use std::fmt::Debug;
57

68
struct NotDebugable;

tests/ui/cfg/cfgs-on-items.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//@ run-pass
2-
//@ compile-flags: --cfg fooA --cfg fooB
2+
//@ compile-flags: --cfg fooA --cfg fooB --check-cfg=cfg(fooA,fooB,fooC,bar)
33

44
// fooA AND !bar
5-
65
#[cfg(all(fooA, not(bar)))]
76
fn foo1() -> isize { 1 }
87

tests/ui/cfg/diagnostics-not-a-def.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#![feature(lint_reasons)]
2+
13
pub mod inner {
4+
#[expect(unexpected_cfgs)]
25
pub fn i_am_here() {
36
#[cfg(feature = "another one that doesn't exist")]
47
loop {}

tests/ui/cfg/diagnostics-not-a-def.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find function `i_am_not` in module `inner`
2-
--> $DIR/diagnostics-not-a-def.rs:11:12
2+
--> $DIR/diagnostics-not-a-def.rs:14:12
33
|
44
LL | inner::i_am_not();
55
| ^^^^^^^^ not found in `inner`

tests/ui/cfg/diagnostics-same-crate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unexpected_cfgs)] // since we want to recognize them as unexpected
2+
13
pub mod inner {
24
#[cfg(FALSE)]
35
pub fn uwu() {}

tests/ui/cfg/diagnostics-same-crate.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
11
error[E0432]: unresolved import `super::inner::doesnt_exist`
2-
--> $DIR/diagnostics-same-crate.rs:28:9
2+
--> $DIR/diagnostics-same-crate.rs:30:9
33
|
44
LL | use super::inner::doesnt_exist;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `doesnt_exist` in `inner`
66
|
77
note: found an item that was configured out
8-
--> $DIR/diagnostics-same-crate.rs:7:13
8+
--> $DIR/diagnostics-same-crate.rs:9:13
99
|
1010
LL | pub mod doesnt_exist {
1111
| ^^^^^^^^^^^^
1212

1313
error[E0432]: unresolved import `super::inner::doesnt_exist`
14-
--> $DIR/diagnostics-same-crate.rs:31:23
14+
--> $DIR/diagnostics-same-crate.rs:33:23
1515
|
1616
LL | use super::inner::doesnt_exist::hi;
1717
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
1818
|
1919
note: found an item that was configured out
20-
--> $DIR/diagnostics-same-crate.rs:7:13
20+
--> $DIR/diagnostics-same-crate.rs:9:13
2121
|
2222
LL | pub mod doesnt_exist {
2323
| ^^^^^^^^^^^^
2424

2525
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
26-
--> $DIR/diagnostics-same-crate.rs:50:12
26+
--> $DIR/diagnostics-same-crate.rs:52:12
2727
|
2828
LL | inner::doesnt_exist::hello();
2929
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
3030
|
3131
note: found an item that was configured out
32-
--> $DIR/diagnostics-same-crate.rs:7:13
32+
--> $DIR/diagnostics-same-crate.rs:9:13
3333
|
3434
LL | pub mod doesnt_exist {
3535
| ^^^^^^^^^^^^
3636

3737
error[E0425]: cannot find function `uwu` in module `inner`
38-
--> $DIR/diagnostics-same-crate.rs:45:12
38+
--> $DIR/diagnostics-same-crate.rs:47:12
3939
|
4040
LL | inner::uwu();
4141
| ^^^ not found in `inner`
4242
|
4343
note: found an item that was configured out
44-
--> $DIR/diagnostics-same-crate.rs:3:12
44+
--> $DIR/diagnostics-same-crate.rs:5:12
4545
|
4646
LL | pub fn uwu() {}
4747
| ^^^
4848

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

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

6868
error[E0425]: cannot find function `vanished` in this scope
69-
--> $DIR/diagnostics-same-crate.rs:61:5
69+
--> $DIR/diagnostics-same-crate.rs:63:5
7070
|
7171
LL | vanished();
7272
| ^^^^^^^^ not found in this scope

tests/ui/cfg/expanded-cfg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ check-pass
22

3+
#![allow(unexpected_cfgs)] // since we different cfgs
4+
35
macro_rules! mac {
46
{} => {
57
#[cfg(attr)]

tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ check-fail
2-
//@ compile-flags:--cfg foo
2+
//@ compile-flags:--cfg foo --check-cfg=cfg(foo)
33

44
#![cfg_attr(foo, crate_type="bin")]
55
//~^ERROR `crate_type` within

0 commit comments

Comments
 (0)