Commit graph

17950 commits

Author SHA1 Message Date
Matthias Krüger
26b288760e
Rollup merge of #135945 - estebank:useless-parens, r=compiler-errors
Remove some unnecessary parens in `assert!` conditions

While working on #122661, some of these started triggering our "unnecessary parens" lints due to a change in the `assert!` desugaring. A cursory search identified a few more. Some of these have been carried from before 1.0, were a bulk rename from the previous name of `assert!` left them in that state. I went and removed as many of these unnecessary parens as possible in order to have fewer annoyances in the future if we make the lint smarter.
2025-02-07 18:26:26 +01:00
Matthias Krüger
cbd44d7998
Rollup merge of #134367 - WaffleLapkin:trait_upcasting_as_a_treat, r=compiler-errors
Stabilize `feature(trait_upcasting)`

This feature was "done" for a while now, I think it's finally time to stabilize it! Stabilization report: https://github.com/rust-lang/rust/pull/134367#issuecomment-2545839841.
cc reference PR: https://github.com/rust-lang/reference/pull/1622.

Closes #65991 (tracking issue), closes #89460 (the lint is no longer future incompat).

r? compiler-errors
2025-02-07 18:26:25 +01:00
Matthias Krüger
d9f95ecd09
Rollup merge of #136634 - bjoernager:const-mut-cursor, r=m-ou-se
Stabilise `Cursor::{get_mut, set_position}` in `const` scenarios.

Closes: #130801

This PR stabilises the `const_mut_cursor` feature gate.
2025-02-07 12:02:00 +01:00
Waffle Lapkin
3c94d3e60f
remove use of feature(trait_upcasting) from core tests 2025-02-06 23:44:23 +01:00
Esteban Küber
3815ed63ed Remove some unnecessary parens in assert! conditions
While working on #122661, some of these started triggering our "unnecessary parens" lints due to a change in the `assert!` desugaring. A cursory search identified a few more. Some of these have been carried from before 1.0, were a bulk rename from the previous name of `assert!` left them in that state. I went and removed as many of these unnecessary parens as possible in order to have fewer annoyances in the future if we make the lint smarter.
2025-02-06 22:28:44 +00:00
Matthias Krüger
0fb72ee57c
Rollup merge of #136152 - Urgau:stabilize-map_many_mut, r=joshtriplett
Stabilize `map_many_mut` feature

This PR stabilize `HashMap::get_many_mut` as `HashMap::get_disjoint_mut` and `HashMap::get_many_unchecked_mut` as `HashMap::get_disjoint_unchecked_mut` per FCP.

FCP at https://github.com/rust-lang/rust/issues/97601#issuecomment-2532710423
Fixes #97601
r? libs
2025-02-06 21:56:26 +01:00
Matthias Krüger
5b224253c1
Rollup merge of #136630 - jieyouxu:render_tests, r=ChrisDenton
Change two std process tests to not output to std{out,err}, and fix test suite stat reset in bootstrap CI test rendering

I don't really know how to test if this unbreaks CI (since #136607 reported that this breaks the CI test rendering *sometimes*).

Fixes #136607.

r? `@ChrisDenton` (two Windows process tests, but feel free to reroll)
2025-02-06 13:10:05 +01:00
4500ed5256 Stabilise 'Cursor::{get_mut, set_position}' in 'const' scenarios; 2025-02-06 11:54:25 +01:00
许杰友 Jieyou Xu (Joe)
9c5f025c18 tests(std): don't output to std{out,err} in test_creation_flags and test_proc_thread_attributes 2025-02-06 17:18:00 +08:00
bors
59588250ad Auto merge of #136613 - workingjubilee:rollup-ry6rw0m, r=workingjubilee
Rollup of 13 pull requests

Successful merges:

 - #133932 (Avoid using make_direct_deprecated() in extern "ptx-kernel")
 - #136269 (Pass spans around new solver)
 - #136550 (Fix `rustc_hidden_type_of_opaques` for RPITITs with no default body)
 - #136558 (Document minimum supported host tooling on macOS)
 - #136563 (Clean up `Trivial*Impls` macros)
 - #136566 (Fix link in from_fn.rs)
 - #136573 (Document why some "type mismatches" exist)
 - #136583 (Only highlight unmatchable parameters at the definition site)
 - #136587 (Update browser-ui-test version to `0.20.2`)
 - #136590 (Implement RustcInternal for RawPtrKind)
 - #136591 (Add `rustc_hir_pretty::expr_to_string` function)
 - #136595 (Fix `unreachable_pub` lint for hermit target)
 - #136611 (cg_llvm: Remove the `mod llvm_` hack, which should no longer be necessary)

