about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
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/+2
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-63/+93
also introduce ptr::dangling matching NonNull::dangling
2024-02-21make simd_reduce_{mul,add}_unordered use only the 'reassoc' flag, not all ↵Ralf Jung-12/+4
fast-math flags
2024-02-21intrinsics::simd: add missing functionsRalf Jung-0/+103
2024-02-21Auto merge of #121383 - Dylan-DPC:rollup-735p4u4, r=Dylan-DPCbors-0/+12
Rollup of 7 pull requests Successful merges: - #121208 (Convert `delayed_bug`s to `bug`s.) - #121288 (make rustc_expand translatable) - #121304 (Add docs for extension proc-macro) - #121328 (Make --verbose imply -Z write-long-types-to-disk=no) - #121338 (Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect) - #121361 (diagnostic items for legacy numeric modules) - #121375 (Print proper relative path for descriptive name check) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-21Auto merge of #120718 - saethlin:reasonable-fast-math, r=nnethercotebors-0/+40
Add "algebraic" fast-math intrinsics, based on fast-math ops that cannot return poison Setting all of LLVM's fast-math flags makes our fast-math intrinsics very dangerous, because some inputs are UB. This set of flags permits common algebraic transformations, but according to the [LangRef](https://llvm.org/docs/LangRef.html#fastmath), only the flags `nnan` (no nans) and `ninf` (no infs) can produce poison. And this uses the algebraic float ops to fix https://github.com/rust-lang/rust/issues/120720 cc `@orlp`
2024-02-21Rollup merge of #121361 - pitaj:diag_items-legacy_numeric_constants, r=NilstriebDylan DPC-0/+12
diagnostic items for legacy numeric modules For https://github.com/rust-lang/rust-clippy/pull/12312 Missed these in #121272 r? `@Nilstrieb`
2024-02-20Stabilize `LazyCell` and `LazyLock` (`lazy_cell`)Peter Jaszkowiak-14/+8
2024-02-20diagnostic items for legacy numeric modulesPeter Jaszkowiak-0/+12
2024-02-20Add extra detail to field commentGnome!-1/+2
Co-authored-by: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com>
2024-02-20Reduce alignment of TypeId to u64 alignmentGnomedDev-3/+7
2024-02-20Rollup merge of #121352 - malobre:patch-1, r=NilstriebMatthias Krüger-2/+2
docs: add missing "the" to `str::strip_prefix` doc Fix #121348
2024-02-20Rollup merge of #121277 - reitermarkus:generic-nonzero-convert-num, r=dtolnayMatthias Krüger-367/+325
Refactor trait implementations in `core::convert::num`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 Implement conversion traits using generic `NonZero` type, and refactor all macros to use a consistent format/order of parameters. r? `@dtolnay`
2024-02-20Rollup merge of #119203 - farnoy:simd-masked-intrinsic-docfix, r=RalfJungMatthias Krüger-4/+6
Correct the simd_masked_{load,store} intrinsic docs Explains the uniform pointer being used for these two operations and how elements are offset from it.
2024-02-20Add "algebraic" versions of the fast-math intrinsicsBen Kimock-0/+40
2024-02-20docs: add missing "the" to `str::strip_prefix` docMalobre-2/+2
2024-02-20Auto merge of #121345 - Nilstrieb:rollup-reb0xge, r=Nilstriebbors-180/+219
Rollup of 8 pull requests Successful merges: - #121167 (resolve: Scale back unloading of speculatively loaded crates) - #121196 (Always inline check in `assert_unsafe_precondition` with cfg(debug_assertions)) - #121241 (Implement `NonZero` traits generically.) - #121278 (Remove the "codegen" profile from bootstrap) - #121286 (Rename `ConstPropLint` to `KnownPanicsLint`) - #121291 (target: Revert default to the medium code model on LoongArch targets) - #121302 (Remove `RefMutL` hack in `proc_macro::bridge`) - #121318 (Trigger `unsafe_code` lint on invocations of `global_asm`) Failed merges: - #121206 (Top level error handling) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-20Correct the simd_masked_{load,store} intrinsic docsJakub Okoński-4/+6
2024-02-20Add examples for some methods on slicesTakashiidobe-1/+10