about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-07-27Rollup merge of #125897 - RalfJung:from-ref, r=AmanieuTrevor Gross-6/+86
from_ref, from_mut: clarify documentation This was brought up [here](https://github.com/rust-lang/rust/issues/56604#issuecomment-2143193486). The domain of quantification is generally always constrained by the type in the type signature, and I am not sure it's always worth spelling that out explicitly as that makes things exceedingly verbose. But since this was explicitly brought up, let's clarify.
2024-07-27Improve panic sections for sort*, sort_unstable* and select_nth_unstable*Lukas Bergdoll-12/+15
- Move panic information into # Panics section - Fix mentions of T: Ord that should be compare - Add missing information
2024-07-27Improve panic message and surrounding documentation for Ord violationsLukas Bergdoll-4/+19
The new sort implementations have the ability to detect Ord violations in many cases. This commit improves the message in a way that should help users realize what went wrong in their program.
2024-07-27Auto merge of #128255 - stepancheg:doc-shl, r=scottmcmbors-0/+13
Document 0x10.checked_shl(BITS - 1) does not overflow Not obvious.
2024-07-27Auto merge of #127946 - tgross35:fmt-builders-set-result, r=cuviperbors-4/+8
Always set `result` during `finish()` in debug builders Most functions for format builders set `self.result` after writing strings. This ensures that any further writing fails immediately rather than trying to write again. A few `.finish()` methods and the `.finish_non_exhaustive` did have this same behavior, so update the remaining `.finish()` methods to make it consistent here.
2024-07-27Document int.checked_shl(BITS - 1)Stepan Koltsov-0/+13
Not obvious.
2024-07-26Rollup merge of #128235 - harryscholes:fix-iterator-filter-docs, r=tgross35Trevor Gross-1/+1
Fix `Iterator::filter` docs Small fix to add code formatting around `Iterator::filter` `true` return type
2024-07-26Rollup merge of #124941 - Skgland:stabilize-const-int-from-str, r=dtolnayTrevor Gross-5/+4
Stabilize const `{integer}::from_str_radix` i.e. `const_int_from_str` This PR stabilizes the feature `const_int_from_str`. - ACP Issue: rust-lang/libs-team#74 - Implementation PR: rust-lang/rust#99322 - Part of Tracking Issue: rust-lang/rust#59133 API Change Diff: ```diff impl {integer} { - pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>; + pub const fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>; } impl ParseIntError { - pub fn kind(&self) -> &IntErrorKind; + pub const fn kind(&self) -> &IntErrorKind; } ``` This makes it easier to parse integers at compile-time, e.g. the example from the Tracking Issue: ```rust env!("SOMETHING").parse::<usize>().unwrap() ``` could now be achived with ```rust match usize::from_str_radix(env!("SOMETHING"), 10) { Ok(val) => val, Err(err) => panic!("Invalid value for SOMETHING environment variable."), } ``` rather than having to depend on a library that implements or manually implement the parsing at compile-time. --- Checklist based on [Libs Stabilization Guide - When there's const involved](https://std-dev-guide.rust-lang.org/development/stabilization.html#when-theres-const-involved) I am treating this as a [partial stabilization](https://std-dev-guide.rust-lang.org/development/stabilization.html#partial-stabilizations) as it shares a tracking issue (and is rather small), so directly opening the partial stabilization PR for the subset (feature `const_int_from_str`) being stabilized. - [x] ping Constant Evaluation WG - [x] no unsafe involved - [x] no `#[allow_internal_unstable]` - [ ] usage of `intrinsic::const_eval_select` rust-lang/rust#124625 in `from_str_radix_assert` to change the error message between compile-time and run-time - [ ] [rust-labg/libs-api FCP](https://github.com/rust-lang/rust/pull/124941#issuecomment-2207021921)
2024-07-26Add links from `assert_eq!` docs to `debug_assert_eq!`, etc.Matt Brubeck-0/+18
This adds information and links from the docs for the following macros to their debug-only versions: * `assert_eq!` * `assert_ne!` * `assert_matches!` This matches the existing documentation for the `assert!` macro.
2024-07-26Always set `result` during `finish()` in debug buildersTrevor Gross-4/+8
Most functions for format builders set `self.result` after writing strings. This ensures that any further writing fails immediately rather than trying to write again. A few `.finish()` methods did have this same behavior, so make it consistent here.
2024-07-26Fix docsharryscholes-1/+1
2024-07-26Fix doc nitsJohn Arundel-456/+503
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-26Rollup merge of #128170 - saethlin:clone-fn, r=compiler-errorsTrevor Gross-0/+3
Make Clone::clone a lang item I want to absorb all the logic for picking whether an Instance is LocalCopy or GloballyShared into one place. As part of this, I wanted to identify Clone shims inside `cross_crate_inlinable` and found that rather tricky. `@compiler-errors` suggested that I add a lang item for `Clone::clone` because that would produce other cleanups in the compiler. That sounds good to me, but I have looked and I've only been able to find one. r? compiler-errors
2024-07-26Rollup merge of #128150 - BoxyUwU:std_only_sized_const_params, r=workingjubileeMatthias Krüger-13/+2
Stop using `unsized_const_parameters` in core/std `feature(unsized_const_parameters)` is an incomplete feature and should not be used by core/std as it makes it can make it significantly harder to evolve the feature. It also just generally opens the possibility of introducing bugs on stable through std's backdoor. The only usage of this feature in std is the `simd_shuffle_intrinsic` added in #119213. It doesn't seem to be used anywhere as far as I can tell so it is removed in this PR. All tests and codegen logic etc have been kept however. r? `@workingjubilee`
2024-07-26Rollup merge of #127950 - nnethercote:rustfmt-skip-on-use-decls, r=cuviperMatthias Krüger-4/+11
Use `#[rustfmt::skip]` on some `use` groups to prevent reordering. `use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it. This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it. r? `@cuviper`
2024-07-25Make Clone::clone a lang itemBen Kimock-0/+3
2024-07-25Stop using `unsized_const_parameters` in core/stdBoxy-13/+2
2024-07-25clarify interactions with MaybeUninit and UnsafeCellbinarycat-6/+10
2024-07-25remove duplicate explanations of the ptr to ref conversion rulesbinarycat-183/+50
2024-07-25create a new section on pointer to reference conversionbinarycat-36/+28
also start deduplicating the docs that are getting moved to this section.
2024-07-25CStr: derive PartialEq, Eq; add test for OrdPavel Grigorenko-11/+21
2024-07-24Implement `mixed_integer_ops_unsigned_sub`ilikdoge-0/+103
2024-07-24Rollup merge of #128046 - GrigorenkoPV:90435, r=tgross35Matthias Krüger-7/+7
Fix some `#[cfg_attr(not(doc), repr(..))]` Now that #90435 seems to have been resolved.
2024-07-24Rollup merge of #126042 - davidzeng0:master, r=AmanieuMatthias Krüger-0/+61
Implement `unsigned_signed_diff` <!-- 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> --> Implements https://github.com/rust-lang/rust/issues/126041
2024-07-24Rollup merge of #128120 - compiler-errors:async-fn-name, r=oli-obkMatthias Krüger-3/+3
Gate `AsyncFn*` under `async_closure` feature T-lang has not come to a consensus on the naming of async closure callable bounds, and as part of allowing the async closures RFC merge, we agreed to place `AsyncFn` under the same gate as `async Fn` so that these syntaxes can be evaluated in parallel. See https://github.com/rust-lang/rfcs/pull/3668#issuecomment-2246435537 r? oli-obk
2024-07-24Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=AmanieuMatthias Krüger-10/+5
Replace some `mem::forget`'s with `ManuallyDrop` > but I would like to see a larger effort to replace all uses of `mem::forget`. _Originally posted by `@saethlin` in https://github.com/rust-lang/rust/issues/127584#issuecomment-2226087767_ So, r? `@saethlin` Sorry, I have finished writing all of this before I got your response.
2024-07-24Rollup merge of #127252 - fitzgen:edge-cases-for-bitwise-operations, r=m-ou-seMatthias Krüger-6/+35
Add edge-case examples to `{count,leading,trailing}_{ones,zeros}` methods Some architectures (i386) do not define a "count leading zeros" instruction, they define a "find first set bit" instruction (`bsf`) whose result is undefined when given zero (ie none of the bits are set). Of this family of bitwise operations, I always forget which of these things is potentially undefined for zero, and I'm also not 100% sure that Rust provides a hard guarantee for the results of these methods when given zero. So I figured there are others who have these same uncertainties, and it would be good to resolve them and answer the question via extending these doc examples/tests. See https://en.wikipedia.org/wiki/Find_first_set#Hardware_support for more info on i386 and `bsf` on zero.
2024-07-24Rollup merge of #126152 - RalfJung:size_of_val_raw, r=saethlinMatthias Krüger-0/+10
size_of_val_raw: for length 0 this is safe to call For motivation, see https://github.com/rust-lang/unsafe-code-guidelines/issues/465, specifically around [here](https://github.com/rust-lang/unsafe-code-guidelines/issues/465#issuecomment-2136401114). Cc `@rust-lang/opsem`
2024-07-24Rollup merge of #128043 - safinaskar:primitive, r=workingjubileeMatthias Krüger-3/+9
Docs for core::primitive: mention that "core" can be shadowed, too, so we should write "::core" ``@rustbot`` label +A-docs
2024-07-24Rollup merge of #127481 - a1phyr:pattern_gat, r=AmanieuMatthias Krüger-146/+151
Remove generic lifetime parameter of trait `Pattern` Use a GAT for `Searcher` associated type because this trait is always implemented for every lifetime anyway. cc #27721
2024-07-24Rollup merge of #126770 - wr7:master, r=AmanieuMatthias Krüger-0/+149
Add elem_offset and related methods Implementation of #126769
2024-07-23Gate AsyncFn* under async_closure featureMichael Goulet-3/+3
2024-07-23Add elem_offset and related methodswr7-0/+149
2024-07-23library/core/src/primitive.rs: small doc fixAskar Safin-1/+1
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-07-23add `is_multiple_of` for unsigned integer typesFolkert-0/+38
2024-07-23Docs for core::primitive: mention that "core" can be shadowed, too, so we ↵Askar Safin-3/+9
should write "::core"
2024-07-22LocalWaker docs: Make long-ago omitted but probably intended changesIan Jackson-1/+3
In 6f8a944ba4311cbcf5922132721095c226c6fbab, titled Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`. the summary line for Waker was changed: - /// Creates a new `Waker` that does nothing when `wake` is called. + /// Returns a reference to a `Waker` that does nothing when used. and the sentence about clone was added. LocalWaker's docs were not changed, even though the types were, but there is no explanation for why not. It seems like it was simply a slip induced by the clone-and-hack.
2024-07-22Docs for Waker and LocalWaker: Add cross-refs in commentIan Jackson-0/+8
2024-07-22Rollup merge of #128008 - weiznich:fix/121521, r=lcnrTrevor Gross-1/+3
Start using `#[diagnostic::do_not_recommend]` in the standard library This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in #121521 The result in not perfect yet, but at least the `Yeet` suggestion is not shown anymore. I would consider that as a minor improvement.
2024-07-22Start using `#[diagnostic::do_not_recommend]` in the standard libraryGeorg Semmler-1/+3
This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in #121521
2024-07-22Fix some `#[cfg_attr(not(doc), repr(..))]`Pavel Grigorenko-7/+7
Now that #90435 seems to have been resolved.
2024-07-21Implement `debug_more_non_exhaustive`Trevor Gross-2/+521
Add a `.finish_non_exhaustive()` method to `DebugTuple`, `DebugSet`, `DebugList`, and `DebugMap`. This indicates that the structures have remaining items with `..`. This implements the ACP at <https://github.com/rust-lang/libs-team/issues/248>.
2024-07-21Make use of raw strings in `core::fmt::builders`Trevor Gross-49/+49
There are quite a few uses of escaped quotes. Turn these into raw strings within documentation and tests to make things easier to read.
2024-07-21Auto merge of #127722 - BoxyUwU:new_adt_const_params_limitations, ↵bors-12/+65
r=compiler-errors Forbid borrows and unsized types from being used as the type of a const generic under `adt_const_params` Fixes #112219 Fixes #112124 Fixes #112125 ### Motivation Currently the `adt_const_params` feature allows writing `Foo<const N: [u8]>` this is entirely useless as it is not possible to write an expression which evaluates to a type that is not `Sized`. In order to actually use unsized types in const generics they are typically written as `const N: &[u8]` which *is* possible to provide a value of. Unfortunately allowing the types of const parameters to contain references is non trivial (#120961) as it introduces a number of difficult questions about how equality of references in the type system should behave. References in the types of const generics is largely only useful for using unsized types in const generics. This PR introduces a new feature gate `unsized_const_parameters` and moves support for `const N: [u8]` and `const N: &...` from `adt_const_params` into it. The goal here hopefully is to experiment with allowing `const N: [u8]` to work without references and then eventually completely forbid references in const generics. Splitting this out into a new feature gate means that stabilization of `adt_const_params` does not have to resolve #120961 which is the only remaining "big" blocker for the feature. Remaining issues after this are a few ICEs and naming bikeshed for `ConstParamTy`. ### Implementation The implementation is slightly subtle here as we would like to ensure that a stabilization of `adt_const_params` is forwards compatible with any outcome of `unsized_const_parameters`. This is inherently tricky as we do not support unstable trait implementations and we determine whether a type is valid as the type of a const parameter via a trait bound. There are a few constraints here: - We would like to *allow for the possibility* of adding a `Sized` supertrait to `ConstParamTy` in the event that we wind up opting to not support unsized types and instead requiring people to write the 'sized version', e.g. `const N: [u8; M]` instead of `const N: [u8]`. - Crates should be able to enable `unsized_const_parameters` and write trait implementations of `ConstParamTy` for `!Sized` types without downstream crates that only enable `adt_const_params` being able to observe this (required for std to be able to `impl<T> ConstParamTy for [T]` Ultimately the way this is accomplished is via having two traits (sad), `ConstParamTy` and `UnsizedConstParamTy`. Depending on whether `unsized_const_parameters` is enabled or not we change which trait is used to check whether a type is allowed to be a const parameter. Long term (when stabilizing `UnsizedConstParamTy`) it should be possible to completely merge these traits (and derive macros), only having a single `trait ConstParamTy` and `macro ConstParamTy`. Under `adt_const_params` it is now illegal to directly refer to `ConstParamTy` it is only used as an internal impl detail by `derive(ConstParamTy)` and checking const parameters are well formed. This is necessary in order to ensure forwards compatibility with all possible future directions for `feature(unsized_const_parameters)`. Generally the intuition here should be that `ConstParamTy` is the stable trait that everything uses, and `UnsizedConstParamTy` is that plus unstable implementations (well, I suppose `ConstParamTy` isn't stable yet :P).
2024-07-19Auto merge of #127982 - matthiaskrgr:rollup-nzyvphj, r=matthiaskrgrbors-2/+2
Rollup of 6 pull requests Successful merges: - #127295 (CFI: Support provided methods on traits) - #127814 (`C-cmse-nonsecure-call`: improved error messages) - #127949 (fix: explain E0120 better cover cases when its raised) - #127966 (Use structured suggestions for unconstrained generic parameters on impl blocks) - #127976 (Lazy type aliases: Diagostics: Detect bivariant ty params that are only used recursively) - #127978 (Avoid ref when using format! for perf) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-19Rollup merge of #127978 - nyurik:lib-refs, r=workingjubileeMatthias Krüger-2/+2
Avoid ref when using format! for perf Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-07-19Avoid ref when using format! for perfYuri Astrakhan-2/+2
Clean up a few minor refs in `format!` macro, as it has a tiny perf cost. A few more minor related cleanups.
2024-07-19improve safety commentivan-shrimp-1/+1
2024-07-19add `NonZero<uN>::isqrt`ivan-shrimp-45/+63
2024-07-19Use `#[rustfmt::skip]` on some `use` groups to prevent reordering.Nicholas Nethercote-4/+11
`use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it. This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it.