Failed merges:

 - #136565 (compiler: Clean up weird `rustc_abi` reexports)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-06 06:45:07 +00:00
Jubilee
a21c31beca
Rollup merge of #136595 - thaliaarchi:hermit-unreachable-pub, r=Noratrieb
Fix `unreachable_pub` lint for hermit target

The build for the hermit target (`#[cfg(target_os = "hermit")]`) fails on master as of [8df89d1cb0](8df89d1cb0) (2025-02-05), due to introducing `#[warn(unreachable_pub)]` at the root in https://github.com/rust-lang/rust/pull/134286 (Enable unreachable_pub lint in core, merged 2025-01-20).

Make the relevant visibility modifiers more specific to resolve the warning.

```
$ ./x build --target x86_64-unknown-hermit
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.34s
Building stage0 library artifacts (x86_64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.15s
Building compiler artifacts (stage0 -> stage1, x86_64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 1.67s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage1 library artifacts {alloc, core, panic_abort, panic_unwind, proc_macro, std, sysroot, test, unwind} (x86_64-apple-darwin -> x86_64-unknown-hermit)
   Compiling panic_unwind v0.0.0 (library/panic_unwind)
error: unreachable `pub` item
  --> library/panic_unwind/src/hermit.rs:10:9
   |
10 |         pub fn __rust_abort() -> !;
   |         ---^^^^^^^^^^^^^^^^^^^^^^^^
   |         |
   |         help: consider restricting its visibility: `pub(crate)`
   |
   = help: or consider exporting it for use by other crates
   = note: `-D unreachable-pub` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unreachable_pub)]`

error: unreachable `pub` item
  --> library/panic_unwind/src/hermit.rs:17:9
   |
17 |         pub fn __rust_abort() -> !;
   |         ---^^^^^^^^^^^^^^^^^^^^^^^^
   |         |
   |         help: consider restricting its visibility: `pub(crate)`
   |
   = help: or consider exporting it for use by other crates

error: could not compile `panic_unwind` (lib) due to 2 previous errors
Build completed unsuccessfully in 0:00:39
```
2025-02-05 19:53:54 -08:00
Jubilee
8964e70051
Rollup merge of #136566 - hkBst:patch-1, r=scottmcm
Fix link in from_fn.rs
2025-02-05 19:53:49 -08:00
bors
c753cb9b42 Auto merge of #136409 - TDecking:mul_hi, r=Mark-Simulacrum
Use `widening_mul` instead of a separate function

A helper function became obsolete after `widening_mul` became available for `u128` values.
2025-02-06 03:43:58 +00:00
许杰友 Jieyou Xu (Joe)
fd4623bdcc
Rollup merge of #136555 - cramertj:split_off, r=dtolnay
Rename `slice::take...` methods to `split_off...`

This rename was discussed and recommended in a recent t-libs meeting.

cc https://github.com/rust-lang/rust/issues/62280

There's an additional commit here which modifies internals of unstable `OneSidedRange` APIs in order to implement `split_off` methods in a panic-free way (remove `unreachable!()`) as recommended in https://github.com/rust-lang/rust/pull/88502/files#r760177240. I can split this out into a separate PR if needed.
2025-02-05 19:09:38 +08:00
许杰友 Jieyou Xu (Joe)
f30ce21602
Rollup merge of #136537 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.145

This includes https://github.com/rust-lang/compiler-builtins/pull/752 which is required for LLVM 20.
2025-02-05 19:09:37 +08:00
许杰友 Jieyou Xu (Joe)
7ad1a3b8d8
Rollup merge of #136517 - m4rch3n1ng:inherent-str-constructors, r=jhpratt
implement inherent str constructors

implement #131114

this implements
- str::from_utf8
- str::from_utf8_mut
- str::from_utf8_unchecked
- str::from_utf8_unchecked_mut

i left `std::str::from_raw_parts` and `std::str::from_raw_parts_mut` out of this as those are unstable and were not mentioned by the tracking issue or the original pull request, but i can  add those here as well.

i was also unsure of what to do with the `rustc_const_(un)stable` attributes: i removed the `#[rustc_const_stable]` attribute from `str::from_utf8`, `str::from_utf8_unchecked` and `str::from_utf8_unchecked_mut`, and left the`#[rust_const_unstable]` in `str::from_utf8_mut` (btw why is that one not const stable yet with #57349 merged?).

