summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-02-13Revert unsound libcore changes of #119911Oli Scherer-385/+149
(cherry picked from commit 6ac035df442a27cf9e99ab4ec25bb6147a700902)
2024-02-03Bump version placeholdersMark Rousskov-34/+34
2024-01-30Rollup merge of #120295 - reitermarkus:remove-ffi-nonzero, r=dtolnayGuillaume Gomez-50/+14
Remove `raw_os_nonzero` feature. This feature is superseded by a generic `NonZero` type: https://github.com/rust-lang/rust/issues/120257 Closes https://github.com/rust-lang/rust/issues/82363.
2024-01-30Rollup merge of #120424 - RalfJung:raw-ptr-meta, r=NilstriebGuillaume Gomez-14/+14
raw pointer metadata API: data address -> data pointer A pointer consists of [more than just an address](https://github.com/rust-lang/rfcs/pull/3559), so let's not equate "pointer" and "address" in these docs.
2024-01-29Remove `raw_os_nonzero` feature.Markus Reiter-50/+14
2024-01-29Rollup merge of #116677 - joshlf:patch-11, r=RalfJungDylan DPC-0/+24
References refer to allocated objects Partially addresses https://github.com/rust-lang/unsafe-code-guidelines/issues/465
2024-01-29raw pointer metadata API: data address -> data pointerRalf Jung-14/+14
2024-01-27Update primitive_docs.rsJoshua Liebow-Feeser-7/+12
2024-01-27Switch `NonZero` alias direction.Markus Reiter-19/+41
2024-01-27Auto merge of #120417 - matthiaskrgr:rollup-5rszkmd, r=matthiaskrgrbors-1/+0
Rollup of 6 pull requests Successful merges: - #118182 (Properly recover from trailing attr in body) - #119641 (Remove feature not required by `Ipv6Addr::to_cononical` doctest) - #119957 (fix: correct suggestion arg for impl trait) - #120386 (ScopeTree: remove destruction_scopes as unused) - #120398 (Improve handling of numbers in `IntoDiagnosticArg`) - #120399 (Remove myself from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-27Rollup merge of #119641 - eopb:std-unused-ip-feature, r=ChrisDentonMatthias Krüger-1/+0
Remove feature not required by `Ipv6Addr::to_cononical` doctest The feature does not seem to be required by this doctest.
2024-01-27Auto merge of #111379 - nyurik:intersperse-speed-up, r=cuviperbors-49/+98
Boost iterator intersperse(_with) performance I did some benchmark digging into the `intersperse` and `intersperse_with` code as part of [this discussion](https://internals.rust-lang.org/t/add-iterate-with-separators-iterator-function/18781/13), and as a result I optimized them a bit, without relying on the peekable iterator. See also [full benchmark repo](https://github.com/nyurik/intersperse_perf) Benchmarks show near 2x performance improvements with the simple `sum` [benchmarks](https://gist.github.com/nyurik/68b6c9b3d90f0d14746d4186bf8fa1e2): ![image](https://user-images.githubusercontent.com/1641515/237005195-16aebef4-9eed-4514-8b7c-da1d1f5bd9e0.png)
2024-01-26Rollup merge of #120366 - RalfJung:is_val_statically_known, r=cuviperMatthias Krüger-1/+1
mark a doctest with UB as no_run https://github.com/rust-lang/rust/pull/119911 added a doctest with UB. That one shouldn't be run, or else Miri will complain.
2024-01-26Rollup merge of #120311 - mina86:h, r=cuviperMatthias Krüger-0/+16
core: add `From<core::ascii::Char>` implementations Introduce `From<core::ascii::Char>` implementations for all unsigned numeric types and `char`. This matches the API of `char` type. Issue: https://github.com/rust-lang/rust/issues/110998
2024-01-26Rollup merge of #119562 - LegionMammal978:rename-pin-pointer, r=Amanieu,dtolnayMatthias Krüger-20/+26
Rename `pointer` field on `Pin` A few days ago, I was helping another user create a self-referential type using `PhantomPinned`. However, I noticed an odd behavior when I tried to access one of the type's fields via `Pin`'s `Deref` impl: ```rust use std::{marker::PhantomPinned, ptr}; struct Pinned { data: i32, pointer: *const i32, _pin: PhantomPinned, } fn main() { let mut b = Box::pin(Pinned { data: 42, pointer: ptr::null(), _pin: PhantomPinned, }); { let pinned = unsafe { b.as_mut().get_unchecked_mut() }; pinned.pointer = &pinned.data; } println!("{}", unsafe { *b.pointer }); } ``` ```rust error[E0658]: use of unstable library feature 'unsafe_pin_internals' --> <source>:19:30 | 19 | println!("{}", unsafe { *b.pointer }); | ^^^^^^^^^ error[E0277]: `Pinned` doesn't implement `std::fmt::Display` --> <source>:19:20 | 19 | println!("{}", unsafe { *b.pointer }); | ^^^^^^^^^^^^^^^^^^^^^ `Pinned` cannot be formatted with the default formatter | = help: the trait `std::fmt::Display` is not implemented for `Pinned` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) ``` Since the user named their field `pointer`, it conflicts with the `pointer` field on `Pin`, which is public but unstable since Rust 1.60.0 with #93176. On versions from 1.33.0 to 1.59.0, where the field on `Pin` is private, this program compiles and prints `42` as expected. To avoid this confusing behavior, this PR renames `pointer` to `__pointer`, so that it's less likely to conflict with a `pointer` field on the underlying type, as accessed through the `Deref` impl. This is technically a breaking change for anyone who names their field `__pointer` on the inner type; if this is undesirable, it could be renamed to something more longwinded. It's also a nightly breaking change for any external users of `unsafe_pin_internals`.
2024-01-26Rollup merge of #103522 - Dylan-DPC:76118/array-methods-stab, r=dtolnayMatthias Krüger-7/+2
stabilise array methods Closes #76118 Stabilises the remaining array methods FCP is yet to be carried out for this There wasn't a clear consensus on the naming, but all the other alternatives had some flaws as discussed in the tracking issue and there was a silence on this issue for a year
2024-01-26Rollup merge of #117678 - niklasf:stabilize-slice_group_by, r=dtolnayMatthias Krüger-58/+50
Stabilize `slice_group_by` Renamed "group by" to "chunk by" a per #80552. Newly stable items: * `core::slice::ChunkBy` * `core::slice::ChunkByMut` * `[T]::chunk` * `[T]::chunk_by` Closes #80552.
2024-01-26mark a doctest with UB as no_runRalf Jung-1/+1
2024-01-26Rollup merge of #119466 - Sky9x:str_from_raw_parts, r=dtolnayMatthias Krüger-1/+42
Initial implementation of `str::from_raw_parts[_mut]` ACP (accepted): rust-lang/libs-team#167 Tracking issue: #119206 Thanks to ``@Kixiron`` for previous work on this (#107207) ``@rustbot`` label +T-libs-api -T-libs r? ``@thomcc`` Closes #107207.
2024-01-26Rollup merge of #107464 - WaffleLapkin:all_that_remains_of_lines, r=dtolnayMatthias Krüger-0/+25
Add `str::Lines::remainder` Based on https://github.com/rust-lang/rust/pull/98453. This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](https://github.com/rust-lang/rust/issues/77998).
2024-01-25use checked_add for upper boundYuri Astrakhan-2/+2
2024-01-25Update library/core/src/iter/adapters/intersperse.rsYuri Astrakhan-2/+2
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-01-26Auto merge of #116167 - RalfJung:structural-eq, r=lcnrbors-5/+23
remove StructuralEq trait The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more. One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good. Fixes https://github.com/rust-lang/rust/issues/115881
2024-01-25fmtYuri Astrakhan-1/+8
2024-01-25Postpone .next() call until iterationYuri Astrakhan-29/+49
2024-01-25Boost intersperse(_with) performanceYuri Astrakhan-52/+74
I did some benchmark digging into the `intersperse` and `intersperse_with` code as part of the https://internals.rust-lang.org/t/add-iterate-with-separators-iterator-function/18781/13 discussion, and as a result I optimized them a bit, without relying on the peekable iterator.
2024-01-25Rollup merge of #120338 - steffahn:provenance_links, r=NilstriebMatthias Krüger-8/+8
Fix links to [strict|exposed] provenance sections of `[std|core]::ptr`
2024-01-25core: add `From<core::ascii::char>` implementationsMichal Nazarewicz-0/+16
Introduce `From<core::ascii::char>` implementations for all unsigned numeric types and `char`. This matches the API of `char` type. Issue: https://github.com/rust-lang/rust/issues/110998
2024-01-25Update primitive_docs.rsJoshua Liebow-Feeser-0/+4
2024-01-25Fix links to [strict|exposed] provenance sections of `[std|core]::ptr`Frank Steffahn-8/+8
2024-01-25Rollup merge of #119305 - compiler-errors:async-fn-traits, r=oli-obkMatthias Krüger-0/+112
Add `AsyncFn` family of traits I'm proposing to add a new family of `async`hronous `Fn`-like traits to the standard library for experimentation purposes. ## Why do we need new traits? On the user side, it is useful to be able to express `AsyncFn` trait bounds natively via the parenthesized sugar syntax, i.e. `x: impl AsyncFn(&str) -> String` when experimenting with async-closure code. This also does not preclude `AsyncFn` becoming something else like a trait alias if a more fundamental desugaring (which can take many[^1] different[^2] forms) comes around. I think we should be able to play around with `AsyncFn` well before that, though. I'm also not proposing stabilization of these trait names any time soon (we may even want to instead express them via new syntax, like `async Fn() -> ..`), but I also don't think we need to introduce an obtuse bikeshedding name, since `AsyncFn` just makes sense. ## The lending problem: why not add a more fundamental primitive of `LendingFn`/`LendingFnMut`? Firstly, for `async` closures to be as flexible as possible, they must be allowed to return futures which borrow from the async closure's captures. This can be done by introducing `LendingFn`/`LendingFnMut` traits, or (equivalently) by adding a new generic associated type to `FnMut` which allows the return type to capture lifetimes from the `&mut self` argument of the trait. This was proposed in one of [Niko's blog posts](https://smallcultfollowing.com/babysteps/blog/2023/05/09/giving-lending-and-async-closures/). Upon further experimentation, for the purposes of closure type- and borrow-checking, I've come to the conclusion that it's significantly harder to teach the compiler how to handle *general* lending closures which may borrow from their captures. This is, because unlike `Fn`/`FnMut`, the `LendingFn`/`LendingFnMut` traits don't form a simple "inheritance" hierarchy whose top trait is `FnOnce`. ```mermaid flowchart LR Fn FnMut FnOnce LendingFn LendingFnMut Fn -- isa --> FnMut FnMut -- isa --> FnOnce LendingFn -- isa --> LendingFnMut Fn -- isa --> LendingFn FnMut -- isa --> LendingFnMut ``` For example: ``` fn main() { let s = String::from("hello, world"); let f = move || &s; let x = f(); // This borrows `f` for some lifetime `'1` and returns `&'1 String`. ``` That trait hierarchy means that in general for "lending" closures, like `f` above, there's not really a meaningful return type for `<typeof(f) as FnOnce>::Output` -- it can't return `&'static str`, for example. ### Special-casing this problem: By splitting out these traits manually, and making sure that each trait has its own associated future type, we side-step the issue of having to answer the questions of a general `LendingFn`/`LendingFnMut` implementation, since the compiler knows how to generate built-in implementations for first-class constructs like async closures, including the required future types for the (by-move) `AsyncFnOnce` and (by-ref) `AsyncFnMut`/`AsyncFn` trait implementations. [^1]: For example, with trait transformers, we may eventually be able to write: `trait AsyncFn = async Fn;` [^2]: For example, via the introduction of a more fundamental "`LendingFn`" trait, plus a [special desugaring with augmented trait aliases](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Lending.20closures.20and.20Fn*.28.29.20-.3E.20impl.20Trait/near/408471480).
2024-01-25Auto merge of #119911 - NCGThompson:is-statically-known, r=oli-obkbors-149/+445
Replacement of #114390: Add new intrinsic `is_var_statically_known` and optimize pow for powers of two This adds a new intrinsic `is_val_statically_known` that lowers to [``@llvm.is.constant.*`](https://llvm.org/docs/LangRef.html#llvm-is-constant-intrinsic).` It also applies the intrinsic in the int_pow methods to recognize and optimize the idiom `2isize.pow(x)`. See #114390 for more discussion. While I have extended the scope of the power of two optimization from #114390, I haven't added any new uses for the intrinsic. That can be done in later pull requests. Note: When testing or using the library, be sure to use `--stage 1` or higher. Otherwise, the intrinsic will be a noop and the doctests will be skipped. If you are trying out edits, you may be interested in [`--keep-stage 0`](https://rustc-dev-guide.rust-lang.org/building/suggested.html#faster-builds-with---keep-stage). Fixes #47234 Resolves #114390 `@Centri3`
2024-01-24Rollup merge of #118326 - WaffleLapkin:nz_count_ones, r=scottmcmLeón Orell Valerian Liehr-0/+37
Add `NonZero*::count_ones` This PR adds the following APIs to the standard library: ```rust impl NonZero* { pub const fn count_ones(self) -> NonZeroU32; } ``` This is potentially interesting, given that `count_ones` can't ever return 0. r? libs-api
2024-01-24remove StructuralEq traitRalf Jung-5/+23
2024-01-24Add `NonZero*::count_ones`Maybe Waffle-0/+37
2024-01-23Auto merge of #120283 - fmease:rollup-rk0f6r5, r=fmeasebors-10/+105
Rollup of 9 pull requests Successful merges: - #112806 (Small code improvements in `collect_intra_doc_links.rs`) - #119766 (Split tait and impl trait in assoc items logic) - #120139 (Do not normalize closure signature when building `FnOnce` shim) - #120160 (Manually implement derived `NonZero` traits.) - #120171 (Fix assume and assert in jump threading) - #120183 (Add `#[coverage(off)]` to closures introduced by `#[test]` and `#[bench]`) - #120195 (add several resolution test cases) - #120259 (Split Diagnostics for Uncommon Codepoints: Add List to Display Characters Involved) - #120261 (Provide structured suggestion to use trait objects in some cases of `if` arm type divergence) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-23Rollup merge of #120183 - Zalathar:test-closure, r=compiler-errorsLeón Orell Valerian Liehr-2/+2
Add `#[coverage(off)]` to closures introduced by `#[test]` and `#[bench]` These closures are an internal implementation detail of the `#[test]` and `#[bench]` attribute macros, so from a user perspective there is no reason to instrument them for coverage. Skipping them makes coverage reports slightly cleaner, and will also allow other changes to span processing during coverage instrumentation, without having to worry about how they affect the `#[test]` macro. The `#[coverage(off)]` attribute has no effect when `-Cinstrument-coverage` is not used. Fixes #120046. --- Note that this PR has no effect on the user-written function that has the `#[test]` attribute attached to it. That function will still be instrumented as normal.
2024-01-23Rollup merge of #120171 - cjgillot:jump-threading-assume-assert, r=tmiaskoLeón Orell Valerian Liehr-0/+2
Fix assume and assert in jump threading r? ``@tmiasko``
2024-01-23Rollup merge of #120160 - reitermarkus:nonzero-traits, r=dtolnayLeón Orell Valerian Liehr-8/+101
Manually implement derived `NonZero` traits. Step 3 as mentioned in https://github.com/rust-lang/rust/pull/100428#pullrequestreview-1767139731. Manually implement the traits that would cause “borrow of layout constrained field with interior mutability” errors when switching to `NonZero<T>`. r? ```@dtolnay```
2024-01-23Rollup merge of #120244 - reitermarkus:nonzero-self, r=dtolnayLeón Orell Valerian Liehr-43/+48
Use `Self` in `NonZero*` implementations. This slightly reduces the size of the eventual diff when making these generic, since this can be merged independently.
2024-01-23Further Implement Power of Two OptimizationNicholas Thompson-146/+324
2024-01-23Further Implement `is_val_statically_known`Nicholas Thompson-8/+22
2024-01-23Auto merge of #119892 - joboet:libs_use_assert_unchecked, r=Nilstrieb,cuviperbors-9/+12
Use `assert_unchecked` instead of `assume` intrinsic in the standard library Now that a public wrapper for the `assume` intrinsic exists, we can use it in the standard library. CC #119131
2024-01-22Add Assume custom MIR.Camille GILLOT-0/+2
2024-01-22Rollup merge of #120143 - ↵Matthias Krüger-0/+1
compiler-errors:consolidate-instance-resolve-for-coroutines, r=oli-obk Consolidate logic around resolving built-in coroutine trait impls Deduplicates a lot of code. Requires defining a new lang item for `Coroutine::resume` for consistency, but it seems not harmful at worst, and potentially later useful at best. r? oli-obk
2024-01-22Use `Self` in `NonZero*` implementations.Markus Reiter-43/+48
2024-01-22Rollup merge of #118578 - mina86:c, r=dtolnayMatthias Krüger-28/+217
core: introduce split_at{,_mut}_checked Introduce split_at_checked and split_at_mut_checked methods to slices types (including str) which are non-panicking versions of split_at and split_at_mut respectively. This is analogous to get method being non-panicking version of indexing. - https://github.com/rust-lang/libs-team/issues/308 - https://github.com/rust-lang/rust/issues/119128
2024-01-22Auto merge of #120226 - matthiaskrgr:rollup-9xwx0si, r=matthiaskrgrbors-39/+39
Rollup of 9 pull requests Successful merges: - #118714 ( Explanation that fields are being used when deriving `(Partial)Ord` on enums) - #119710 (Improve `let_underscore_lock`) - #119726 (Tweak Library Integer Division Docs) - #119746 (rustdoc: hide modals when resizing the sidebar) - #119986 (Fix error counting) - #120194 (Shorten `#[must_use]` Diagnostic Message for `Option::is_none`) - #120200 (Correct the anchor of an URL in an error message) - #120203 (Replace `#!/bin/bash` with `#!/usr/bin/env bash` in rust-installer tests) - #120212 (Give nnethercote more reviews) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-22Auto merge of #120196 - matthiaskrgr:rollup-id2zocf, r=matthiaskrgrbors-2/+0
Rollup of 8 pull requests Successful merges: - #120005 (Update Readme) - #120045 (Un-hide `iter::repeat_n`) - #120128 (Make stable_mir::with_tables sound) - #120145 (fix: Drop guard was deallocating with the incorrect size) - #120158 (`rustc_mir_dataflow`: Restore removed exports) - #120167 (Capture the rationale for `-Zallow-features=` in bootstrap.py) - #120174 (Warn users about limited review for tier 2 and 3 code) - #120180 (Document some alternatives to `Vec::split_off`) Failed merges: - #120171 (Fix assume and assert in jump threading) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-22Rollup merge of #120194 - ↵Matthias Krüger-1/+1
HTGAzureX1212:HTGAzureX1212shorten-option-must-use, r=Nilstrieb Shorten `#[must_use]` Diagnostic Message for `Option::is_none` This shortens the `#[must_use]` diagnostics displayed, in light of the [review comment](https://github.com/rust-lang/rust/pull/62431/files#r300819839) on when this was originally added.