Commit Graph

6553 Commits

Author SHA1 Message Date
Jani Mustonen
4ca3151568 doc: describe panic conditions for SliceIndex implementations
Implementation note: The most probable place for users to find
the documentation is at https://doc.rust-lang.org/std/slice/trait.SliceIndex.html

On that page, documentation added to specific methods will not
be visible. As such, I opted to add the comments to the impl blocks
directly.

Helps with #121568.
2024-03-31 16:13:25 +03:00
Stepan Koltsov
8f5a28e0aa Require Pointee::Metadata to be Freeze
So pointee metadata can be used in anonymous statics.

This is prerequisite for implementing ThinBox without allocation for
ZST.

See https://github.com/rust-lang/rust/pull/123184#discussion_r1544627488
2024-03-31 03:35:17 +01:00
bors
1aedc9640c Auto merge of #123181 - stepancheg:pointee-metadata-debug, r=the8472,Amanieu
Require Debug for Pointee::Metadata

Useful for debugging.
2024-03-31 00:09:41 +00:00
bors
5da1a1b59a Auto merge of #123085 - tgross35:f16-f128-step4.0-libs-basic-impls, r=Amanieu
Add basic trait impls for `f16` and `f128`

Split off part of <https://github.com/rust-lang/rust/pull/122470> so the compiler doesn't ICE because it expects primitives to have some minimal traits.

Fixes <https://github.com/rust-lang/rust/issues/123074>
2024-03-30 21:58:49 +00:00
bors
8df7e723ea Auto merge of #99322 - GKFX:const-int-parse, r=Mark-Simulacrum
Make {integer}::from_str_radix constant

This commit makes FromStr on integers constant so that `const x: u32 = "23".parse();` works. More practical use-case is with environment variables at build time as discussed in https://github.com/rust-lang/rfcs/issues/1907.

Tracking issue #59133.

ACP: https://github.com/rust-lang/libs-team/issues/74
2024-03-30 19:56:58 +00:00
Matthias Krüger
558880ab88
Rollup merge of #123201 - Wilfred:patch-2, r=Nilstrieb
Improve wording in std::any explanation

