about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-11-03clarify that the str invariant is a safety, not validity, invariantRalf Jung-6/+13
2023-11-02Add insta-stable std::hash::{DefaultHasher, RandomState} exportsltdk-41/+19
2023-11-02Pretty print Fn traits in rustc_on_unimplementedMichael Goulet-12/+12
2023-11-02Rollup merge of #117512 - joshlf:patch-8, r=dtolnayMatthias Krüger-2/+63
Expand mem::offset_of! docs Makes progress on #106655
2023-11-02Rollup merge of #117495 - compiler-errors:unsize-docs, r=lcnrMatthias Krüger-6/+12
Clarify `Unsize` documentation The documentation erroneously says that: ```rust /// - Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`. /// - Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions /// are met: /// - `T: Unsize<U>`. /// - Only the last field of `Foo` has a type involving `T`. /// - `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field. ``` Specifically, `T: Unsize<U>` is not required to hold -- only the final field must implement `FinalField<T>: Unsize<FinalField<U>>`. This can be demonstrated by the test I added. --- Second commit fleshes out the documentation a lot more.
2023-11-02Update mod.rsJoshua Liebow-Feeser-0/+2
2023-11-02Update mod.rsJoshua Liebow-Feeser-2/+1
2023-11-02Remove trailing spaceJoshua Liebow-Feeser-1/+1
2023-11-02Expand mem::offset_of! docsJoshua Liebow-Feeser-2/+62
Makes progress on #106655
2023-11-02Add track_caller to transmute_copyElichai Turkel-0/+1
2023-11-01fixes: typo in `std::cmp::Ord` trait docsmassivebird-1/+1
2023-11-01Rework unsize documentationMichael Goulet-5/+12
2023-11-01Remove a false statement from Unsize docs, add a testMichael Goulet-1/+0
2023-11-01Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiserbors-2/+9
Support enum variants in offset_of! This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like ```rust offset_of!(Type, field.Variant.field) ``` Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful. [RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant) Tracking Issue #106655.
2023-11-01Rollup merge of #115626 - clarfonthey:unchecked-math, r=thomccMatthias Krüger-19/+45
Clean up unchecked_math, separate out unchecked_shifts Tracking issue: #85122 Changes: 1. Remove `const_inherent_unchecked_arith` flag and make const-stability flags the same as the method feature flags. Given the number of other unsafe const fns already stabilised, it makes sense to just stabilise these in const context when they're stabilised. 2. Move `unchecked_shl` and `unchecked_shr` into a separate `unchecked_shifts` flag, since the semantics for them are unclear and they'll likely be stabilised separately as a result. 3. Add an `unchecked_neg` method exclusively to signed integers, under the `unchecked_neg` flag. This is because it's a new API and probably needs some time to marinate before it's stabilised, and while it *would* make sense to have a similar version for unsigned integers since `checked_neg` also exists for those there is absolutely no case where that would be a good idea, IMQHO. The longer-term goal here is to prepare the `unchecked_math` methods for an FCP and stabilisation since they've existed for a while, their semantics are clear, and people seem in favour of stabilising them.
2023-10-31Update based on wesleywiser reviewGeorge Bateman-2/+2
2023-10-31Update MIR tests for offset_ofGeorge Bateman-0/+1
2023-10-31Enums in offset_of: update based on est31, scottmcm & llogiq reviewGeorge Bateman-2/+8
2023-10-31Accept less invalid Rust in rustdocOli Scherer-20/+0
2023-10-30Rollup merge of #117205 - weiznich:multiple_notes_for_on_unimplemented, ↵León Orell Valerian Liehr-1/+14
r=compiler-errors Allows `#[diagnostic::on_unimplemented]` attributes to have multiple notes This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests. r? `@compiler-errors` I'm happy to adjust any of the existing changed location to emit the old error message if that's desired.
2023-10-30Auto merge of #117332 - saethlin:panic-immediate-abort, r=workingjubileebors-2/+9
Increase the reach of panic_immediate_abort I wanted to use/abuse this recently as part of another project, and I was surprised how many panic-related things were left in my binaries if I built a large crate with the feature enabled along with LTO. These changes get all the panic-related symbols that I could find out of my set of locally installed Rust utilities.
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-2/+9
2023-10-29Rollup merge of #117312 - RalfJung:memcpy-assumptions, r=Mark-SimulacrumGuillaume Gomez-1/+2
memcpy assumptions: link to source showing that GCC makes the same assumption I finally stumbled upon a source showing that GCC also generates overlapping `memcpy`. So if we're linking major C compilers making such assumptions here, let's have both clang and GCC.
2023-10-28Remove asmjs from libraryJubilee Young-6/+0
2023-10-28Rollup merge of #117162 - c410-f3r:try, r=workingjubileeJubilee-89/+91
Remove `cfg_match` from the prelude Fixes #117057 cc #115585
2023-10-28Auto merge of #116240 - dtolnay:constdiscriminant, r=thomccbors-3/+2
Const stabilize mem::discriminant Tracking issue: #69821. This PR is a rebase of https://github.com/rust-lang/rust/pull/103893 to resolve conflicts in library/core/src/lib.rs (against #102470 and #110393).
2023-10-28make pointer_structural_match warn-by-defaultRalf Jung-0/+1
2023-10-28Auto merge of #117038 - saethlin:inline-range-methods, r=workingjubileebors-0/+7
Add #[inline] to some recalcitrant ops::range methods Fixes https://github.com/rust-lang/rust/issues/116861
2023-10-28memcpy assumptions: link to source showing that GCC makes the same assumptionRalf Jung-1/+2
2023-10-27Allows `#[diagnostic::on_unimplemented]` attributes to have multipleGeorg Semmler-1/+14
notes This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests.
2023-10-27Auto merge of #117272 - matthiaskrgr:rollup-upg122z, r=matthiaskrgrbors-1/+1
Rollup of 6 pull requests Successful merges: - #114998 (feat(docs): add cargo-pgo to PGO documentation 📝) - #116868 (Tweak suggestion span for outer attr and point at item following invalid inner attr) - #117240 (Fix documentation typo in std::iter::Iterator::collect_into) - #117241 (Stash and cancel cycle errors for auto trait leakage in opaques) - #117262 (Create a new ConstantKind variant (ZeroSized) for StableMIR) - #117266 (replace transmute by raw pointer cast) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-27Rollup merge of #117240 - ↵Matthias Krüger-1/+1
trueNAHO:docs-std-iter-Iterator-collect-into-fix-typo, r=the8472 Fix documentation typo in std::iter::Iterator::collect_into
2023-10-27Auto merge of #116205 - WaffleLapkin:stabilize_pointer_byte_offsets, r=dtolnaybors-33/+42
Stabilize `[const_]pointer_byte_offsets` Closes #96283 Awaiting FCP completion: https://github.com/rust-lang/rust/issues/96283#issuecomment-1735835331 r? libs-api
2023-10-27Auto merge of #117260 - okaneco:ascii_branchless, r=thomccbors-6/+12
Refactor some `char`, `u8` ASCII functions to be branchless Extract conditions in singular `matches!` with or-patterns to individual `matches!` statements which enables branchless code output. The following functions were changed: - `is_ascii_alphanumeric` - `is_ascii_hexdigit` - `is_ascii_punctuation` Added codegen tests --- Continued from https://github.com/rust-lang/rust/pull/103024. Based on the comment from `@scottmcm` https://github.com/rust-lang/rust/pull/103024#pullrequestreview-1248697206. The unmodified `is_ascii_*` functions didn't seem to benefit from extracting the conditions. I've never written a codegen test before, but I tried to check that no branches were emitted.
2023-10-26Refactor some `char`, `u8` ascii functions to be branchlessokaneco-6/+12
Decompose singular `matches!` with or-patterns to individual `matches!` statements to enable branchless code output. The following functions were changed: - `is_ascii_alphanumeric` - `is_ascii_hexdigit` - `is_ascii_punctuation` Add codegen tests Co-authored-by: George Bateman <george.bateman16@gmail.com> Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2023-10-26Rollup merge of #117243 - chfogelman:replace-not-swap-comment, r=thomccMatthias Krüger-0/+4
Explain implementation of mem::replace This adds a comment to explain why `mem::replace` is not implemented in terms of `mem::swap` to prevent [naïfs like me](https://github.com/rust-lang/rust/pull/117189) from trying to "fix" it.
2023-10-26Add comment to mem::replace to explain why it's not implemented via mem::swapCarter Hunt Fogelman-0/+4
2023-10-26Fix documentation typo in std::iter::Iterator::collect_intoNAHO-1/+1
2023-10-26Auto merge of #112875 - compiler-errors:negative-coherence-rework, r=lcnrbors-0/+1
Rework negative coherence to properly consider impls that only partly overlap This PR implements a modified negative coherence that handles impls that only have partial overlap. It does this by: 1. taking both impl trait refs, instantiating them with infer vars 2. equating both trait refs 3. taking the equated trait ref (which represents the two impls' intersection), and resolving any vars 4. plugging all remaining infer vars with placeholder types these placeholder-plugged trait refs can then be used normally with the new trait solver, since we no longer have to worry about the issue with infer vars in param-envs. We use the **new trait solver** to reason correctly about unnormalized trait refs (due to deferred projection equality), since this avoid having to normalize anything under param-envs with infer vars in them. This PR then additionally: * removes the `FnPtr` knowable hack by implementing proper negative `FnPtr` trait bounds for rigid types. --- An example: Consider these two partially overlapping impls: ``` impl<T, U> PartialEq<&U> for &T where T: PartialEq<U> {} impl<F> PartialEq<F> for F where F: FnPtr {} ``` Under the old algorithm, we would take one of these impls and replace it with infer vars, then try unifying it with the other impl under identity substitutions. This is not possible in either direction, since it either sets `T = U`, or tries to equate `F = &?0`. Under the new algorithm, we try to unify `?0: PartialEq<?0>` with `&?1: PartialEq<&?2>`. This gives us `?0 = &?1 = &?2` and thus `?1 = ?2`. The intersection of these two trait refs therefore looks like: `&?1: PartialEq<&?1>`. After plugging this with placeholders, we get a trait ref that looks like `&!0: PartialEq<&!0>`, with the first impl having substs `?T = ?U = !0` and the second having substs `?F = &!0`[^1]. Then we can take the param-env from the first impl, and try to prove the negated where clause of the second. We know that `&!0: !FnPtr` never holds, since it's a rigid type that is also not a fn ptr, we successfully detect that these impls may never overlap. [^1]: For the purposes of this example, I just ignored lifetimes, since it doesn't really matter.
2023-10-25Stabilize `[const_]pointer_byte_offsets`Maybe Waffle-33/+42
2023-10-25Auto merge of #117180 - matthiaskrgr:rollup-rxhl6ep, r=matthiaskrgrbors-0/+1
Rollup of 7 pull requests Successful merges: - #117111 (Remove support for alias `-Z instrument-coverage`) - #117141 (Require target features to match exactly during inlining) - #117152 (Fix unwrap suggestion for async fn) - #117154 (implement C ABI lowering for CSKY) - #117159 (Work around the fact that `check_mod_type_wf` may spuriously return `ErrorGuaranteed`) - #117163 (compiletest: Display compilation errors in mir-opt tests) - #117173 (Make `Iterator` a lang item) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-25Avoid unnecessary comparison in partition_equalLukas Bergdoll-3/+10
The branchy Hoare partition `partition_equal` as part of `slice::sort_unstable` has a bug that makes it perform a comparison of the last element twice. Measuring inputs with a Zipfian distribution with characterizing exponent s == 1.0, yields a ~0.05% reduction in the total number of comparisons performed.
2023-10-25Make `Iterator` a lang itemOli Scherer-0/+1
2023-10-25Add the missing wordscottmcm-4/+4
2023-10-25Update library/core/src/primitive_docs.rsJoshua Liebow-Feeser-0/+4
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2023-10-25Fix some coroutine sentences that don't make sense anymore.Oli Scherer-1/+1
These happened during the `generator` -> `coroutine` rename.
2023-10-25Remove `cfg_match` from the preludeCaio-89/+91
2023-10-24Auto merge of #117135 - matthiaskrgr:rollup-zdh18i6, r=matthiaskrgrbors-49/+2
Rollup of 8 pull requests Successful merges: - #116094 (Introduce `-C instrument-coverage=branch` to gate branch coverage) - #116396 (Migrate diagnostics in `rustc_hir_analysis/src/coherence/orphan.rs`) - #116714 (Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*`) - #116792 (Avoid unnecessary renumbering during borrowck) - #116841 (Suggest unwrap/expect for let binding type mismatch) - #116943 (Add target features for LoongArch) - #117010 (Add method to convert internal to stable constructs) - #117127 (Remove `#[allow(incomplete_features)]` from RPITIT/AFIT tests) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-24Rollup merge of #116714 - WaffleLapkin:order-the-order, r=joshtriplettMatthias Krüger-49/+2
Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*` Fixes #116711 The main pain of this PR is to fix the buggy impl of `Ord` for `SocketAddrV6`, which ignored half of the fields (while `PartialEq` is derived): https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L99-L106 https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L676 For me it looks like a simple copy-paste error made in https://github.com/rust-lang/rust/pull/72239 (copy from v4 impl) (cc `@hch12907),` as I don't see this behavior being mentioned anywhere on the PR and it also does not respect `cmp` trait "rules". I also do not see any reasons for those impls to _not_ be derived. It's a shame we did not notice this for 28 versions/3 years. I guess this is a bug fix, but I'm not sure what the process here should be. r? libs
2023-10-24Auto merge of #117126 - matthiaskrgr:rollup-8huie8f, r=matthiaskrgrbors-1/+1
Rollup of 5 pull requests Successful merges: - #117081 (fix typos in comments) - #117091 (`OptWithInfcx` naming nits, trait bound simplifications) - #117092 (Add regression test for #117058) - #117093 (Update books) - #117105 (remove change-id assertion in bootstrap test) r? `@ghost` `@rustbot` modify labels: rollup