Commit Graph

7464 Commits

Author SHA1 Message Date
Matthias Krüger
3bfce83cb2
Rollup merge of #138370 - cuviper:try_oom_error, r=jhpratt
Simulate OOM for the `try_oom_error` test

We can create the expected error manually, rather than trying to produce
a real one, so the error conversion test can run on all targets. Before,
it was only running on 64-bit and not miri.

In Fedora, we also found that s390x was not getting the expected error,
"successfully" allocating the huge size because it was optimizing the
real `malloc` call away. It's possible to counter that by looking at the
pointer in any way, like a debug print, but it's more robust to just
deal with errors directly, since this test is only about conversion.

Related: #133806
2025-03-13 10:58:24 +01:00
Matthias Krüger
448aa30b5a
Rollup merge of #138162 - ehuss:library-2024, r=cuviper
Update the standard library to Rust 2024

This updates the standard library to Rust 2024. This includes the following notable changes:

- Macros are updated to use new expression fragment specifiers. This PR includes a test to illustrate the changes, primarily allowing `const {...}` expressions now.
- Some tests show a change in MIR drop order. We do not believe this will be an observable change ([see zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/268952-edition/topic/standard.20library.20migration/near/500972873)).

Fixes https://github.com/rust-lang/rust/issues/133081
2025-03-13 10:58:21 +01:00
Matthias Krüger
9527572460
Rollup merge of #137355 - thaliaarchi:io-optional-methods/sgx, r=ChrisDenton
Implement `read_buf` and vectored read/write for SGX stdio

Implement `read_buf`, `read_vectored`, and `write_vectored` for the SGX stdio types.

Additionally, extend `User<T>::copy_to_enclave` to work for copying to uninitialized values and fix unsoundness in `UserRef<[T]>::copy_to_enclave_vec`.

cc ``@jethrogb``

Tracked in https://github.com/rust-lang/rust/issues/136756
2025-03-13 10:58:19 +01:00
Matthias Krüger
a488cf8a70
Rollup merge of #136842 - randomPoison:trusty-libstd-v3, r=ChrisDenton
Add libstd support for Trusty targets