is there a way to redirect users to the stable `std::str::from_utf8` instead of only saying "hey this is unstable"?

for now i just removed the check for `str::from_utf8` in the test in `tests/ui/suggestions/suggest-std-when-using-type.rs`.
2025-02-05 19:09:36 +08:00
许杰友 Jieyou Xu (Joe)
ff339fbbf4
Rollup merge of #136449 - joboet:move_pal_net, r=ChrisDenton
std: move network code into `sys`

As per #117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support #135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
2025-02-05 19:09:35 +08:00
许杰友 Jieyou Xu (Joe)
cc58e8b7ec
Rollup merge of #136418 - Ayush1325:command-env, r=jhpratt
uefi: process: Add support for command environment variables

Set environment variables before launching the process and restore the prior variables after the program exists.

This is the same implementation as the one used by UEFI Shell Execute [0].

[0]: 2d2642f483/ShellPkg/Application/Shell/ShellProtocol.c (L1700)
2025-02-05 19:09:35 +08:00
Marijn Schouten
6770d3ddf4
Fix link in from_fn.rs 2025-02-05 08:52:13 +01:00
Thalia Archibald
5794952156 Fix unreachable_pub lint for hermit target 2025-02-04 23:38:17 -08:00
León Orell Valerian Liehr
ba420062f1
Rollup merge of #136502 - yotamofek:pr/fmt-from-fn-must-use, r=dtolnay
Mark `std::fmt::from_fn` as `#[must_use]`

While working on #135494 I managed to shoot my own foot a few times by forgetting to actually use the result of `fmt::from_fn`, so I think a `#[must_use]` could be appropriate!

Didn't have a good message to put in the attr so left it blank, still unstable so we can come back to it I guess?

cc #117729 (and a huge +1 for getting it stabilized, it's very useful IMHO)
2025-02-05 05:03:06 +01:00
León Orell Valerian Liehr
d81701b610
Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obk
#[contracts::requires(...)]  + #[contracts::ensures(...)]

cc https://github.com/rust-lang/rust/issues/128044

Updated contract support: attribute syntax for preconditions and postconditions, implemented via a series of desugarings  that culminates in:
1. a compile-time flag (`-Z contract-checks`) that, similar to `-Z ub-checks`, attempts to ensure that the decision of enabling/disabling contract checks is delayed until the end user program is compiled,
2. invocations of lang-items that handle invoking the precondition,  building a checker for the post-condition, and invoking that post-condition checker at the return sites for the function, and
3. intrinsics for the actual evaluation of pre- and post-condition predicates that third-party verification tools can intercept and reinterpret for their own purposes (e.g. creating shims of behavior that abstract away the function body and replace it solely with the pre- and post-conditions).

