Skip to content

Rollup of 7 pull requests - #157472

Closed
GuillaumeGomez wants to merge 15 commits into
rust-lang:mainfrom
GuillaumeGomez:rollup-DB2JeT3
Closed

Rollup of 7 pull requests#157472
GuillaumeGomez wants to merge 15 commits into
rust-lang:mainfrom
GuillaumeGomez:rollup-DB2JeT3

Conversation

@GuillaumeGomez

Copy link
Copy Markdown
Member

Successful merges:

r? @ghost

Create a similar rollup

sanidhyasinand others added 15 commits June 3, 2026 12:09
These methods return `io::Result` but did not document why they can fail
or, importantly, that a child terminated by a signal is reported through
its `ExitStatus` rather than as an `Err`.
Add `# Errors` sections describing the common reasons spawning a child
can fail (program not found, missing permission, resource exhaustion)
and clarifying that a running child which exits unsuccessfully or is
killed by a signal is not an error: those methods still return `Ok` and
the outcome is reflected in the resulting `ExitStatus`.
… r=petrochenkov
Staticlib hide internal symbols
According to issue rust-lang#104707, when building a staticlib, all Rust internal symbols — mangled symbols, `#[rustc_std_internal_symbol]` items, allocator shims, etc. — leak out of the static archive. In contrast, cdylib correctly exports only `#[no_mangle]` symbols via a linker version script.
`-Zstaticlib-hide-internal-symbols` directly post-processes ELF object files in the archive: parsing the `SHT_SYMTAB` sections and setting `STV_HIDDEN` visibility on any `GLOBAL/WEAK` defined symbol that is not in the exported symbol set, without changing the binding. This is an in-place modification (only writing the st_other byte per matching entry), with zero overhead.
Supported on ELF targets (Linux, BSD, etc.) and Apple targets (macOS, iOS, etc.). On unsupported targets (Windows), a warning is emitted and the flag has no effect.
**Update**: The rename counterpart (`-Zstaticlib-rename-internal-symbols`) is in rust-lang#156950.
The test code are as follows:
1.a std rust staticlib:
```rust
use std::collections::HashMap;
use std::panic::{catch_unwind, AssertUnwindSafe};
#[no_mangle]
pub extern "C" fn my_add(a: i32, b: i32) -> i32 { a + b }
#[no_mangle]
pub extern "C" fn my_hash_lookup(key: u64) -> u64 {
let mut map = HashMap::new();
for i in 0..100u64 { map.insert(i, i.wrapping_mul(2654435761)); }
*map.get(&key).unwrap_or(&0)
}
pub fn internal_reverse(s: &str) -> String { s.chars().rev().collect() }
#[no_mangle]
pub extern "C" fn my_format_number(n: i32) -> i32 {
let s = format!("number: {}", n); s.len() as i32
}
#[no_mangle]
pub extern "C" fn my_safe_div(a: i32, b: i32) -> i32 {
match catch_unwind(AssertUnwindSafe(|| {
if b == 0 { panic!("division by zero!"); }
a / b
})) {
Ok(result) => result,
Err(_) => -1,
}
}
#[no_mangle]
pub extern "C" fn my_uncaught_panic() { panic!("uncaught panic across FFI"); }
```
1.b downstream c program:
```c
extern int my_add(int a, int b);
extern unsigned long my_hash_lookup(unsigned long key);
extern int my_format_number(int n);
extern int my_safe_div(int a, int b);
extern void my_uncaught_panic(void);
int main() {
int failures = 0;
if (my_add(10, 20) != 30) failures++;
if (my_hash_lookup(5) != 5UL * 2654435761UL) failures++;
if (my_format_number(42) != 10) failures++;
if (my_safe_div(100, 5) != 20) failures++;
if (my_safe_div(100, 0) != -1) failures++;
pid_t pid = fork();
if (pid == 0) { alarm(5); my_uncaught_panic(); _exit(0); }
else { waitpid(pid, &status, 0); }
return failures;
}
```
The test results with different compiler flags(which might cause binary size reduction) are as follows:
1.c result with `-Zstaticlib-hide-internal-symbols`
```
settings OFF ON -Zsave ALL OFF.dynsym ON.dynsym
------------------------------------------------------------------------
default 1.7M 1.5M 204K (12%) 1735 5 1730
lto_thin 616K 584K 33K (5%) 246 5 241
lto_fat 525K 525K 0 (0%) 6 5 1
opt_s 1.7M 1.5M 204K (12%) 1735 5 1730
opt_z 1.7M 1.5M 204K (12%) 1735 5 1730
lto_thin_z 602K 570K 32K (5%) 246 5 241
lto_fat_z 514K 514K 0 (0%) 6 5 1
full 514K 514K 0 (0%) 6 5 1
```
1.d result with `-Zstaticlib-hide-internal-symbols + -Zstaticlib-rename-internal-symbols`
```
settings OFF ON -Zsave ALL OFF.dynsym ON.dynsym
------------------------------------------------------------------------
default 1.7M 1.5M 162K (9%) 1735 5 1730
lto_thin 616K 599K 18K (2%) 246 5 241
lto_fat 525K 535K -1% (-1%) 6 5 1
opt_s 1.7M 1.5M 162K (9%) 1735 5 1730
opt_z 1.7M 1.5M 162K (9%) 1735 5 1730
lto_thin_z 602K 585K 18K (2%) 246 5 241
lto_fat_z 514K 524K -1% (-1%) 6 5 1
full 514K 523K -1% (-1%) 6 5 1
```
2.a no_std rust staticlib
```rust
#![no_std]
#![feature(core_intrinsics)]
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! { loop {} }
#[no_mangle]
pub extern "C" fn embedded_add(a: i32, b: i32) -> i32 { a.wrapping_add(b) }
#[no_mangle]
pub extern "C" fn embedded_checksum(data: *const u8, len: usize) -> u8 {
if data.is_null() { return 0; }
let slice = unsafe { core::slice::from_raw_parts(data, len) };
let mut sum: u8 = 0;
for &byte in slice { sum = sum.wrapping_add(byte); }
sum
}
fn internal_helper() -> i32 { 42 }
#[no_mangle]
pub extern "C" fn call_internal() -> i32 { internal_helper() }
#[no_mangle]
pub extern "C" fn embedded_trigger_abort() { core::intrinsics::abort(); }
```
2.b downstream c program
```c
extern int embedded_add(int a, int b);
extern unsigned char embedded_checksum(const unsigned char *data, unsigned long len);
extern int call_internal(void);
extern void embedded_trigger_abort(void);
int main() {
int failures = 0;
if (embedded_add(10, 20) != 30) failures++;
unsigned char data[] = {1, 2, 3};
if (embedded_checksum(data, 3) != 6) failures++;
if (call_internal() != 42) failures++;
pid_t pid = fork();
if (pid == 0) { embedded_trigger_abort(); _exit(0); }
else { waitpid(pid, &status, 0); }
return failures;
}
```
The test results with different compiler flags(which might cause binary size reduction) are as follows:
2.c result with `-Zstaticlib-hide-internal-symbols`
```
settings OFF ON -Zsave ALL OFF.dynsym ON.dynsym
------------------------------------------------------------------------
default 485K 429K 56K (11%) 490 4 486
lto_thin 180K 180K 0 (0%) 4 4 0
lto_fat 179K 179K 0 (0%) 4 4 0
opt_s 485K 429K 56K (11%) 490 4 486
opt_z 485K 429K 56K (11%) 490 4 486
lto_thin_z 180K 180K 0 (0%) 4 4 0
lto_fat_z 179K 179K 0 (0%) 4 4 0
full 179K 179K 0 (0%) 4 4 0
```
2.d result with `-Zstaticlib-hide-internal-symbols + -Zstaticlib-rename-internal-symbols`
```
settings OFF ON -Zsave ALL OFF.dynsym ON.dynsym
------------------------------------------------------------------------
default 485K 447K 39K (7%) 490 4 486
lto_thin 180K 189K -5% (-5%) 4 4 0
lto_fat 179K 189K -5% (-5%) 4 4 0
opt_s 485K 448K 38K (7%) 490 4 486
opt_z 485K 448K 38K (7%) 490 4 486
lto_thin_z 180K 189K -5% (-5%) 4 4 0
lto_fat_z 179K 189K -5% (-5%) 4 4 0
full 179K 189K -5% (-5%) 4 4 0
```
Test results show that this compiler option is beneficial for scenarios where LTO cannot be enabled.
r? @bjorn3@petrochenkov
…acro, r=Urgau
Create non-exhaustive `proc_macro::EscapeError` enum mirrorring `rustc-literal-escaper`'s
As discussed in rust-lang/literal-escaper#26.
r? @Urgau
…rrow-suggestion, r=mejrs
Suppress E0621 perpetual borrow suggestion
Fixesrust-lang#156682
E0621 suggests `&'a mut Buffer<'a>` when you write `&mut Buffer<'a>` and the compiler wants a named lifetime on the outer reference. That ties both lifetimes together and makes the value unusable after the call. Usually it's not the info that the user actually needs.
When the suggested fix would produce `&'a [mut] T` where `'a` also appears inside `T`, with the changes being implemented on this PR we now suppress the `help:` suggestion and instead emit a `help:` linking to the nomicon's borrow-splitting chapter, which explains the actual fix. Detection uses the pre-fold parameter type and only fires for mutable references, avoiding false positives on trait objects (`&dyn Foo` folds to `&'a (dyn Foo + 'a)`) and shared references (`&'a S<'a>` is often intentional).
What we had before the changes:
```
help: add explicit lifetime `'a` to the type of `buffer`
|
5 | pub fn foo<'a>(buffer: &'a mut Buffer<'a>) {
| ++
```
What we are going to have now after:
```
error[E0621]: explicit lifetime required in the type of `buffer`
|
5 | buffer.buf = &mut buffer.buf[..];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
|
= help: see <https://doc.rust-lang.org/nomicon/borrow-splitting.html> for more
information about lifetime errors related to mutable references
```
…c, r=wesleywiser
fix armv7a-none-eabihf tier doc
I found that PR rust-lang#146522 promoted `armv7a-none-eabihf` from Tier 3 to Tier 2, updating the target spec, `armv7a-none-eabi.md` and `platform-support.md`, but missed updating `arm-none-eabi.md`. The target remained listed under Tier 3 in that file.
So I move `armv7a-none-eabihf` from Tier 3 to Tier 2 in `arm-none-eabi.md`, merging it with the existing `armv7a-none-eabi` entry.
This makes the documentation consistent with the actual tier in the target spec and `platform-support.md`.
r? @wesleywiser
…-errors, r=LawnGnome
Document error conditions for `Command::{spawn, output, status}`
Fixesrust-lang#150361.
`Command::spawn`, `Command::output`, and `Command::status` all return `io::Result`, but the docs never explain *why* they can fail, and they do not mention the (easy to get wrong) distinction between a failure to spawn and a child that runs but exits unsuccessfully or is killed by a signal.
This adds an `# Errors` section to each method:
- **`spawn`** describes the common reasons spawning fails — the program not being found, lacking permission to execute it (e.g. not executable, or blocked by a policy such as `seccomp`), and the OS being unable to create the process due to resource exhaustion. It also clarifies that an error is only returned for failures *while spawning*; once the child has started, anything that happens to it (including signals) is reported through its `ExitStatus`.
- **`output`** and **`status`** refer back to `spawn` for the spawn failures, and explicitly note that a child which exits unsuccessfully or is terminated by a signal is **not** an error — they still return `Ok`, with the outcome reflected in the resulting `ExitStatus`.
The error conditions and the signal/`ExitStatus` behavior were confirmed by `@bjorn3` in the issue discussion.
Docs-only change; no code blocks were added or modified, and all intra-doc links (`io::Error`, `ExitStatus`, `Output`, `spawn`) follow link patterns already used in this module.
r? libs
…r-kulst, r=ZuseZ4
NVPTX: Add @kulst to the target maintainers
@kulst is joining me as a `nvptx64-nvidia-cuda` target maintainer 🎆
r? @ZuseZ4
…=mejrs
Make distinction between crate-level attributes that are warned vs errored
r? @mejrs
This is a follow-up to rust-lang#157377 (comment)
This PR makes all unstable crate-level attributes error on incorrect targets.
To make the diff more helpful, I'd recommend reviewing the two commits separately.
* The first commit introduces the infra & makes all crate-level attributes a warning, the commit should have no effect
* The second commit undoes some changes from the first commit, to make all unstable crate-level attributes error
@rust-borsrust-borsBot added the rollup A PR which is a rollup label Jun 5, 2026
@rust-bors

rust-borsBot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

PR #155338, which is a member of this rollup, was unapproved.

@rustbotrustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 5, 2026
@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

@bors r+ rollup=never p=5

@rust-bors

rust-borsBot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 3022bfe has been approved by GuillaumeGomez

It is now in the queue for this repository.

@rust-borsrust-borsBot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 5, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

This rollup contains a PR that I just unapproved

@rust-borsrust-borsBot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 5, 2026
@rust-bors

rust-borsBot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved due to being closed.

@GuillaumeGomez
GuillaumeGomez deleted the rollup-DB2JeT3 branch June 5, 2026 09:01
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-run-makeArea: port run-make Makefiles to rmake.rsrollupA PR which is a rollupS-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@GuillaumeGomez@JonathanBrouwer@rustbot@sanidhyasin@cezarbbb@kjetilkjeka@Dnreikronos