about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-03-03Apply suggestions from code reviewLukas Bergdoll-4/+4
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-03-03Small enhancement to description of From traitJonas Pleyer-2/+2
- fix small typo - avoid repetition of formulations
2024-03-03library/ptr: mention that ptr::without_provenance is equivalent to deriving ↵Ralf Jung-0/+4
from the null ptr
2024-03-02typoRalf Jung-1/+1
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2024-03-02Rollup merge of #121888 - cppcoffee:style, r=NilstriebMatthias Krüger-0/+1
style library/core/src/error.rs Add an extra blank line for clarity in distinguishing implementations.
2024-03-02Rollup merge of #121759 - RalfJung:addr_of, r=the8472Matthias Krüger-15/+63
attempt to further clarify addr_of docs
2024-03-02const_eval_select: make it safe but be careful with what we expose on stable ↵Ralf Jung-30/+73
for now
2024-03-02Apply review commentsLukas Bergdoll-2/+2
2024-03-02attempt to further clarify addr_of docsRalf Jung-15/+63
2024-03-02style library/core/src/error.rsXiaobo Liu-0/+1
2024-03-01Rollup merge of #121634 - RavuAlHemio:slice-prefix-suffix-docs, r=cuviperMatthias Krüger-4/+10
Clarify behavior of slice prefix/suffix operations in case of equality Operations such as starts_with, ends_with, strip_prefix and strip_suffix can be either strict (do not consider a slice to be a prefix/suffix of itself) or not. In Rust's case, they are not strict. Add a few phrases to the documentation to clarify this.
2024-03-01Make `ZeroablePrimitive` trait unsafe.Markus Reiter-2/+6
2024-02-29Rollup merge of #121753 - mu001999:core/add_cfg, r=cuviperMatthias Krüger-9/+5
Add proper cfg to keep only one AlignmentEnum definition for different target_pointer_widths Detected by #121752 Only one AlignmentEnum would be used with a specified target_pointer_width
2024-02-29Rollup merge of #121681 - jswrenn:nix-visibility-analysis, r=compiler-errorsMatthias Krüger-4/+5
Safe Transmute: Revise safety analysis This PR migrates `BikeshedIntrinsicFrom` to a simplified safety analysis (described [here](https://github.com/rust-lang/project-safe-transmute/issues/15)) that does not rely on analyzing the visibility of types and fields. The revised analysis treats primitive types as safe, and user-defined types as potentially carrying safety invariants. If Rust gains explicit (un)safe fields, this PR is structured so that it will be fairly easy to thread support for those annotations into the analysis. Notably, this PR removes the `Context` type parameter from `BikeshedIntrinsicFrom`. Most of the files changed by this PR are just UI tests tweaked to accommodate the removed parameter. r? `@compiler-errors`
2024-02-29Forbid implementing `Freeze` even if the trait is stabilizedOli Scherer-3/+4
2024-02-29Expose `Freeze` trait againOli Scherer-2/+8
2024-02-29Drop link to matches macro and link matches macro to assert_matches.Lukas Bergdoll-5/+10
2024-02-29Add proper cfgr0cky-9/+5
2024-02-28Improve assert_matches! documentationLukas Bergdoll-29/+50
This new documentation tries to avoid to limit the impact of the conceptual pitfall, that the if guard relaxes the constraint, when really it tightens it. This is achieved by changing the text and examples. The previous documentation also chose a rather weird and non-representative example for the if guard, that made it needlessly complicated to understand.
2024-02-27safe transmute: revise safety analysisJack Wrenn-4/+5
Migrate to a simplified safety analysis that does not use visibility. Closes https://github.com/rust-lang/project-safe-transmute/issues/15
2024-02-27intrinsics.rs: add some notes on unwindingRalf Jung-0/+10
2024-02-27Stabilize the `#[diagnostic]` namespace and ↵Georg Semmler-1/+1
`#[diagnostic::on_unimplemented]` attribute This PR stabilizes the `#[diagnostic]` attribute namespace and a minimal option of the `#[diagnostic::on_unimplemented]` attribute. The `#[diagnostic]` attribute namespace is meant to provide a home for attributes that allow users to influence error messages emitted by the compiler. The compiler is not guaranteed to use any of this hints, however it should accept any (non-)existing attribute in this namespace and potentially emit lint-warnings for unused attributes and options. This is meant to allow discarding certain attributes/options in the future to allow fundamental changes to the compiler without the need to keep then non-meaningful options working. The `#[diagnostic::on_unimplemented]` attribute is allowed to appear on a trait definition. This allows crate authors to hint the compiler to emit a specific error message if a certain trait is not implemented. For the `#[diagnostic::on_unimplemented]` attribute the following options are implemented: * `message` which provides the text for the top level error message * `label` which provides the text for the label shown inline in the broken code in the error message * `note` which provides additional notes. The `note` option can appear several times, which results in several note messages being emitted. If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Any other occurrence generates an lint warning. For any other non-existing option a lint-warning is generated. All three options accept a text as argument. This text is allowed to contain format parameters referring to generic argument or `Self` by name via the `{Self}` or `{NameOfGenericArgument}` syntax. For any non-existing argument a lint warning is generated. Tracking issue: #111996
2024-02-27Auto merge of #121655 - matthiaskrgr:rollup-qpx3kks, r=matthiaskrgrbors-7/+18
Rollup of 4 pull requests Successful merges: - #121598 (rename 'try' intrinsic to 'catch_unwind') - #121639 (Update books) - #121648 (Update Vec and String `{from,into}_raw_parts`-family docs) - #121651 (Properly emit `expected ;` on `#[attr] expr`) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-27Rollup merge of #121598 - RalfJung:catch_unwind, r=oli-obkMatthias Krüger-7/+18
rename 'try' intrinsic to 'catch_unwind' The intrinsic has nothing to do with `try` blocks, and corresponds to the stable `catch_unwind` function, so this makes a lot more sense IMO. Also rename Miri's special function while we are at it, to reflect the level of abstraction it works on: it's an unwinding mechanism, on which Rust implements panics.
2024-02-26Auto merge of #121516 - RalfJung:platform-intrinsics-begone, r=oli-obkbors-2/+80
remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsics `@Amanieu` `@workingjubilee` I don't think there is any reason these need to be "special"? The [original RFC](https://rust-lang.github.io/rfcs/1199-simd-infrastructure.html) indicated eventually making them stable, but I think that is no longer the plan, so seems to me like we can clean this up a bit. Blocked on https://github.com/rust-lang/stdarch/pull/1538, https://github.com/rust-lang/rust/pull/121542.
2024-02-26Clarify behavior of slice prefix/suffix operations in case of equalityOndřej Hošek-4/+10
Operations such as starts_with, ends_with, strip_prefix and strip_suffix can be either strict (do not consider a slice to be a prefix/suffix of itself) or not. In Rust's case, they are not strict. Add a few phrases to the documentation to clarify this.
2024-02-26rename 'try' intrinsic to 'catch_unwind'Ralf Jung-7/+18
2024-02-25Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkinbors-0/+5
Implement RFC 3373: Avoid non-local definitions in functions This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-25Fix Hash implDavid Thomas-1/+1
2024-02-25remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsicsRalf Jung-2/+80
2024-02-25Auto merge of #121114 - Nilstrieb:no-inline!, r=saethlinbors-3/+15
Add `#[rustc_no_mir_inline]` for standard library UB checks should help with #121110 and also with #120848 Because the MIR inliner cannot know whether the checks are enabled or not, so inlining is an unnecessary compile time pessimization when debug assertions are disabled. LLVM knows whether they are enabled or not, so it can optimize accordingly without wasting time. r? `@saethlin`
2024-02-24Rollup merge of #121556 - GrigorenkoPV:addr_of, r=NilstriebMatthias Krüger-5/+6
Use `addr_of!` As per https://github.com/rust-lang/rust/pull/121303#discussion_r1500954662
2024-02-24Rollup merge of #121551 - nbdd0121:ffi_unwind, r=RalfJungMatthias Krüger-0/+1
Forbid use of `extern "C-unwind"` inside standard library Those libraries are build with `-C panic=unwind` and is expected to be linkable to `-C panic=abort` library. To ensure unsoundness compiler needs to prevent a `C-unwind` call to exist, as doing so may leak foreign exceptions into `-C panic=abort`. r? ``@RalfJung``
2024-02-24Rollup merge of #121343 - Takashiidobe:takashi/examples-for-slice, ↵Matthias Krüger-1/+10
r=Mark-Simulacrum Add examples for some methods on slices Adds some examples to some methods on slice. `is_empty` didn't have an example for an empty slice, even though `str` and the collections all have one, so I added that in. `first_mut` and `last_mut` didn't have an example for what happens when the slice is empty, whereas `first` and `last` do, so I added that too.
2024-02-24Add `#[rustc_no_mir_inline]` for standard library UB checksNilstrieb-3/+15
Co-authored-by: Ben Kimock <kimockb@gmail.com>
2024-02-24Forbid use of `extern "C-unwind"` inside standard libraryGary Guo-0/+1
Those libraries are build with `-C panic=unwind` and is expected to be linkable to `-C panic=abort` library. To ensure unsoundness compiler needs to prevent a `C-unwind` call to exist, as doing so may leak foreign exceptions into `-C panic=abort`.
2024-02-24library: use `addr_of!`Pavel Grigorenko-5/+6
2024-02-23Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnaybors-86/+84
Use generic `NonZero` everywhere in `library`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 Use generic `NonZero` everywhere (except stable examples). r? `@dtolnay`
2024-02-23Auto merge of #120730 - estebank:confusable-api, r=oli-obkbors-0/+4
Provide suggestions through `rustc_confusables` annotations Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` Fix #59450 (we can open subsequent tickets for specific cases). Fix #108437: ``` error[E0599]: `Option<{integer}>` is not an iterator --> f101.rs:3:9 | 3 | opt.flat_map(|val| Some(val)); | ^^^^^^^^ `Option<{integer}>` is not an iterator | ::: /home/gh-estebank/rust/library/core/src/option.rs:571:1 | 571 | pub enum Option<T> { | ------------------ doesn't satisfy `Option<{integer}>: Iterator` | = note: the following trait bounds were not satisfied: `Option<{integer}>: Iterator` which is required by `&mut Option<{integer}>: Iterator` help: you might have meant to use `and_then` | 3 | opt.and_then(|val| Some(val)); | ~~~~~~~~ ``` On type error of method call arguments, look at confusables for suggestion. Fix #87212: ``` error[E0308]: mismatched types --> f101.rs:8:18 | 8 | stuff.append(Thing); | ------ ^^^^^ expected `&mut Vec<Thing>`, found `Thing` | | | arguments to this method are incorrect | = note: expected mutable reference `&mut Vec<Thing>` found struct `Thing` note: method defined here --> /home/gh-estebank/rust/library/alloc/src/vec/mod.rs:2025:12 | 2025 | pub fn append(&mut self, other: &mut Self) { | ^^^^^^ help: you might have meant to use `push` | 8 | stuff.push(Thing); | ~~~~ ```
2024-02-22Add `flatmap`/`flat_map` -> `and_then` suggestionsEsteban Küber-0/+2
2024-02-22Add `rustc_confusables` annotations to some stdlib APIsEsteban Küber-0/+2
Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` #59450
2024-02-22Rollup merge of #121439 - jrudolph:patch-1, r=bjorn3Matthias Krüger-1/+1
Fix typo in metadata.rs doc comment
2024-02-22Fix example.Markus Reiter-3/+4
2024-02-22Use generic `NonZero` everywhere in `core`.Markus Reiter-84/+81
2024-02-22Auto merge of #121309 - Nilstrieb:inline-all-the-fallbacks, r=oli-obkbors-0/+6
Make intrinsic fallback bodies cross-crate inlineable This change was prompted by the stage1 compiler spending 4% of its time when compiling the polymorphic-recursion MIR opt test in `unlikely`. Intrinsic fallback bodies like `unlikely` should always be inlined, it's very silly if they are not. To do this, we enable the fallback bodies to be cross-crate inlineable. Not that this matters for our workloads since the compiler never actually _uses_ the "fallback bodies", it just uses whatever was cfg(bootstrap)ped, so I've also added `#[inline]` to those. See the comments for more information. r? oli-obk
2024-02-22Fix typo in metadata.rs doc commentJohannes Rudolph-1/+1
2024-02-22Add std::ffi::c_str modulesltdk-7/+24
2024-02-22Auto merge of #121223 - RalfJung:simd-intrinsics, r=Amanieubors-0/+69
intrinsics::simd: add missing functions, avoid UB-triggering fast-math Turns out stdarch declares a bunch more SIMD intrinsics that are still missing from libcore. I hope I got the docs and in particular the safety requirements right for these "unordered" and "nanless" intrinsics. Many of these are unused even in stdarch, but they are implemented in the codegen backend, so we may as well list them here. r? `@Amanieu` Cc `@calebzulawski` `@workingjubilee`
2024-02-21remove simd_reduce_{min,max}_nanlessRalf Jung-26/+0
2024-02-21rename ptr::invalid -> ptr::without_provenanceRalf Jung-98/+128
also introduce ptr::dangling matching NonNull::dangling