This PR adds support for `alloc` and `std` for the Trusty targets based on the internal patches used in Android. The original patches can be seen [here](https://android.googlesource.com/toolchain/android_rust/+/refs/heads/main/patches/development/rustc-0023-Add-Trusty-OS-support-to-Rust-std.patch) and [here](https://android.googlesource.com/toolchain/android_rust/+/refs/heads/main/patches/development/rustc-0054-Add-std-os-fd-support-for-Trusty.patch). Please let me know if there's any additional context I need to add.
2025-03-13 10:58:17 +01:00
bors
8536f201ff Auto merge of #138416 - Manishearth:rollup-fejor9p, r=Manishearth
Rollup of 12 pull requests

Successful merges:

 - #134076 (Stabilize `std::io::ErrorKind::InvalidFilename`)
 - #137504 (Move methods from Map to TyCtxt, part 4.)
 - #138175 (Support rmeta inputs for --crate-type=bin --emit=obj)
 - #138259 (Disentangle `ForwardGenericParamBan` and `ConstParamTy` ribs)
 - #138280 (fix ICE in pretty-printing `global_asm!`)
 - #138318 (Rustdoc: remove a bunch of `@ts-expect-error` from main.js)
 - #138331 (Use `RUSTC_LINT_FLAGS` more)
 - #138357 (merge `TypeChecker` and `TypeVerifier`)
 - #138394 (remove unnecessary variant)
 - #138403 (Delegation: one more ICE fix for `MethodCall` generation)
 - #138407 (Delegation: reject C-variadics)
 - #138409 (Use sa_sigaction instead of sa_union.__su_sigaction for AIX)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-13 01:37:26 +00:00
Manish Goregaokar
185dd2d01b
Rollup merge of #134076 - GrigorenkoPV:InvalidFilename, r=joboet
Stabilize `std::io::ErrorKind::InvalidFilename`

FCP complete: https://github.com/rust-lang/rust/issues/130192#issuecomment-2674989358

Tracking issues: #86442 & #130192

This PR:
- Stabilizes `InvalidFilename` without changing its name to `InvalidFileName`.
- Fixes the doc comment (https://github.com/rust-lang/rust/issues/130192#issuecomment-2429534640)
- Does not separate "the name is too long" case into a separate `ErrorKind`. That case is currently documented to be covered by `InvalidFilename` in the doc. I'm not sure if it would be possible to change this later or if that would be an unacceptable breaking change.
- Does not map more raw OS errors to this `ErrorKind` (as suggested in https://github.com/rust-lang/rust/issues/86442#issuecomment-1441709738). This can presumably be addressed later.
2025-03-12 10:19:25 -07:00
Matthias Krüger
a21d41a22d
Rollup merge of #138269 - Ayush1325:uefi-fs-permission, r=joboet
uefi: fs: Implement FileType, FilePermissions and FileAttr

- In UEFI, both FileType and FilePermissions are represented by the attr bitfield.
- Using simple bools here since both are represented by a single bit.
- Add `FILE_PERMISSION` mask for constructing attribute while change permissions.

cc ````@nicholasbishop````
2025-03-12 17:59:07 +01:00
Thalia Archibald
c62aa0baa1 Fix UserRef<[T]>::copy_to_enclave_vec
It reinterprets uninitialized memory as initialized and does not drop
existing elements of the Vec. Fix that.

Additionally, make it more general by appending, instead of overwriting
existing elements, and rename it to `append_to_enclave_vec`. A caller
can simply call `.clear()` before, for the old behavior.
2025-03-11 20:16:31 -07:00
bors
c625102320 Auto merge of #138366 - matthiaskrgr:rollup-cn16m7q, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #137715 (Allow int literals for pattern types with int base types)
 - #138002 (Disable CFI for weakly linked syscalls)
 - #138051 (Add support for downloading GCC from CI)
 - #138231 (Prevent ICE in autodiff validation by emitting user-friendly errors)
 - #138245 (stabilize `ci_rustc_if_unchanged_logic` test for local environments)
 - #138256 (Do not feed anon const a type that references generics that it does not have)
 - #138284 (Do not write user type annotation for const param value path)
 - #138296 (Remove `AdtFlags::IS_ANONYMOUS` and `Copy`/`Clone` condition for anonymous ADT)
 - #138352 (miri native_calls: ensure we actually expose *mutable* provenance to the memory FFI can access)
 - #138354 (remove redundant `body`  arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-11 21:17:18 +00:00
Josh Stone
53f488aa4b Simulate OOM for the try_oom_error test
We can create the expected error manually, rather than trying to produce
a real one, so the error conversion test can run on all targets. Before,
it was only running on 64-bit and not miri.

In Fedora, we also found that s390x was not getting the expected error,
"successfully" allocating the huge size because it was optimizing the
real `malloc` call away. It's possible to counter that by looking at the
pointer in any way, like a debug print, but it's more robust to just
deal with errors directly, since this test is only about conversion.
2025-03-11 13:27:15 -07:00
Matthias Krüger
9746ac5c2f
Rollup merge of #138002 - 1c3t3a:fix-std-cfi-violation, r=rcvalle
Disable CFI for weakly linked syscalls

Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g. std::sys::random::getrandom, we can observe a CFI violation. This is the case for all consumers of the std::sys::pal::weak::syscall macro, as it is defining weak functions which don't show up in LLVM IR metadata. CFI fails for all these functions.

Similar to other such cases in
https://github.com/rust-lang/rust/issues/115199, this change stops emitting the CFI typecheck for consumers of the macro via the `#[no_sanitize(cfi)]` attribute.

r? ``````@rcvalle``````
2025-03-11 19:35:28 +01:00
Nicole L
d3c55cd52b
Remove unnecessary parens
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2025-03-11 11:16:10 -07:00
bors
6650252439 Auto merge of #128440 - oli-obk:defines, r=lcnr
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type

Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed.

A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table.

Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable.

Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature.

One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now.

fixes #131298
2025-03-11 18:13:31 +00:00
Eric Huss
993359e701 Migrate std to Rust 2024 2025-03-11 09:46:34 -07:00
Jakub Beránek
95d9ade39d
Rollup merge of #137967 - mustartt:fix-aix-test-hangs, r=workingjubilee
[AIX] Fix hangs during testing

Fixes all current test hangs experienced during CI runs.
1. ipv6 link-local (the loopback device) gets assigned an automatic zone id of 1, causing the assert to fail and hang in `library/std/src/net/udp/tests.rs`
2. Const alloc does not fail gracefully
3. Debuginfo test has problem with gdb auto load safe path
2025-03-11 13:30:50 +01:00
Oli Scherer
cb4751d4b8 Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
Pavel Grigorenko
7475a3416b Stabilize std::io::ErrorKind::InvalidFilename 2025-03-11 14:07:31 +03:00
Nicole L
2b3b0bd50b Remove unused file 2025-03-10 14:19:27 -07:00
Nicole L
f5dd3d13fc Update Trusty support to account for recent libstd reorganization 2025-03-10 12:54:59 -07:00
Nicole LeGare
0b1a7ab339 Remove custom TLS implementation for Trusty targets 2025-03-10 10:00:25 -07:00
Nicole LeGare
22fea97c9d Disable unsupported tests
Unclear why this needs to be done manually and is not done by the existing Trusty patches.
2025-03-10 10:00:25 -07:00
Nicole LeGare
d633d8e074 Format after patches have been applied 2025-03-10 10:00:25 -07:00
Nicole LeGare
7f6ee12526 Apply rustc-0054-Add-std-os-fd-support-for-Trusty.patch 2025-03-10 10:00:24 -07:00
Nicole LeGare
87ca2dbb00 Apply rustc-0023-Add-Trusty-OS-support-to-Rust-std.patch 2025-03-10 10:00:24 -07:00
Bastian Kersting
e5dc1e3786 Add comments for #[no_sanitize(cfi)] in stdlib 2025-03-10 08:59:24 +00:00
Bastian Kersting
02bb2d4410 Disable CFI for weakly linked syscalls
Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g.
std::sys::random::getrandom, we can observe a CFI violation. This is
the case for all consumers of the std::sys::pal::weak::weak macro,
as it is defining weak functions which don't show up in LLVM IR
metadata. CFI fails for all these functions.

Similar to other such cases in
https://github.com/rust-lang/rust/issues/115199, this change stops
emitting the CFI typecheck for consumers of the macro via the
\#[no_sanitize(cfi)] attribute.
2025-03-10 08:51:04 +00:00
Matthias Krüger
2f1908df61
Rollup merge of #138074 - thaliaarchi:hermit-seek, r=ChrisDenton
Support `File::seek` for Hermit

`lseek` was added in `hermit-abi` in commit [87dd201](87dd201a14) (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0.

cc ``@mkroening,`` ``@stlankes``

Fixes https://github.com/hermit-os/hermit-rs/issues/652
2025-03-10 09:32:13 +01:00
Thalia Archibald
8c7a94e4cd Implement read_buf and vectored read/write for SGX stdio 2025-03-10 00:48:13 -07:00
Jethro Beekman
b52666868f Copy from userspace to MaybeUninit
Co-authored-by: Thalia Archibald <thalia@archibald.dev>
2025-03-10 00:45:19 -07:00
Ayush Singh
e0a9dd31c1
uefi: fs: Partially implement FileAttr
- Just the permission and file type.
- FileTimes will need some new conversion functions and thus will come
  with a future PR. Trying to keep things simple here.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10 08:16:56 +05:30
Ayush Singh
c717cc7cd2
uefi: fs: Implement FileType
- Similar to FilePermissions, using bool to represent the bitfield.
- FileType cannot be changed, so no need to worry about converting back
  to attribute.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10 08:16:56 +05:30
Ayush Singh
1833737e16
uefi: fs: Implement FilePermission
- UEFI file permissions are indicated using a u64 bitfield used for
  readonly/filetype, etc.
- Using normal bool with to and from attribute conversions to
  FilePermission from overriding some other bitfields.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10 08:16:55 +05:30
joboet
c52e0596c5
std: move stdio to sys
As per #117276, this moves the platform definitions of `Stdout` and friends into `sys`. This PR also unifies the UNIX and Hermit implementations and moves the `__rust_print_err` function needed by libunwind on SGX into the dedicated module for such helper functions.
2025-03-09 23:42:13 +01:00
Thalia Archibald
1abaacd375 Support File::seek for Hermit 2025-03-09 15:38:30 -07:00
Thalia Archibald
32d0c4ed86 Update hermit-abi to 0.5.0 2025-03-09 15:38:29 -07:00
Matthias Krüger
33530e4cb9
Rollup merge of #138276 - bdbai:fix-uwp-ntopenfile, r=ChrisDenton
Lazy load NtOpenFile for UWP

Lazily load `NtOpenFile` to allow libraries targeting UWP to build and link.

Fixes #138257 .

r? `@ChrisDenton`
2025-03-09 16:41:54 +01:00
bdbai
33c6c3a1e9 Lazy load NtOpenFile for UWP 2025-03-09 22:42:17 +08:00
Thalia Archibald
685619e4c9 Move fs into sys 2025-03-08 16:22:37 -08:00
Jacob Pratt
6576d35aef
Rollup merge of #138189 - GuillaumeGomez:env-var, r=joshtriplett
Mention `env` and `option_env` macros in `std::env::var` docs

Fixes https://github.com/rust-lang/rust/issues/138159.

Just like there are mentions in `env!` and `option_env!` docs to `std::env::var`, it'd be nice to have a "mention back" as well.
2025-03-08 01:27:23 -05:00
Jacob Pratt
0c67061569
Rollup merge of #137528 - ChrisDenton:rename-win, r=joboet
Windows: Fix error in `fs::rename` on Windows 1607

Fixes #137499

There's a bug in our Windows implementation of `fs::rename` that only manifests on a specific version of Windows. Both newer and older versions of Windows work.

I took the safest route to fixing this by using the old `MoveFileExW` function to implement this and only falling back to the new behaviour if that fails. This is similar to what is done in `unlink` (just above this function).

try-job: dist-x86_64-mingw
try-job: dist-x86_64-msvc
2025-03-08 01:27:21 -05:00
Jacob Pratt
4ec8407196
Rollup merge of #137606 - davidtwco:next-edition, r=traviscross,ehuss
add a "future" edition

This idea has been discussed previously [on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Continuous.20edition-like.20changes.3F/near/432559262) (though what I've implemented isn't exactly the "next"/"future" editions proposed in that message, just the "future" edition). I've found myself prototyping changes that involve edition migrations and wanting to target an upcoming edition for those migrations, but none exists. This should be permanently unstable and not removed.
2025-03-07 21:57:49 -05:00
Guillaume Gomez
17dd2b179c Mention env and option_env macros in std::env::var docs 2025-03-07 22:00:36 +01:00
Matthias Krüger
f5a143f796
Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakis
Ergonomic ref counting

This is an experimental first version of ergonomic ref counting.

This first version implements most of the RFC but doesn't implement any of the optimizations. This was left for following iterations.

RFC: https://github.com/rust-lang/rfcs/pull/3680
Tracking issue: https://github.com/rust-lang/rust/issues/132290
Project goal: https://github.com/rust-lang/rust-project-goals/issues/107

r? ```@nikomatsakis```
2025-03-07 19:15:33 +01:00
Chris Denton
3cb53df1fe
Return OutOfMemoryError and update docs 2025-03-07 17:51:56 +00:00
Chris Denton
0dfe2ae3fb
Windows: Use MoveFileEx by default in fs:rename 2025-03-07 17:51:49 +00:00
bors
03eb454523 Auto merge of #138155 - matthiaskrgr:rollup-xq5buio, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #137674 (Enable `f16` for LoongArch)
 - #138034 (library: Use `size_of` from the prelude instead of imported)
 - #138060 (Revert #138019 after further discussion about how hir-pretty printing should work)
 - #138073 (Break critical edges in inline asm before code generation)
 - #138107 (`librustdoc`: clippy fixes)
 - #138111 (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-07 13:47:27 +00:00
Matthias Krüger
b834632071
Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35
library: Use `size_of` from the prelude instead of imported

Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.

try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-1
2025-03-07 10:12:44 +01:00
Matthias Krüger
6e7d1353d1
Rollup merge of #137674 - heiher:enable-f16-loong, r=tgross35
Enable `f16` for LoongArch

Blocked on https://github.com/rust-lang/compiler-builtins/pull/770

r? ```@tgross35```

Tracking issue for f16: https://github.com/rust-lang/rust/issues/116909

try-job: dist-loongarch64-linux
try-job: dist-loongarch64-musl
2025-03-07 10:12:43 +01:00
Matthias Krüger
a98df54bdc
Rollup merge of #137832 - wgwoods:fix-bufreader-peek, r=joboet
Fix crash in BufReader::peek()

`bufreader_peek` tracking issue: #128405

This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
2025-03-07 10:02:22 +01:00
Matthias Krüger
d9860276b8
Rollup merge of #137777 - thaliaarchi:os_string-push-str, r=joboet
Specialize `OsString::push` and `OsString as From` for UTF-8

When concatenating two WTF-8 strings, surrogate pairs at the boundaries need to be joined. However, since UTF-8 strings cannot contain surrogate halves, this check can be skipped when one string is UTF-8. Specialize `OsString::push` to use a more efficient concatenation in this case.

The WTF-8 version of `OsString` tracks whether it is known to be valid UTF-8 with its `is_known_utf8` field. Specialize `From<AsRef<OsStr>>` so this can be set for UTF-8 string types.

Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro.

r? ``@ChrisDenton``
2025-03-07 10:02:20 +01:00