Known issues:

 * My original intent, as described in the MCP (https://github.com/rust-lang/compiler-team/issues/759) was   to have a rustc-prefixed attribute namespace (like   rustc_contracts::requires). But I could not get things working when I tried   to do rewriting via a rustc-prefixed builtin attribute-macro. So for now it  is called `contracts::requires`.

 * Our attribute macro machinery does not provide direct support for attribute arguments that are parsed like rust expressions. I spent some time trying to add that (e.g. something that would parse the attribute arguments as an AST while treating the remainder of the items as a token-tree), but its too big a lift for me to undertake. So instead I hacked in something approximating that goal, by semi-trivially desugaring the token-tree attribute contents into internal AST constucts. This may be too fragile for the long-term.
   * (In particular, it *definitely* breaks when you try to add a contract to a function like this: `fn foo1(x: i32) -> S<{ 23 }> { ... }`, because its token-tree based search for where to inject the internal AST constructs cannot immediately see that the `{ 23 }` is within a generics list. I think we can live for this for the short-term, i.e. land the work, and continue working on it while in parallel adding a new attribute variant that takes a token-tree attribute alongside an AST annotation, which would completely resolve the issue here.)

* the *intent* of `-Z contract-checks` is that it behaves like `-Z ub-checks`, in that we do not prematurely commit to including or excluding the contract evaluation in upstream crates (most notably, `core` and `std`). But the current test suite does not actually *check* that this is the case. Ideally the test suite would be extended with a multi-crate test that explores the matrix of enabling/disabling contracts on both the upstream lib and final ("leaf") bin crates.
2025-02-05 05:03:01 +01:00
Taylor Cramer
836a989820 Add OneSidedRangeBound to eliminate panic in split_point_of
See discussion in https://github.com/rust-lang/rust/pull/88502/files#r760177240
2025-02-04 11:45:21 -08:00
Taylor Cramer
07cf20e987 Rename slice::take methods to split_off 2025-02-04 11:09:17 -08:00
bors
3f33b30e19 Auto merge of #135760 - scottmcm:disjoint-bitor, r=WaffleLapkin
Add `unchecked_disjoint_bitor` per ACP373

Following the names from libs-api in https://github.com/rust-lang/libs-team/issues/373#issuecomment-2085686057

Includes a fallback implementation so this doesn't have to update cg_clif or cg_gcc, and overrides it in cg_llvm to use `or disjoint`, which [is available in LLVM 18](https://releases.llvm.org/18.1.0/docs/LangRef.html#or-instruction) so hopefully we don't need any version checks.
2025-02-04 17:46:06 +00:00
bors
01e4f19cc8 Auto merge of #136534 - jhpratt:rollup-dnz57dq, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - #136398 (add UnsafeCell direct access APIs)
 - #136465 (Some `rustc_middle` cleanups)
 - #136479 (std::fs: further simplify dirent64 handling)
 - #136504 (Fix last compare-mode false negatives in tests)
 - #136511 (Add `cast_signed` and `cast_unsigned` methods for `NonZero` types)
 - #136518 (Add note about `FnPtr` trait being exposed as public bound)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-04 14:59:25 +00:00
bors
7b31983d55 Auto merge of #136533 - jhpratt:rollup-s0ign8n, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - #134777 (Enable more tests on Windows)
 - #135621 (Move some std tests to integration tests)
 - #135844 ( Add new tool for dumping feature status based on tidy )
 - #136167 (Implement unstable `new_range` feature)
 - #136334 (Extract `core::ffi` primitives to a separate (internal) module)

Failed merges:

 - #136201 (Removed dependency on the field-offset crate, alternate approach)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-04 12:13:02 +00:00
Trevor Gross
90fee92fcc Update compiler-builtins to 0.1.145
This includes [1] which is required for LLVM 20.

[1]: https://github.com/rust-lang/compiler-builtins/pull/752
2025-02-04 11:49:01 +00:00
Jacob Pratt
af178aa806
Rollup merge of #136518 - Urgau:fn_ptr-public-bound, r=Noratrieb
Add note about `FnPtr` trait being exposed as public bound
2025-02-04 05:38:06 -05:00
Jacob Pratt
5178a3630e
Rollup merge of #136511 - joshtriplett:nonzero-cast-signed-unsigned, r=dtolnay
Add `cast_signed` and `cast_unsigned` methods for `NonZero` types

Requested in https://github.com/rust-lang/rust/issues/125882 .

Note that this keeps the same names as the methods currently present on other
integer types. If we want to rename them, we can rename them all at the same
time.
2025-02-04 05:38:05 -05:00
Jacob Pratt
1baf59e5f6
Rollup merge of #136479 - RalfJung:dirent64, r=tgross35
std::fs: further simplify dirent64 handling

Follow-up to https://github.com/rust-lang/rust/pull/134678.

r? `@tgross35`
2025-02-04 05:38:04 -05:00
Jacob Pratt
d89e98dcbf
Rollup merge of #136398 - pitaj:unsafecell_access, r=dtolnay
add UnsafeCell direct access APIs

- Implementation for ACP: https://github.com/rust-lang/libs-team/issues/521
- Tracking issue #136327
2025-02-04 05:38:03 -05:00
Jacob Pratt
54f9ef9eda
Rollup merge of #136334 - ricci009:primitivers, r=tgross35
Extract `core::ffi` primitives to a separate (internal) module

### Introduce library/core/src/ffi/primitives.rs

The regex preprocessing for PR #133944 would be more robust if the relevant types from core/src/ffi/mod.rs were first moved to library/core/src/ffi/primitives.rs, then there isn't a need to deal with traits / c_str / va_list / whatever might wind up in that module in the future

r? `@tgross35`
2025-02-04 05:36:53 -05:00
Jacob Pratt
d31e137d6a
Rollup merge of #136167 - pitaj:new_range, r=Nadrieril
Implement unstable `new_range` feature

Switches `a..b`, `a..`, and `a..=b` to resolve to the new range types.

For rust-lang/rfcs#3550
Tracking issue #123741

also adds the re-export that was missed in the original implementation of `new_range_api`
2025-02-04 05:36:52 -05:00
Jacob Pratt
d2aa3dec8a
Rollup merge of #135621 - bjorn3:move_tests_to_stdtests, r=Noratrieb
Move some std tests to integration tests

Unit tests directly inside of standard library crates require a very fragile way of building that is hard to reproduce outside of bootstrap.

Follow up to https://github.com/rust-lang/rust/pull/133859
2025-02-04 05:36:50 -05:00
bors
019fc4de2f Auto merge of #135265 - pascaldekloe:fmt-int-speed, r=tgross35,ChrisDenton
Display of integers without raw pointers and without overflowing_literals

The benchmarks as is measure formatting speed of literals. The first commit `black_box`-es input to simulate runtime speed instead.

The second commit replaces `unsafe` pointer optimizations with plain array indices. The performance is equivalent on Apple M1. Needs peer review on Intel.

Happy to do the 128-bit version too if such change is welcome.
2025-02-04 09:15:53 +00:00
may
15adc38ffc
specify a prim@slice in docs
i am not quite sure how this failure is in any way related to this pr,
since i am only touching inherent functions on str? but sure.
2025-02-04 02:51:44 +01:00
may
03eed12168
implement inherent str constructors 2025-02-04 02:51:44 +01:00
Urgau
d47cb21188 Add note about FnPtr being exposed as public bound 2025-02-03 23:59:43 +01:00
ricci009
3419e2f408 primitive type migration from mod.rs to primitives.rs 2025-02-03 17:21:32 -05:00
Celina G. Val
ddbf54b67d Rename rustc_contract to contract
This has now been approved as a language feature and no longer needs
a `rustc_` prefix.

Also change the `contracts` feature to be marked as incomplete and
`contracts_internals` as internal.
2025-02-03 13:55:15 -08:00
Celina G. Val
2bb1464cb6 Improve contracts intrisics and remove wrapper function
1. Document the new intrinsics.
2. Make the intrinsics actually check the contract if enabled, and
   remove `contract::check_requires` function.
3. Use panic with no unwind in case contract is using to check for
   safety, we probably don't want to unwind. Following the same
   reasoning as UB checks.
2025-02-03 13:55:15 -08:00
Felix S. Klock II
6a6c6b891b Separate contract feature gates for the internal machinery
The extended syntax for function signature that includes contract clauses
should never be user exposed versus the interface we want to ship
externally eventually.
2025-02-03 13:55:15 -08:00
Felix S. Klock II
ae7eff0be5 Desugars contract into the internal AST extensions
Check ensures on early return due to Try / Yeet

Expand these two expressions to include a call to contract checking
2025-02-03 13:54:32 -08:00
Josh Triplett
f4a92e3262 Add cast_signed and cast_unsigned methods for NonZero types 2025-02-03 22:18:44 +01:00
Celina G. Val
38eff16d0a Express contracts as part of function header and lower it to the contract lang items
includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures.

includes post-developed commit: removed tabs that creeped in into rustfmt tool source code.

includes post-developed commit, placating rustfmt self dogfooding.

includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/

includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures).

