about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-05-28Add custom mir support for `PtrMetadata`Scott McMurray-0/+4
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-4/+44
2024-05-28Rollup merge of #125637 - nnethercote:rustfmt-fixes, r=GuillaumeGomezMatthias Krüger-6/+2
rustfmt fixes The `rmake.rs` entries in `rustfmt.toml` are causing major problems for `x fmt`. This PR removes them and does some minor related cleanups. r? ``@GuillaumeGomez``
2024-05-28Don't format `tests/run-make/*/rmake.rs`.Nicholas Nethercote-6/+2
It's reasonable to want to, but in the current implementation this causes multiple problems. - All the `rmake.rs` files are formatted every time even when they haven't changed. This is because they get whitelisted unconditionally in the `OverrideBuilder`, before the changed files get added. - The way `OverrideBuilder` works, if any files gets whitelisted then no unmentioned files will get traversed. This is surprising, and means that the `rmake.rs` entries broke the use of explicit paths to `x fmt`, and also broke `GITHUB_ACTIONS=true git check --fmt`. The commit removes the `rmake.rs` entries, fixes the formatting of a couple of files that were misformatted (not previously caught due to the `GITHUB_ACTIONS` breakage), and bans `!`-prefixed entries in `rustfmt.toml` because they cause all these problems.
2024-05-28Rollup merge of #125647 - tspiteri:track-lazy_cell_consume, r=workingjubileeJubilee-1/+1
update tracking issue for lazy_cell_consume <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->
2024-05-28Rollup merge of #125551 - clarfonthey:ip-bits, r=jhprattJubilee-19/+10
Stabilise `IpvNAddr::{BITS, to_bits, from_bits}` (`ip_bits`) This completed FCP in #113744. (Closes #113744.) Stabilises the following APIs: ```rust impl Ipv4Addr { pub const BITS: u32 = 32; pub const fn from_bits(bits: u32) -> Ipv4Addr; pub const fn to_bits(self) -> u32; } impl Ipv6Addr { pub const BITS: u32 = 128; pub const fn from_bits(bits: u128) -> Ipv4Addr; pub const fn to_bits(self) -> u128; } ```
2024-05-28update tracking issue for lazy_cell_consumeTrevor Spiteri-1/+1
2024-05-28Auto merge of #125609 - diondokter:opt-size-char-count, r=thomccbors-1/+1
Always use the general case char count with `optimize_for_size` The faster algo is really expensive, over a kilobyte if the full algo is present in a binary. With this PR the general case algo is picked always instead of only for small strings. In a test of mine this change makes the total binary go from 3116 bytes to 2032 bytes in opt-level 3 and from 1652 bytes to 1428 bytes in opt-level z. I've seen it much worse in real application, so the savings (especially on 'z') will be higher in many cases. This is the second pr of this kind after #125606
2024-05-27Rollup merge of #124870 - Lokathor:update-result-docs, r=dtolnayGuillaume Gomez-0/+24
Update Result docs to the new guarantees The `Option` docs already explain the guarantees given in [RFC 3391](https://github.com/rust-lang/rfcs/blob/master/text/3391-result_ffi_guarantees.md), so all that we need is a paragraph saying that some `Result` type combinations will also qualify. Part of https://github.com/rust-lang/rust/issues/110503
2024-05-27Always use the general case char countDion Dokter-1/+1
2024-05-27Size optimize int formattingDion Dokter-0/+33
2024-05-26Rollup merge of #125559 - scottmcm:simplify-shift-ubcheck, r=workingjubileeJubilee-8/+4
Simplify the `unchecked_sh[lr]` ub-checks a bit It can use the constant in the check, rather than passing it as a parameter.
2024-05-26Rollup merge of #125571 - tesuji:dummy-pi, r=NilstriebMatthias Krüger-4/+4
f32: use constants instead of reassigning a dummy value as PI
2024-05-26Rollup merge of #125561 - Cyborus04:stabilize-slice-flatten, r=scottmcmMatthias Krüger-7/+3
Stabilize `slice_flatten`
2024-05-26f32: use constants instead of reassigning a dummy value as PILzu Tao-4/+4
2024-05-26Stabilize `slice_flatten`Cyborus-7/+3
2024-05-26Auto merge of #125518 - saethlin:check-arguments-new-in-const, r=joboetbors-11/+7
Move the checks for Arguments constructors to inline const Thanks `@Skgland` for pointing out this opportunity: https://github.com/rust-lang/rust/pull/117804#discussion_r1612964362
2024-05-25It seems that anchor names are implicitly all lowercaseLokathor-1/+1
2024-05-25Simplify the `unchecked_sh[lr]` ub-checks a bitScott McMurray-8/+4
2024-05-25Fix URL target, it's in the module not the type.Lokathor-1/+1
2024-05-25github showed that weird.Lokathor-1/+1
2024-05-25correct for copy paste errors when fixing wrapping.Lokathor-6/+6
2024-05-25Resolve https://github.com/rust-lang/rust/pull/124870#issuecomment-2128824959Lokathor-0/+3
2024-05-25revert to the inconsistent paragraph wrapping.Lokathor-52/+55
2024-05-25Rollup merge of #124667 - newpavlov:stabilize_div_duration, r=jhprattMatthias Krüger-7/+8
Stabilize `div_duration` Closes #63139
2024-05-25Rollup merge of #122986 - taiki-e:aix-c-char, r=Mark-SimulacrumMatthias Krüger-1/+2
Fix c_char on AIX Closes https://github.com/rust-lang/rust/issues/122985
2024-05-25Rollup merge of #121377 - pitaj:lazy_cell_fn_pointer, r=dtolnayMatthias Krüger-15/+8
Stabilize `LazyCell` and `LazyLock` Closes #109736 This stabilizes the [`LazyLock`](https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html) and [`LazyCell`](https://doc.rust-lang.org/stable/std/cell/struct.LazyCell.html) types: ```rust static HASHMAP: LazyLock<HashMap<i32, String>> = LazyLock::new(|| { println!("initializing"); let mut m = HashMap::new(); m.insert(13, "Spica".to_string()); m.insert(74, "Hoyten".to_string()); m }); let lazy: LazyCell<i32> = LazyCell::new(|| { println!("initializing"); 92 }); ``` r? libs-api
2024-05-25Stabilise ip_bits featureltdk-19/+10
2024-05-25Auto merge of #121571 - clarfonthey:unchecked-math-preconditions, r=saethlinbors-45/+161
Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methods (Old PR is haunted, opening a new one. See #117494 for previous discussion.) This ensures that these preconditions are actually checked in debug mode, and hopefully should let people know if they messed up. I've also replaced the calls (I could find) in the code that use these intrinsics directly with those that use these methods, so that the asserts actually apply. More discussions on people misusing these methods in the tracking issue: https://github.com/rust-lang/rust/issues/85122.
2024-05-25Rollup merge of #125478 - Urgau:check-cfg-config-bump-stage0, r=Mark-SimulacrumMatthias Krüger-1/+0
Bump bootstrap compiler to the latest beta compiler This PR updates the bootstrap compiler, aka stage0 to the latest beta version, since it contains rust-lang/cargo#13925. It removes those unconditional Cargo warnings: ``` warning: [...]/rust/library/core/Cargo.toml: unused manifest key: lints.rust.unexpected_cfgs.check-cfg warning: [...]/rust/library/std/Cargo.toml: unused manifest key: lints.rust.unexpected_cfgs.check-cfg warning: [...]/rust/library/alloc/Cargo.toml: unused manifest key: lints.rust.unexpected_cfgs.check-cfg ``` for all contributors/users of this repository (including CI). I don't know if that's something we do, or if it's even advisable, feel free to close. r? `@Mark-Simulacrum`
2024-05-24Move the checks for Arguments constructors to inline constBen Kimock-11/+7
2024-05-24Rollup merge of #125497 - meesfrensel:patch-1, r=calebzulawskiMatthias Krüger-4/+4
Fix some SIMD intrinsics documentation Spotted some mistakes in the docs of some SIMD intrinsics.
2024-05-24Change pedantically incorrect OnceCell/OnceLock wordingMahmoud Al-Qudsi-2/+2
While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby technically allowing it to be written to again. Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole categorically prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract). To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference.
2024-05-24Rollup merge of #125455 - blyxyas:opt-clamp, r=joboetMatthias Krüger-0/+1
Make `clamp` inline Context: rust-lang/rust-clippy#12826 This results in slightly more optimized assembly. (And most important, it's now less than lines than just manually clamping a value)
2024-05-24Fix some SIMD intrinsics documentationMees Frensel-4/+4
2024-05-24Auto merge of #121150 - Swatinem:debug-ascii-str, r=joboetbors-20/+43
Add a fast-path to `Debug` ASCII `&str` Instead of going through the `EscapeDebug` machinery, we can just skip over ASCII chars that don’t need any escaping. --- This is an alternative / a companion to https://github.com/rust-lang/rust/pull/121138. The other PR is adding the fast path deep within `EscapeDebug`, whereas this skips as early as possible.
2024-05-24Auto merge of #125479 - scottmcm:validate-vtable-projections, r=Nilstriebbors-8/+19
Validate the special layout restriction on `DynMetadata` If you look at <https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/std/ptr/struct.DynMetadata.html>, you'd think that `DynMetadata` is a struct with fields. But it's actually not, because the lang item is special-cased in rustc_middle layout: https://github.com/rust-lang/rust/blob/7601adcc764d42c9f2984082b49948af652df986/compiler/rustc_middle/src/ty/layout.rs#L861-L864 That explains the very confusing codegen ICEs I was getting in https://github.com/rust-lang/rust/pull/124251#issuecomment-2128543265 > Tried to extract_field 0 from primitive OperandRef(Immediate((ptr: %5 = load ptr, ptr %4, align 8, !nonnull !3, !align !5, !noundef !3)) @ TyAndLayout { ty: DynMetadata<dyn Callsite>, layout: Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Scalar(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), fields: Primitive, largest_niche: Some(Niche { offset: Size(0 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes) } }) because there was a `Field` projection despite the layout clearly saying it's [`Primitive`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/enum.FieldsShape.html#variant.Primitive). Thus this PR updates the MIR validator to check for such a projection, and changes `libcore` to not ever emit any projections into `DynMetadata`, just to transmute the whole thing when it wants a pointer.
2024-05-23Validate the special layout restriction on DynMetadataScott McMurray-8/+19
2024-05-24Remove now outdated comment since we bumped stage0Urgau-1/+0
2024-05-23Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methodsltdk-45/+161
2024-05-23Rollup merge of #125452 - Urgau:check-cfg-libraries-cleanup, r=bjorn3Guillaume Gomez-1/+3
Cleanup check-cfg handling in core and std Follow-up to https://github.com/rust-lang/rust/pull/125296 where we: - expect any feature cfg in std, due to `#[path]` imports - move some check-cfg args inside the `build.rs` as per Cargo recommendation - and replace the fake Cargo feature `"restricted-std"` by the custom cfg `restricted_std` Fixes https://github.com/rust-lang/rust/pull/125296#issuecomment-2127009301 r? `@bjorn3` (maybe, feel free to re-roll)
2024-05-23Rollup merge of #125362 - joboet:tait_hack, r=NilstriebGuillaume Gomez-117/+44
Actually use TAIT instead of emulating it `core`'s `impl_fn_for_zst` macro is just a hacky way of emulating TAIT. TAIT has become stable enough to be used [in other places](https://github.com/rust-lang/rust/blob/e8fbd991287f637f95016a71ddc13438415bbe59/library/std/src/backtrace.rs#L431) inside the standard library, so let's use it in `core` as well.
2024-05-23Process a single not-ASCII-printable `char` per iterationArpad Borsos-8/+5
This avoids having to collect a non-ASCII-printable run before processing it.
2024-05-23Auto merge of #117804 - saethlin:no-recursive-panics, r=joboetbors-2/+5
Panic directly in Arguments::new* instead of recursing This has been bothering me because it looks very silly in MIR.
2024-05-23Make clamp inlineblyxyas-0/+1
2024-05-23panic_nounwind in Arguments::new* instead of recursingBen Kimock-2/+5
2024-05-23Expect any feature cfg in core and std cratesUrgau-1/+3
2024-05-23core: use `Copy` in TAIT to fix clippy lintjoboet-10/+10
2024-05-23Rollup merge of #125392 - workingjubilee:unwind-a-problem-in-context, r=AmanieuMatthias Krüger-4/+7
Wrap Context.ext in AssertUnwindSafe Fixes https://github.com/rust-lang/rust/issues/125193 Alternative to https://github.com/rust-lang/rust/pull/125377 Relevant to https://github.com/rust-lang/rust/issues/123392 I believe this approach is justifiable due to the fact that this function is unstable API and we have been considering trying to dispose of the notion of "unwind safety". Making a more long-term decision should be considered carefully as part of stabilizing `fn ext`, if ever. r? `@Amanieu`
2024-05-23Rollup merge of #125156 - zachs18:for_loops_over_fallibles_behind_refs, ↵Matthias Krüger-0/+1
r=Nilstrieb Expand `for_loops_over_fallibles` lint to lint on fallibles behind references. Extends the scope of the (warn-by-default) lint `for_loops_over_fallibles` from just `for _ in x` where `x: Option<_>/Result<_, _>` to also cover `x: &(mut) Option<_>/Result<_>` ```rs fn main() { // Current lints for _ in Some(42) {} for _ in Ok::<_, i32>(42) {} // New lints for _ in &Some(42) {} for _ in &mut Some(42) {} for _ in &Ok::<_, i32>(42) {} for _ in &mut Ok::<_, i32>(42) {} // Should not lint for _ in Some(42).into_iter() {} for _ in Some(42).iter() {} for _ in Some(42).iter_mut() {} for _ in Ok::<_, i32>(42).into_iter() {} for _ in Ok::<_, i32>(42).iter() {} for _ in Ok::<_, i32>(42).iter_mut() {} } ``` <details><summary><code>cargo build</code> diff</summary> ```diff diff --git a/old.out b/new.out index 84215aa..ca195a7 100644 --- a/old.out +++ b/new.out `@@` -1,33 +1,93 `@@` warning: for loop over an `Option`. This is more readably written as an `if let` statement --> src/main.rs:3:14 | 3 | for _ in Some(42) {} | ^^^^^^^^ | = note: `#[warn(for_loops_over_fallibles)]` on by default help: to check pattern in a loop use `while let` | 3 | while let Some(_) = Some(42) {} | ~~~~~~~~~~~~~~~ ~~~ help: consider using `if let` to clear intent | 3 | if let Some(_) = Some(42) {} | ~~~~~~~~~~~~ ~~~ warning: for loop over a `Result`. This is more readably written as an `if let` statement --> src/main.rs:4:14 | 4 | for _ in Ok::<_, i32>(42) {} | ^^^^^^^^^^^^^^^^ | help: to check pattern in a loop use `while let` | 4 | while let Ok(_) = Ok::<_, i32>(42) {} | ~~~~~~~~~~~~~ ~~~ help: consider using `if let` to clear intent | 4 | if let Ok(_) = Ok::<_, i32>(42) {} | ~~~~~~~~~~ ~~~ -warning: `for-loops-over-fallibles` (bin "for-loops-over-fallibles") generated 2 warnings - Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s +warning: for loop over a `&Option`. This is more readably written as an `if let` statement + --> src/main.rs:7:14 + | +7 | for _ in &Some(42) {} + | ^^^^^^^^^ + | +help: to check pattern in a loop use `while let` + | +7 | while let Some(_) = &Some(42) {} + | ~~~~~~~~~~~~~~~ ~~~ +help: consider using `if let` to clear intent + | +7 | if let Some(_) = &Some(42) {} + | ~~~~~~~~~~~~ ~~~ + +warning: for loop over a `&mut Option`. This is more readably written as an `if let` statement + --> src/main.rs:8:14 + | +8 | for _ in &mut Some(42) {} + | ^^^^^^^^^^^^^ + | +help: to check pattern in a loop use `while let` + | +8 | while let Some(_) = &mut Some(42) {} + | ~~~~~~~~~~~~~~~ ~~~ +help: consider using `if let` to clear intent + | +8 | if let Some(_) = &mut Some(42) {} + | ~~~~~~~~~~~~ ~~~ + +warning: for loop over a `&Result`. This is more readably written as an `if let` statement + --> src/main.rs:9:14 + | +9 | for _ in &Ok::<_, i32>(42) {} + | ^^^^^^^^^^^^^^^^^ + | +help: to check pattern in a loop use `while let` + | +9 | while let Ok(_) = &Ok::<_, i32>(42) {} + | ~~~~~~~~~~~~~ ~~~ +help: consider using `if let` to clear intent + | +9 | if let Ok(_) = &Ok::<_, i32>(42) {} + | ~~~~~~~~~~ ~~~ + +warning: for loop over a `&mut Result`. This is more readably written as an `if let` statement + --> src/main.rs:10:14 + | +10 | for _ in &mut Ok::<_, i32>(42) {} + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: to check pattern in a loop use `while let` + | +10 | while let Ok(_) = &mut Ok::<_, i32>(42) {} + | ~~~~~~~~~~~~~ ~~~ +help: consider using `if let` to clear intent + | +10 | if let Ok(_) = &mut Ok::<_, i32>(42) {} + | ~~~~~~~~~~ ~~~ + +warning: `for-loops-over-fallibles` (bin "for-loops-over-fallibles") generated 6 warnings + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s ``` </details> ----- Question: * ~~Currently, the article `an` is used for `&Option`, and `&mut Option` in the lint diagnostic, since that's what `Option` uses. Is this okay or should it be changed? (likewise, `a` is used for `&Result` and `&mut Result`)~~ The article `a` is used for `&Option`, `&mut Option`, `&Result`, `&mut Result` and (as before) `Result`. Only `Option` uses `an` (as before). `@rustbot` label +A-lint