Prefer 'log' over 'log out' to avoid confusion, and use backticks consistently.
2024-03-30 14:30:50 +01:00
George Bateman
3855b8bb60
Make {integer}::from_str_radix constant 2024-03-30 12:43:58 +00:00
Scott McMurray
0601f0c66d De-LLVM the unchecked shifts [MCP#693]
This is just one part of the MCP, but it's the one that IMHO removes the most noise from the standard library code.

Seems net simpler this way, since MIR already supported heterogeneous shifts anyway, and thus it's not more work for backends than before.
2024-03-30 03:32:11 -07:00
Aria Beingessner
ea92faec49 stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate
This is an alternative to #121920
2024-03-29 19:59:46 -04:00
bors
faae5f1ffe Auto merge of #122520 - scottmcm:stabilize_unchecked_math_basics, r=jhpratt
Stabilize `unchecked_{add,sub,mul}`

Tracking issue: #85122

I think we might as well just stabilize these basic three.  They're the ones that have `nuw`/`nsw` flags in LLVM.

Notably, this doesn't include the potentially-more-complex or -more-situational things like `unchecked_neg` or `unchecked_shr` that are under different feature flags.

To quote Ralf https://github.com/rust-lang/rust/issues/85122#issuecomment-1681669646,

> Are there any objections to stabilizing at least `unchecked_{add,sub,mul}`? For those there shouldn't be any surprises about what their safety requirements are.

*Semantially* these are [already available on stable, even in `const`, via](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=bdb1ff889b61950897f1e9f56d0c9a36) `checked_*`+`unreachable_unchecked`.  So IMHO we might as well just let people write them directly, rather than try to go through a `let Some(x) = x.checked_add(y) else { unsafe { hint::unreachable_unchecked() }};` dance.

I added additional text to each method to attempt to better describe the behaviour and encourage `wrapping_*` instead.

r? rust-lang/libs-api
2024-03-29 20:25:08 +00:00
Justin Karneges
13838a53fd rustfmt 2024-03-29 12:16:09 -07:00
bors
af4a5a13a1 Auto merge of #121268 - Urgau:improve_ambi_wide_ptr_cmps, r=Nadrieril
Add detection of [Partial]Ord methods in the `ambiguous_wide_pointer_comparisons` lint

Partially addresses https://github.com/rust-lang/rust/issues/121264 by adding diagnostics items for PartialOrd and Ord methods, detecting such diagnostics items as "binary operation" and suggesting the correct replacement.

I also took the opportunity to change the suggestion to use new methods `.cast()` on `*mut T` an d `*const T`.
2024-03-29 18:23:57 +00:00
Justin Karneges
c6ac3b02db Add Context::ext 2024-03-29 10:12:10 -07:00
Wilfred Hughes
7804edebfe
Improve wording in std::any explanation
Prefer 'log' over 'log out' to avoid confusion, and use backticks consistently.
2024-03-29 10:10:52 -07:00
Arthur Carcano
54ab425839 Add fn const BuildHasherDefault::new
Because `HashMap::with_hasher` constness is being stabilized this will
in turn allow creating empty HashMap<K,V,BuildHasherDefault<H>> in const
context for any H: Default + Hasher.
2024-03-29 17:10:17 +01:00
Urgau
d4b514f982 Add detection of [Partial]Ord methods to the ambiguous wide ptr cmp lint 2024-03-29 16:36:17 +01:00
Urgau
4a9f3cac88 Add diagnostic items for Ord and PartialOrd methods 2024-03-29 16:25:41 +01:00
bors
1c19595575 Auto merge of #122616 - Jules-Bertholet:casemappingiter-layout, r=Nilstrieb
Optimize `core::char::CaseMappingIter`

Godbolt says this saves a few instructions…

`@rustbot` label T-libs A-layout C-optimization
2024-03-29 07:02:56 +00:00
Stepan Koltsov
b110cb3dc6 Require Debug for Pointee::Metadata
Useful for debugging
2024-03-29 03:53:29 +00:00
bors
760e567af5 Auto merge of #122975 - DianQK:simplify_ub_check, r=saethlin
Eliminate `UbChecks` for non-standard libraries

 The purpose of this PR is to allow other passes to treat `UbChecks` as constants in MIR for optimization after #122629.

r? RalfJung
2024-03-29 02:25:43 +00:00
bors
db2f9759f4 Auto merge of #122671 - Mark-Simulacrum:const-panic-msg, r=Nilstrieb
Codegen const panic messages as function calls

This skips emitting extra arguments at every callsite (of which there
can be many). For a librustc_driver build with overflow checks enabled,
this cuts 0.7MB from the resulting shared library (see [perf]).

A sample improvement from nightly:

```
        leaq    str.0(%rip), %rdi
        leaq    .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdx
        movl    $25, %esi
        callq   *_ZN4core9panicking5panic17h17cabb89c5bcc999E@GOTPCREL(%rip)
```

to this PR:

```
        leaq    .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdi
        callq   *_RNvNtNtCsduqIKoij8JB_4core9panicking11panic_const23panic_const_div_by_zero@GOTPCREL(%rip)
```

[perf]: https://perf.rust-lang.org/compare.html?start=a7e4de13c1785819f4d61da41f6704ed69d5f203&end=64fbb4f0b2d621ff46d559d1e9f5ad89a8d7789b&stat=instructions:u
2024-03-29 00:24:01 +00:00
Trevor Gross
d7d5fc9734 Add basic trait impls for f16 and f128
Split off part of <https://github.com/rust-lang/rust/pull/122470> so the
compiler doesn't ICE because it expects primitives to have some minimal
traits.

Fixes <https://github.com/rust-lang/rust/issues/123074>
2024-03-28 15:02:51 -04:00
Matthias Krüger
83b4d3d638
Rollup merge of #123164 - Marcondiro:unicode15-1, r=Manishearth
Bump Unicode printables to version 15.1, align to unicode_data

r? `@Manishearth`
Thanks!
2024-03-28 17:40:51 +01:00
Marcondiro
e9870b5df3
Bump Unicode printables to version 15.1, align to unicode_data 2024-03-28 11:21:52 +01:00
Matthias Krüger
9c91e2cd84
Rollup merge of #123139 - scottmcm:simpler-nonzero-get, r=jhpratt
`num::NonZero::get` can be 1 transmute instead of 2

Just something I noticed in passing.  No need for a `match` in here to call `unreachable_unchecked`, as `transmute_unchecked` will add the appropriate `llvm.assume` <https://rust.godbolt.org/z/W5hjeETnc>.
2024-03-27 23:27:25 +01:00
Matthias Krüger
45cec32ac3
Rollup merge of #123133 - xiaoxiangxianzi:master, r=fmease
chore: fix some comments
2024-03-27 23:27:24 +01:00
Matthias Krüger
a9ed9fb943
Rollup merge of #121943 - joshlf:patch-11, r=scottmcm
Clarify atomic bit validity

The previous definition used the phrase "representation", which is ambiguous given the current state of memory model nomenclature in Rust. For integer types and for `AtomicPtr<T>`, the new wording clarifies that size and bit validity are guaranteed to match the corresponding native integer type/`*mut T`. For `AtomicBool`, the new wording clarifies that size, alignment, and bit validity are guaranteed to match `bool`.

Note that we use the phrase "size and alignment" rather than "layout" since the latter term also implies that the field types are the same. This isn't true - `AtomicXxx` doesn't store an `xxx`, but rather an `UnsafeCell<xxx>`. This distinction is important for some `unsafe` code, which needs to reason about the presence or absence of interior mutability in order to ensure that their code is sound (see e.g. https://github.com/google/zerocopy/issues/251).
2024-03-27 23:27:22 +01:00
Scott McMurray
336ff42367 num::NonZero::get can be 1 transmute instead of 3 2024-03-27 10:25:56 -07:00
xiaoxiangxianzi
3157114f0b chore: fix some comments
Signed-off-by: xiaoxiangxianzi <zhaoyizheng@outlook.com>
2024-03-27 22:32:53 +08:00
DianQK
47ed73a7b5
Eliminate UbCheck for non-standard libraries 2024-03-27 21:02:40 +08:00
tison
95e195f41e
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock
See also https://github.com/rust-lang/rust/issues/74465#issuecomment-1676522051

Signed-off-by: tison <wander4096@gmail.com>
2024-03-27 16:16:08 +08:00
bors
0dcc1309d0 Auto merge of #116016 - jhpratt:kill-rustc-serialize, r=ehuss
Soft-destabilize `RustcEncodable` & `RustcDecodable`, remove from prelude in next edition

cc rust-lang/libs-team#272

Any use of `RustcEncodable` and `RustcDecodable` now triggers a deny-by-default lint. The derives have been removed from the 2024 prelude. I specifically chose **not** to document this in the module-level documentation, as the presence in existing preludes is not documented (which I presume is intentional).

This does not implement the proposed change for `rustfix`, which I will be looking into shortly.

With regard to the items in the preludes being stable, this should not be an issue because #15702 has been resolved.

r? libs-api
2024-03-27 07:30:36 +00:00
Matthias Krüger
0029a11d7d
Rollup merge of #122835 - compiler-errors:deref-pure, r=Nadrieril
Require `DerefMut` and `DerefPure` on `deref!()` patterns when appropriate

Waiting on the deref pattern syntax pr to merge

r? nadrieril
2024-03-26 21:23:48 +01:00
Ralf Jung
6e190fa993 panic_str only exists for the migration to 2021 panic macros 2024-03-26 08:11:34 +01:00
Michael Goulet
fc1d7d275b Extract helper, fix comment on DerefPure 2024-03-25 19:39:45 -04:00
Michael Goulet
b56279569b Require DerefPure for patterns 2024-03-25 19:39:45 -04:00
Jubilee
ac0a9c58e8
Rollup merge of #123042 - dpaoliello:prelude, r=Nilstrieb
Import the 2021 prelude in the core crate

The `core` crate currently imports the v1 prelude
b3df0d7e5e/library/core/src/lib.rs (L285-L287)

This recently caused an issue when updating the `portable-simd` subtree since it was using a trait that was added to the 2021 prelude: https://github.com/rust-lang/rust/pull/122905#discussion_r1536228822

To make it easier to have a consistent build environment for subtrees and submodules that get included in `core`, we will now import the 2021 prelude into `core`.

Fixes #122912

r? `@Nilstrieb`
2024-03-25 14:35:37 -07:00
Jubilee
cf9acea658
Rollup merge of #122896 - dpaoliello:stdarch, r=Amanieu
Update stdarch submodule

r? ```@Amanieu```
2024-03-25 14:35:35 -07:00
Daniel Paoliello
d261647c93 Import the 2021 prelude in the core crate 2024-03-25 13:12:06 -07:00
Matthias Krüger
e3fbaa87c9
Rollup merge of #122990 - SkiFire13:transmute-may-copy, r=jhpratt
Clarify transmute example

The example claims using an iterator will copy the entire vector, but this is not true in practice thanks to internal specializations in the stdlib (see https://godbolt.org/z/cnxo3MYs5 for confirmation that this doesn't reallocate nor iterate over the vec's elements). Since neither the copy nor the optimization is guaranteed I opted for saying that they _may_ happen.
2024-03-25 11:00:13 +01:00
Scott McMurray
c59e93c753 Address PR feedback 2024-03-24 17:42:35 -07:00
Scott McMurray
8d5977d6af Slightly simplify the iN::partial_cmp MIR
This saves some debug and scope metadata in every single function that calls it.

Normally wouldn't be worth it, but with the derives there's *so* many of these.
2024-03-24 10:01:37 -07:00
Matthias Krüger
6b1f4e44d2
Rollup merge of #122977 - cuviper:as_statically_known_str, r=RalfJung
Rename `Arguments::as_const_str` to `as_statically_known_str`

While `const` has a particular meaning about language guarantees, here
we need a fuzzier notion like whether constant propagation was
effective, and `statically_known` is the best term we have for now.

r? ``@RalfJung``
2024-03-24 17:08:18 +01:00
Giacomo Stevanato
fb65ca14b2 Clarify transmute example 2024-03-24 11:27:34 +01:00
Scott McMurray
3da115a93b Add+Use mir::BinOp::Cmp 2024-03-23 23:23:41 -07:00
Jubilee
862d870070
Rollup merge of #122762 - RoboSchmied:RoboSchmied-typo, r=workingjubilee
fix typo of endianness

fix typo
endianess -> endianness
2024-03-23 22:59:41 -07:00
Josh Stone
b67ad8f626 Rename Arguments::as_const_str to as_statically_known_str
While `const` has a particular meaning about language guarantees, here
we need a fuzzier notion like whether constant propagation was
effective, and `statically_known` is the best term we have for now.
2024-03-23 21:49:29 -07:00
Andy Kurnia
643029693b clarify equivalency of binary_search and partition_point 2024-03-24 08:15:00 +08:00
Matthias Krüger
6f16b41a4b
Rollup merge of #122963 - RalfJung:core-panicking, r=m-ou-se
core/panicking: fix outdated comment

Looks like this function got renamed/changed at some point and the comment did not get updated.

r? `@m-ou-se`
2024-03-24 01:05:54 +01:00
Matthias Krüger
2dcc96883e
Rollup merge of #122379 - RalfJung:int2ptr-transmute, r=m-ou-se
transmute: caution against int2ptr transmutation

This came up in https://github.com/rust-lang/rust/pull/121282.
Cc ```@saethlin``` ```@scottmcm```

Eventually we'll add a proper description of provenance that we can reference, but that's a bunch of work and it's unclear who will have the time to do that when. Meanwhile, let's at least do what we can without mentioning provenance explicitly.
2024-03-24 01:05:52 +01:00
Ralf Jung
f2cff5ebb9 also rename the SIMD intrinsic 2024-03-23 23:03:37 +01:00
bors
2f090c30dd Auto merge of #122629 - RalfJung:assert-unsafe-precondition, r=saethlin
refactor check_{lang,library}_ub: use a single intrinsic

This enacts the plan I laid out [here](https://github.com/rust-lang/rust/pull/122282#issuecomment-1996917998): use a single intrinsic, called `ub_checks` (in aniticpation of https://github.com/rust-lang/compiler-team/issues/725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library.

This makes it easier to do something like https://github.com/rust-lang/rust/pull/122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time.

The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics.

r? `@saethlin`
2024-03-23 21:11:00 +00:00
Ralf Jung
e74b01e925 core/panicking: fix outdated comment 2024-03-23 21:36:22 +01:00
Ralf Jung
6177530420 refactor check_{lang,library}_ub: use a single intrinsic, put policy into library 2024-03-23 18:45:05 +01:00
Ralf Jung
987ef4c922 move assert_unsafe_preconditions to its own file
These macros and functions are not intrinsics, after all.
2024-03-23 18:44:17 +01:00
bors
020bbe46bd Auto merge of #122947 - matthiaskrgr:rollup-10j7orh, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #120577 (Stabilize slice_split_at_unchecked)
 - #122698 (Cancel `cargo update` job if there's no updates)
 - #122780 (Rename `hir::Local` into `hir::LetStmt`)
 - #122915 (Delay a bug if no RPITITs were found)
 - #122916 (docs(sync): normalize dot in fn summaries)
 - #122921 (Enable more mir-opt tests in debug builds)
 - #122922 (-Zprint-type-sizes: print the types of awaitees and unnamed coroutine locals.)
 - #122927 (Change an ICE regression test to use the original reproducer)
 - #122930 (add panic location to 'panicked while processing panic')
 - #122931 (Fix some typos in the pin.rs)
 - #122933 (tag_for_variant follow-ups)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-23 15:58:17 +00:00
Matthias Krüger
9ff7a65752
Rollup merge of #122931 - herobs:patch-1, r=joboet
Fix some typos in the pin.rs
2024-03-23 15:00:21 +01:00
Matthias Krüger
691d5f533d
Rollup merge of #122930 - RalfJung:panic-in-panic-fmt, r=Amanieu
add panic location to 'panicked while processing panic'

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

r? `@Amanieu`
2024-03-23 15:00:20 +01:00
Matthias Krüger
71ce3c26e6
Rollup merge of #120577 - wutchzone:slice_split_at_unchecked, r=m-ou-se
Stabilize slice_split_at_unchecked

Greetings!

I took the opportunity, and I tried to stabilize the `slice_split_at_unchecked` feature. I followed the guidelines, and I hope everything was done correctly 🤞 .

Closes #76014
2024-03-23 15:00:17 +01:00
bors
d6eb0f5a09 Auto merge of #122582 - scottmcm:swap-intrinsic-v2, r=oli-obk
Let codegen decide when to `mem::swap` with immediates

Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea.

Thus this PR introduces a new `typed_swap` intrinsic with a fallback body, and replaces that fallback implementation when swapping immediates or scalar pairs.

r? oli-obk

Replaces #111744, and means we'll never need more libs PRs like #111803 or #107140
2024-03-23 13:57:55 +00:00
Andy Kurnia
5afe4a9e09 improve example on inserting to a sorted vector to avoid shifting equal elements 2024-03-23 21:38:32 +08:00
Ralf Jung
67b9d7d184 rename ptr::from_exposed_addr -> ptr::with_exposed_provenance 2024-03-23 13:18:33 +01:00
Herobs
9e7c00b0e9
Fix some typos in the pin.rs 2024-03-23 16:51:40 +08:00
Ralf Jung
fc257fae3c add panic location to 'panicked while processing panic' 2024-03-23 09:44:04 +01:00
Jacob Pratt
fbf21c5763
Remove RustcEncodable/Decodable from 2024 prelude 2024-03-22 13:30:48 -07:00
Jacob Pratt
2624e9183d
Soft-destabilize RustcEncodable/RustcDecodable 2024-03-22 13:24:35 -07:00
Daniel Paoliello
9685161b04 Update stdarch submodule 2024-03-22 12:16:16 -07:00
Scott McMurray
d0ce391b14 swap_simple no longer needs to be a separate function 2024-03-22 11:55:17 -07:00
Mark Rousskov
00f4daa276 Codegen const panic messages as function calls
This skips emitting extra arguments at every callsite (of which there
can be many). For a librustc_driver build with overflow checks enabled,
this cuts 0.7MB from the resulting binary.
2024-03-22 09:55:50 -04:00
Matthias Krüger
ef4a64b5d2
Rollup merge of #122800 - zachs18:nonnull-slice-is_empty, r=Amanieu
Add `NonNull::<[T]>::is_empty`.

As per https://github.com/rust-lang/rust/issues/71146#issuecomment-2008373983

I figured this should be fine to be insta-stable (with an FCP), but I can edit if that is not desired.

r? ```@Amanieu```
2024-03-22 11:37:00 +01:00
bors
cdb683f6e4 Auto merge of #122024 - clubby789:remove-spec-option-pe, r=jhpratt
Remove SpecOptionPartialEq

With the recent LLVM bump, the specialization for Option::partial_eq on types with niches is no longer necessary. I kept the manual implementation as it still gives us better codegen than the derive (will look at this seperately).

Also implemented PartialOrd/Ord by hand as it _somewhat_ improves codegen for #49892: https://godbolt.org/z/vx5Y6oW4Y
2024-03-22 04:06:25 +00:00
Matthias Krüger
1757cb5871
Rollup merge of #122829 - ShoyuVanilla:gen-block-impl-fused-iter, r=compiler-errors
Implement `FusedIterator` for `gen` block

cc #117078
2024-03-22 01:07:31 +01:00
Zachary S
1b95760e41 Not insta-stable 2024-03-21 17:01:41 -05:00
Shoyu Vanilla
ae4c5c891e Implement FusedIterator for gen block 2024-03-22 02:02:34 +09:00
Michael Goulet
2d633317f3 Implement macro-based deref!() syntax for deref patterns
Stop using `box PAT` syntax for deref patterns, as it's misleading and
also causes their semantics being tangled up.
2024-03-21 11:42:49 -04:00
lilasta
d324d6de0e Stabilize const_caller_location and const_location_fields 2024-03-21 22:19:57 +09:00
Matthias Krüger
62e414d3af
Rollup merge of #122806 - compiler-errors:type-ascribe, r=fmease
Make `type_ascribe!` not a built-in

The only weird thing is the macro expansion note. I wonder if we should suppress these 🤔

r? ````@fmease```` since you told me about builtin# lol
2024-03-21 12:05:09 +01:00
Michael Goulet
a015b90953 Make type_ascribe! not a built-in 2024-03-20 22:28:56 -04:00
Jacob Pratt
43ad753adb
Rollup merge of #122729 - m-ou-se:relax, r=Amanieu
Relax SeqCst ordering in standard library.

Every single SeqCst in the standard library is unnecessary. In all cases, Relaxed or Release+Acquire was sufficient.

As I [wrote](https://marabos.nl/atomics/memory-ordering.html#common-misconceptions) in my book on atomics:

> [..] when reading code, SeqCst basically tells the reader: "this operation depends on the total order of every single SeqCst operation in the program," which is an incredibly far-reaching claim. The same code would likely be easier to review and verify if it used weaker memory ordering instead, if possible. For example, Release effectively tells the reader: "this relates to an acquire operation on the same variable," which involves far fewer considerations when forming an understanding of the code.
>
> It is advisable to see SeqCst as a warning sign. Seeing it in the wild often means that either something complicated is going on, or simply that the author did not take the time to analyze their memory ordering related assumptions, both of which are reasons for extra scrutiny.

r? ````@Amanieu```` ````@joboet````
2024-03-20 20:29:44 -04:00
Zachary S
4250216663 Add NonNull::<[T]>::is_empty as insta-stable. 2024-03-20 18:25:06 -05:00
RoboSchmied
0d5a3f464f Update target.rs alloc.rs event.rs simd.rs
fix typos
2024-03-20 17:07:15 +01:00
bors
a128516cf9 Auto merge of #122754 - Mark-Simulacrum:bootstrap-bump, r=albertlarsan68
Bump to 1.78 bootstrap compiler

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-03-20 13:43:41 +00:00
Mark Rousskov
02f1930595 step cfgs 2024-03-20 08:49:13 -04:00
Michael Goulet
05116c5c30 Only split by-ref/by-move futures for async closures 2024-03-19 16:59:23 -04:00
Matthias Krüger
f7731243d9
Rollup merge of #122720 - heisen-li:offset_of, r=workingjubilee
[doc]:fix error code example

fixs #122716
2024-03-19 18:03:53 +01:00
clubby789
f8fd23a2ad Manually implement PartialOrd/Ord for Option 2024-03-19 16:32:07 +00:00
clubby789
5f254d8b66 Remove SpecOptionPartialEq 2024-03-19 16:32:01 +00:00
Mara Bos
a2c74b8445 SeqCst->Relaxed in doc examples.
SeqCst is unnecessary here.
2024-03-19 15:27:11 +01:00
heisen-li
a370ed7644 [doc]:fix error code example 2024-03-19 17:18:10 +08:00
Oli Scherer
3e5c468662 Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends implementing it 2024-03-19 09:17:40 +00:00
Oli Scherer
e0d67aeb0b Make vtable_align a rustc_intrinsic 2024-03-19 09:13:48 +00:00
Oli Scherer
7f9830b16c Make const_eval_select a rustc_intrinsic 2024-03-19 09:12:58 +00:00
Ralf Jung
f4adb1e6bd add notes on how to store 'ptr or int' 2024-03-19 07:19:22 +01:00
Jules Bertholet
2f1ab2ce09
Reimplement CaseMappingIter with core::array::IntoIter
Makes the iterator 2*usize larger, but I doubt that matters much.
In exchange, we save a lot on instruction count.

In the absence of delegation syntax,
we must forward all the specialized impls manually…
2024-03-18 23:07:28 -04:00
bors
21d94a3d2c Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk
Stabilize associated type bounds (RFC 2289)

This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses.

### What are we stabilizing?

We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation.

In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info).

Associated type bounds are stabilized in four positions:
* **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`.
* **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629.
* **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`.
* **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound.

The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds.

### How does this differ from the RFC?

Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular:
* It does *not* desugar to anonymous associated items in associated type item bounds.
* It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds.

This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example:
* Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531.
* Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types.

This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719.

### Implementation history:

Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out--
* #57428
* #108063
* #110512
* #112629
* #120719
* #120584

Closes #52662

[RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-19 00:04:09 +00:00
Matthias Krüger
e5b9a42e37
Rollup merge of #122675 - tmfink:doc-clarify, r=scottmcm
core: document default attribute stabilization

As of now, the first release which stabilized the `#[default]` macro for the deriving the `Default` trait for enus is not documented.
I have had to search the [`RELEASES.md`](https://github.com/rust-lang/rust/blob/master/RELEASES.md) when making sure my code would be accepted by an older Rust compiler.

I just added a line in the doc comment since, as far as I know, there's no option to pass to the `#[stable()]` attribute.

I am open to improvements in the wording.
2024-03-18 22:24:39 +01:00
Ralf Jung
bcf8015177 remove retag_box_to_raw, it is no longer needed 2024-03-18 10:32:25 +01:00
Scott McMurray
7d537106a1 Let codegen decide when to mem::swap with immediates
Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea.

So introduce a new `typed_swap` intrinsic with a fallback body, but replace that implementation for immediates and scalar pairs.
2024-03-17 11:59:18 -07:00
Petr Portnov
e7d397024f
chore(121952): echo comments on the *_assign methods 2024-03-17 17:06:12 +03:00
Petr Portnov
5ebed0ba4b
chore(121952): remove redundant comments
These were only relevant for the unsafe-containing implementations

Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2024-03-17 17:00:48 +03:00
Petr Portnov
b186f40b8b
feat: implement {Div,Rem}Assign<NonZero<X>> on X
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2024-03-17 17:00:44 +03:00
Matthias Krüger
3c07321541
Rollup merge of #119411 - yotamofek:array-ptr-get, r=Nilstrieb
Add as_(mut_)ptr and as_(mut_)slice to raw array pointers

Hey, first time contributing to the standard libraries so not completely sure about the process.

These functions are complementary to the ones being added in #74265 . I found them missing on array pointers.

See also:
- ACP: https://github.com/rust-lang/libs-team/issues/321
- Tracking issue: #119834
2024-03-17 08:23:25 +01:00
Travis Finkenauer
d7b4b01911 core: document default attribute stabilization 2024-03-16 21:20:29 -07:00
Jules Bertholet
1c137b7582
Optimize core::char::CaseMappingIter layout
Godbolt says this saves a few instructions…
2024-03-16 23:42:06 -04:00
bors
a615cea333 Auto merge of #121885 - reitermarkus:generic-nonzero-inner, r=oli-obk,wesleywiser
Move generic `NonZero` `rustc_layout_scalar_valid_range_start` attribute to inner type.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

r? `@dtolnay`
2024-03-17 02:27:52 +00:00
Yotam Ofek
d0c0887498 Add as_(mut_)ptr and as_(mut_)slice to raw array pointers 2024-03-16 20:15:30 +00:00
joboet
f2721338f6
core: optimize ptr::replace 2024-03-16 17:51:00 +01:00
Scott McMurray
50392ccc5a Workaround issue 122566 2024-03-15 13:09:04 -07:00
Scott McMurray
234e383c34 Stabilize unchecked_{add,sub,mul} 2024-03-14 18:39:37 -07:00
Matthias Krüger
5d41186446
Rollup merge of #122479 - GrigorenkoPV:duration_millis_float, r=scottmcm
Implement `Duration::as_millis_{f64,f32}`

Implementation of #122451.

Linked const-unstability to #72440, so the post there should probably be updated to mentions the 2 new methods when/if this PR is merged.
2024-03-14 20:00:20 +01:00
Markus Reiter
bc532a6307
Hide implementation details for NonZero auto traits. 2024-03-14 17:34:57 +01:00
Matthias Krüger
75dc99b996
Rollup merge of #122461 - the8472:fix-step-forward-unchecked, r=Amanieu
fix unsoundness in Step::forward_unchecked for signed integers

Fixes #122420

```rust
pub fn foo(a: i8, b: u8) -> i8 {
    unsafe { a.checked_add_unsigned(b).unwrap_unchecked() }
}
```

still compiles down to a single arithmetic instruction ([godbolt](https://rust.godbolt.org/z/qsd3xYWfE)).

But we may be losing some loop optimizations if llvm can no longer easily derive that it's a finite counted loop from the no-wrapping flags.
2024-03-14 11:10:00 +01:00
Matthias Krüger
a0e50a4a96
Rollup merge of #122421 - CAD97:step-trait-docs, r=jhpratt
Improve `Step` docs

It [came up on urlo](https://users.rust-lang.org/t/implement-trait-step-in-1-76-0/108204?u=cad97) that the unstable reason string isn't helpful, so just remove it; there's nothing meaningful to add here.

Also makes a couple drive-by improvements to the method docs -- removes incorrect references, changes `forward_checked`'s invariant formulation to match `backward_checked`'s, and adds a helpful corollary that `step_unchecked(a, 0)` is always safe.
2024-03-14 11:09:59 +01:00
Matthias Krüger
1ae69ae615
Rollup merge of #104353 - clarfonthey:cstr-bytes-iter, r=cuviper
Add CStr::bytes iterator

See rust-lang/libs-team#135 for an ACP.

Since rust-lang/libs-team#134 was also accepted, this type is now `core::ffi::c_str::Bytes` instead of `core::ffi::CStrBytes`.
2024-03-14 11:09:56 +01:00
The 8472
be33586adc fix unsoundness in Step::forward_unchecked for signed integers 2024-03-14 00:57:02 +01:00
Pavel Grigorenko
f2ec0d3d26
Implement Duration::as_millis_{f64,f32} 2024-03-14 01:37:12 +03:00
Christopher Durham
c527ec76ce Improve Step docs 2024-03-13 00:49:51 -04:00
ltdk
a38a556ceb Reduce unsafe code, use more NonNull APIs per @cuviper review 2024-03-12 17:21:17 -04:00
Ralf Jung
d3299af26d transmute: caution against int2ptr transmutation 2024-03-12 17:26:45 +01:00
Nadrieril
9962a01e9f Use min_exhaustive_patterns in core & std 2024-03-12 08:20:46 +01:00
Jacob Pratt
05f22c3614
Rollup merge of #121840 - oli-obk:freeze, r=dtolnay
Expose the Freeze trait again (unstably) and forbid implementing it manually

non-emoji version of https://github.com/rust-lang/rust/pull/121501

cc #60715

This trait is useful for generic constants (associated consts of generic traits). See the test (`tests/ui/associated-consts/freeze.rs`) added in this PR for a usage example. The builtin `Freeze` trait is the only way to do it, users cannot work around this issue.

It's also a useful trait for building some very specific abstrations, as shown by the usage by the `zerocopy` crate: https://github.com/google/zerocopy/issues/941

cc ```@RalfJung```

T-lang signed off on reexposing this unstably: https://github.com/rust-lang/rust/pull/121501#issuecomment-1969827742
2024-03-11 03:47:19 -04:00
Jacob Pratt
6c8c272ad4
Rollup merge of #121148 - clarfonthey:try-range, r=dtolnay
Add slice::try_range

This adds a fallible version of the unstable `slice::range` (tracking: #76393) which is highly requested in the tracking issue.

Hoping this can slide by without an ACP (since the feature is already being tracked), but let me know otherwise.
2024-03-11 03:47:18 -04:00
Matthias Krüger
97f3b3383a
Rollup merge of #122302 - ratmice:issue122234, r=cuviper
docs: Correct ptr/ref verbiage in SliceIndex docs.

Fixes #122234
2024-03-10 22:16:45 +01:00
Matthias Krüger
ff09d32d83
Rollup merge of #122277 - RalfJung:BorrowedCursor, r=cuviper
BorrowedCursor docs clarification

If one reads the `BorrowedCursor` docs without having seen `BorrowedBuf` before, it is quite easy to assume that "unfilled" and "uninit" are synonyms.
2024-03-10 22:16:42 +01:00
ltdk
15b71f491f Add CStr::bytes iterator 2024-03-10 17:04:04 -04:00
matt rice
dd2cda731a docs: Correct ptr/ref verbiage in SliceIndex docs.
Fixes #122234
2024-03-10 11:50:05 -07:00
Markus Reiter
85dfb479df
Fix lint. 2024-03-10 13:18:07 +01:00
Markus Reiter
2d48a3a7bc
Move generic NonZero rustc_layout_scalar_valid_range_start attribute to inner type. 2024-03-10 13:18:07 +01:00
Matthias Krüger
9d03046a81
Rollup merge of #122271 - pitaj:diag_items-legacy_numeric_constants, r=Nilstrieb
Fix legacy numeric constant diag items

- missed syms for usize/isize
- missed diag items on unsigned integers

For rust-lang/rust-clippy#12312

r? ```@Nilstrieb```

Follow-up to #121272, #121361, #121667
This should be the last one 🤞 Sorry!
2024-03-10 10:58:20 +01:00
Matthias Krüger
4faf535a55
Rollup merge of #122244 - tvallotton:local_waker_leak_fix, r=Nilstrieb
fix: LocalWaker memory leak and some stability attributes

fixes #122180.
2024-03-10 10:58:18 +01:00
Matthias Krüger
1b44889ec2
Rollup merge of #112136 - clarfonthey:ffi-c_str, r=cuviper
Add std::ffi::c_str module

ACP: rust-lang/libs-team#134

`std::ffi` docs before change:
![Structs: VaList, VaListImpl, CStr, CString, FromBytesWithNulError, FromVecWithNulError, IntoStringError, NulError, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/b2cf3534-30f9-4ef0-a655-bacdc3a19e17)

`std::ffi` docs after change:
![Re-exports: self::c_str::{FromBytesWithNulError, FromBytesUntilNulError, FromVecWithNulError, NulError, IntoStringError} ; Modules: c_str ; Structs: VaList, VaListImpl, CStr, CString, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/23aa6964-da7a-4942-bbf7-42bde2146f9e)

(note: I'm omitting the `c_int`, etc. stuff from the screenshots since it's the same in both. this doesn't just delete those types)
2024-03-10 10:58:14 +01:00
Ralf Jung
c06f801ef6 BorrowedCursor docs clarification 2024-03-10 09:48:56 +01:00
Peter Jaszkowiak
83590ac069 fix legacy numeric constant diag items
- missed syms for usize/isize
- missed diag items on unsigned integers
2024-03-09 23:33:27 -07:00
bors
768408af12 Auto merge of #121662 - saethlin:precondition-unification, r=RalfJung
Distinguish between library and lang UB in assert_unsafe_precondition

As described in https://github.com/rust-lang/rust/pull/121583#issuecomment-1963168186, `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do).

`debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation.

Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR.

r? RalfJung
2024-03-10 01:23:54 +00:00
Guillaume Boisseau
cbd59d0f62
Rollup merge of #121280 - ajwock:maybeuninit_fill, r=Amanieu
Implement MaybeUninit::fill{,_with,_from}

ACP: rust-lang/libs-team#156
2024-03-09 21:40:07 +01:00
Ben Kimock
2a1f97f77f Explain why we don't use intrinsics::is_nonoverlapping 2024-03-09 13:36:36 -05:00
Tomás Vallotton
092a1ab001 fix: remove memory leak due to missing drop implementation for local waker. Also, fix some
of the stability attributes of LocalWaker's methods.
2024-03-09 14:38:58 -03:00
Ben Kimock
af49c4df0a NonZero::from_mut_unchecked is library UB 2024-03-09 12:27:11 -05:00
Ben Kimock
50d0bea153 Improve docs 2024-03-09 10:49:26 -05:00
Matthias Krüger
b14e8054af
Rollup merge of #122233 - RalfJung:custom-alloc-box, r=oli-obk
miri: do not apply aliasing restrictions to Box with custom allocator

This is the Miri side of https://github.com/rust-lang/rust/pull/122018. The "intrinsics with body" made this much more pleasant. :)

Fixes https://github.com/rust-lang/miri/issues/3341.
r? `@oli-obk`
2024-03-09 16:21:20 +01:00
Matthias Krüger
2bb4b9901f
Rollup merge of #122232 - RalfJung:misc, r=jhpratt
library/core: fix a comment, and a cfg(miri) warning

Just two things I noticed while working on another PR.
2024-03-09 16:21:20 +01:00
Matthias Krüger
a1f6191e0e
Rollup merge of #121358 - GnomedDev:lower-align-typeid, r=Mark-Simulacrum
Reduce alignment of TypeId to u64 alignment

Closes #115620
2024-03-09 16:21:14 +01:00
Ralf Jung
e632e3f9a5 miri: do not apply aliasing restrictions to Box with custom allocator 2024-03-09 13:08:55 +01:00
Ralf Jung
1082c36a4c fn is_align_to: move some comments closer to the cast they refer to 2024-03-09 11:54:27 +01:00
Ralf Jung
6aff1ca68c fix warning when building libcore for Miri 2024-03-09 11:11:10 +01:00
Ben Kimock
5a93a59fd5 Distinguish between library and lang UB in assert_unsafe_precondition 2024-03-08 18:53:58 -05:00
Michael Goulet
c63f3feb0f Stabilize associated type bounds 2024-03-08 20:56:25 +00:00
Matthias Krüger
948d32d94f
Rollup merge of #121201 - RalfJung:align_offset_contract, r=cuviper
align_offset, align_to: no longer allow implementations to spuriously fail to align

For a long time, we have allowed `align_offset` to fail to compute a properly aligned offset, and `align_to` to return a smaller-than-maximal "middle slice". This was done to cover the implementation of `align_offset` in const-eval and Miri. See https://github.com/rust-lang/rust/issues/62420 for more background. For about the same amount of time, this has caused confusion and surprise, where people didn't realize they have to write their code to be defensive against `align_offset` failures.

Another way to put this is: the specification is effectively non-deterministic, and non-determinism is hard to test for -- in particular if the implementation everyone uses to test always produces the same reliable result, and nobody expects it to be non-deterministic to begin with.

With https://github.com/rust-lang/rust/pull/117840, Miri has stopped making use of this liberty in the spec; it now always behaves like rustc. That only leaves const-eval as potential motivation for this behavior. I do not think this is sufficient motivation. Currently, none of the relevant functions are stably const: `align_offset` is unstably const, `align_to` is not const at all. I propose that if we ever want to make these const-stable, we just accept the fact that they can behave differently at compile-time vs at run-time. This is not the end of the world, and it seems to be much less surprising to programmers than unexpected non-determinism. (Related: https://github.com/rust-lang/rfcs/pull/3352.)

`@thomcc` has repeatedly made it clear that they strongly dislike the non-determinism in align_offset, so I expect they will support this. `@oli-obk,` what do you think? Also, whom else should we involve? The primary team responsible is clearly libs-api, so I will nominate this for them. However, allowing const-evaluated code to behave different from run-time code is t-lang territory. The thing is, this is not stabilizing anything t-lang-worthy immediately, but it still does make a decision we will be bound to: if we accept this change, then
- either `align_offset`/`align_to` can never be called in const fn,
- or we allow compile-time behavior to differ from run-time behavior.

So I will nominate for t-lang as well, with the question being: are you okay with accepting either of these outcomes (without committing to which one, just accepting that it has to be one of them)? This closes the door to "have `align_offset` and `align_to` at compile-time and also always have compile-time behavior match run-time behavior".

Closes https://github.com/rust-lang/rust/issues/62420
2024-03-08 21:01:59 +01:00
Noa
c0e913fdd7
Document overrides of clone_from()
Specifically, when an override doesn't just forward to an inner type,
document the behavior and that it's preferred over simply assigning
a clone of source. Also, change instances where the second parameter is
"other" to "source".
2024-03-08 12:27:24 -06:00
Ralf Jung
507583a40c align_offset, align_to: no longer allow implementations to spuriously fail to align 2024-03-08 18:28:38 +01:00