Rebase Conflicts:
 - compiler/rustc_parse/src/parser/diagnostics.rs
 - compiler/rustc_parse/src/parser/item.rs
 - compiler/rustc_span/src/hygiene.rs

Remove contracts keywords from diagnostic messages
2025-02-03 12:54:00 -08:00
Felix S. Klock II
777def87d5 contracts: added lang items that act as hooks for rustc-injected code to invoke.
see test for an example of the kind of injected code that is anticipated here.
2025-02-03 12:54:00 -08:00
Felix S. Klock II
bcb8565f30 Contracts core intrinsics.
These are hooks to:

  1. control whether contract checks are run
  2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-03 12:53:57 -08:00
Yotam Ofek
6b016d7e59 Mark std::fmt::from_fn as #[must_use] 2025-02-03 20:17:27 +00:00
Matthias Krüger
f2b7a299d2
Rollup merge of #136289 - Pyr0de:oncecell-docs, r=tgross35
OnceCell & OnceLock docs: Using (un)initialized consistently

Changed
* `set` / `initialize` / `full` to `initialized state`
* `uninitialize` / `empty` to `uninitialized state`
* `f` to `f()`
* Added explaination of `uninitialized state` & `initialized state`

[OnceCell Docs](https://doc.rust-lang.org/nightly/std/cell/struct.OnceCell.html)
[OnceLock Docs](https://doc.rust-lang.org/nightly/std/sync/struct.OnceLock.html)

Fixes #85716
``@rustbot`` label +A-docs
2025-02-03 21:11:33 +01:00