about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2025-02-05Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obkLeón Orell Valerian Liehr-0/+98
#[contracts::requires(...)] + #[contracts::ensures(...)] cc https://github.com/rust-lang/rust/issues/128044 Updated contract support: attribute syntax for preconditions and postconditions, implemented via a series of desugarings that culminates in: 1. a compile-time flag (`-Z contract-checks`) that, similar to `-Z ub-checks`, attempts to ensure that the decision of enabling/disabling contract checks is delayed until the end user program is compiled, 2. invocations of lang-items that handle invoking the precondition, building a checker for the post-condition, and invoking that post-condition checker at the return sites for the function, and 3. intrinsics for the actual evaluation of pre- and post-condition predicates that third-party verification tools can intercept and reinterpret for their own purposes (e.g. creating shims of behavior that abstract away the function body and replace it solely with the pre- and post-conditions). Known issues: * My original intent, as described in the MCP (https://github.com/rust-lang/compiler-team/issues/759) was to have a rustc-prefixed attribute namespace (like rustc_contracts::requires). But I could not get things working when I tried to do rewriting via a rustc-prefixed builtin attribute-macro. So for now it is called `contracts::requires`. * Our attribute macro machinery does not provide direct support for attribute arguments that are parsed like rust expressions. I spent some time trying to add that (e.g. something that would parse the attribute arguments as an AST while treating the remainder of the items as a token-tree), but its too big a lift for me to undertake. So instead I hacked in something approximating that goal, by semi-trivially desugaring the token-tree attribute contents into internal AST constucts. This may be too fragile for the long-term. * (In particular, it *definitely* breaks when you try to add a contract to a function like this: `fn foo1(x: i32) -> S<{ 23 }> { ... }`, because its token-tree based search for where to inject the internal AST constructs cannot immediately see that the `{ 23 }` is within a generics list. I think we can live for this for the short-term, i.e. land the work, and continue working on it while in parallel adding a new attribute variant that takes a token-tree attribute alongside an AST annotation, which would completely resolve the issue here.) * the *intent* of `-Z contract-checks` is that it behaves like `-Z ub-checks`, in that we do not prematurely commit to including or excluding the contract evaluation in upstream crates (most notably, `core` and `std`). But the current test suite does not actually *check* that this is the case. Ideally the test suite would be extended with a multi-crate test that explores the matrix of enabling/disabling contracts on both the upstream lib and final ("leaf") bin crates.
2025-02-04Add OneSidedRangeBound to eliminate panic in `split_point_of`Taylor Cramer-15/+51
See discussion in https://github.com/rust-lang/rust/pull/88502/files#r760177240
2025-02-04Rename slice::take methods to split_offTaylor Cramer-25/+28
2025-02-04Auto merge of #135760 - scottmcm:disjoint-bitor, r=WaffleLapkinbors-3/+113
Add `unchecked_disjoint_bitor` per ACP373 Following the names from libs-api in https://github.com/rust-lang/libs-team/issues/373#issuecomment-2085686057 Includes a fallback implementation so this doesn't have to update cg_clif or cg_gcc, and overrides it in cg_llvm to use `or disjoint`, which [is available in LLVM 18](https://releases.llvm.org/18.1.0/docs/LangRef.html#or-instruction) so hopefully we don't need any version checks.
2025-02-04intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even ↵Ralf Jung-112/+73
intrinsic
2025-02-04Auto merge of #136534 - jhpratt:rollup-dnz57dq, r=jhprattbors-2/+151
Rollup of 6 pull requests Successful merges: - #136398 (add UnsafeCell direct access APIs) - #136465 (Some `rustc_middle` cleanups) - #136479 (std::fs: further simplify dirent64 handling) - #136504 (Fix last compare-mode false negatives in tests) - #136511 (Add `cast_signed` and `cast_unsigned` methods for `NonZero` types) - #136518 (Add note about `FnPtr` trait being exposed as public bound) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-04Auto merge of #136533 - jhpratt:rollup-s0ign8n, r=jhprattbors-168/+184
Rollup of 5 pull requests Successful merges: - #134777 (Enable more tests on Windows) - #135621 (Move some std tests to integration tests) - #135844 ( Add new tool for dumping feature status based on tidy ) - #136167 (Implement unstable `new_range` feature) - #136334 (Extract `core::ffi` primitives to a separate (internal) module) Failed merges: - #136201 (Removed dependency on the field-offset crate, alternate approach) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-04Rollup merge of #136518 - Urgau:fn_ptr-public-bound, r=NoratriebJacob Pratt-0/+3
Add note about `FnPtr` trait being exposed as public bound
2025-02-04Rollup merge of #136511 - joshtriplett:nonzero-cast-signed-unsigned, r=dtolnayJacob Pratt-2/+64
Add `cast_signed` and `cast_unsigned` methods for `NonZero` types Requested in https://github.com/rust-lang/rust/issues/125882 . Note that this keeps the same names as the methods currently present on other integer types. If we want to rename them, we can rename them all at the same time.
2025-02-04Rollup merge of #136398 - pitaj:unsafecell_access, r=dtolnayJacob Pratt-0/+84
add UnsafeCell direct access APIs - Implementation for ACP: https://github.com/rust-lang/libs-team/issues/521 - Tracking issue #136327
2025-02-04Rollup merge of #136334 - ricci009:primitivers, r=tgross35Jacob Pratt-168/+181
Extract `core::ffi` primitives to a separate (internal) module ### Introduce library/core/src/ffi/primitives.rs The regex preprocessing for PR #133944 would be more robust if the relevant types from core/src/ffi/mod.rs were first moved to library/core/src/ffi/primitives.rs, then there isn't a need to deal with traits / c_str / va_list / whatever might wind up in that module in the future r? `@tgross35`
2025-02-04Rollup merge of #136167 - pitaj:new_range, r=NadrierilJacob Pratt-0/+3
Implement unstable `new_range` feature Switches `a..b`, `a..`, and `a..=b` to resolve to the new range types. For rust-lang/rfcs#3550 Tracking issue #123741 also adds the re-export that was missed in the original implementation of `new_range_api`
2025-02-04Auto merge of #135265 - pascaldekloe:fmt-int-speed, r=tgross35,ChrisDentonbors-68/+75
Display of integers without raw pointers and without overflowing_literals The benchmarks as is measure formatting speed of literals. The first commit `black_box`-es input to simulate runtime speed instead. The second commit replaces `unsafe` pointer optimizations with plain array indices. The performance is equivalent on Apple M1. Needs peer review on Intel. Happy to do the 128-bit version too if such change is welcome.
2025-02-04specify a prim@slice in docsmay-1/+1
i am not quite sure how this failure is in any way related to this pr, since i am only touching inherent functions on str? but sure.
2025-02-04implement inherent str constructorsmay-0/+176
2025-02-03Add note about `FnPtr` being exposed as public boundUrgau-0/+3
2025-02-03primitive type migration from mod.rs to primitives.rsricci009-168/+181
2025-02-03Rename rustc_contract to contractCelina G. Val-10/+10
This has now been approved as a language feature and no longer needs a `rustc_` prefix. Also change the `contracts` feature to be marked as incomplete and `contracts_internals` as internal.
2025-02-03Improve contracts intrisics and remove wrapper functionCelina G. Val-26/+23
1. Document the new intrinsics. 2. Make the intrinsics actually check the contract if enabled, and remove `contract::check_requires` function. 3. Use panic with no unwind in case contract is using to check for safety, we probably don't want to unwind. Following the same reasoning as UB checks.
2025-02-03Separate contract feature gates for the internal machineryFelix S. Klock II-11/+11
The extended syntax for function signature that includes contract clauses should never be user exposed versus the interface we want to ship externally eventually.
2025-02-03Desugars contract into the internal AST extensionsFelix S. Klock II-0/+31
Check ensures on early return due to Try / Yeet Expand these two expressions to include a call to contract checking
2025-02-03Add `cast_signed` and `cast_unsigned` methods for `NonZero` typesJosh Triplett-0/+47
2025-02-03Express contracts as part of function header and lower it to the contract ↵Celina G. Val-1/+1
lang items includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
2025-02-03contracts: added lang items that act as hooks for rustc-injected code to invoke.Felix S. Klock II-0/+38
see test for an example of the kind of injected code that is anticipated here.
2025-02-03Contracts core intrinsics.Felix S. Klock II-0/+32
These are hooks to: 1. control whether contract checks are run 2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-03Mark `std::fmt::from_fn` as `#[must_use]`Yotam Ofek-0/+1
2025-02-03Rollup merge of #136289 - Pyr0de:oncecell-docs, r=tgross35Matthias Krüger-25/+28
OnceCell & OnceLock docs: Using (un)initialized consistently Changed * `set` / `initialize` / `full` to `initialized state` * `uninitialize` / `empty` to `uninitialized state` * `f` to `f()` * Added explaination of `uninitialized state` & `initialized state` [OnceCell Docs](https://doc.rust-lang.org/nightly/std/cell/struct.OnceCell.html) [OnceLock Docs](https://doc.rust-lang.org/nightly/std/sync/struct.OnceLock.html) Fixes #85716 ``@rustbot`` label +A-docs
2025-02-03no unsafe pointer and no overflowing_literals in fmt::Display of integersPascal S. de Kloe-68/+75
2025-02-03For NonZero impl macros, give unsigned impls access to the corresponding ↵Josh Triplett-2/+17
signed type There was a macro parameter giving signed impls access to the corresponding unsigned type, but not the other way around. This will allow implementing methods converting in both directions.
2025-02-03OnceCell & OnceLock docs: Using (un)initialized consistentlyPyrode-25/+28
2025-02-02Docs for f16 and f128: correct a typo and add detailsLaine Taffin Altman-7/+7
2025-02-02Rollup merge of #136434 - ↵Matthias Krüger-1/+5
RalfJung:rustc_allowed_through_unstable_modules-deprecation-required, r=compiler-errors rustc_allowed_through_unstable_modules: require deprecation message This changes the `#[rustc_allowed_through_unstable_modules]` attribute so that a deprecation message (ideally directing people towards the stable path) is required.
2025-02-02Rollup merge of #136283 - hkBst:patch-31, r=workingjubileeMatthias Krüger-4/+5
Update encode_utf16 to mention it is native endian Fixes #83102
2025-02-02Rollup merge of #134272 - RalfJung:destabilize-rustc_encodable_decodable, ↵Matthias Krüger-38/+0
r=oli-obk Remove rustc_encodable_decodable feature This has been shown in future-compat reports since Rust 1.79 (https://github.com/rust-lang/rust/pull/116016), released June 2024. Let's see if crater still finds any issues. Part of https://github.com/rust-lang/rust/issues/134301. Cc ``@rust-lang/libs-api``
2025-02-02rustc_allowed_through_unstable_modules: require deprecation messageRalf Jung-1/+5
2025-02-01Use `widening_mul`Tobias Decking-20/+1
2025-02-01add UnsafeCell direct access APIsPeter Jaszkowiak-0/+84
2025-02-01Rollup merge of #136364 - hkBst:ptr_cmp_docs, r=tgross35Matthias Krüger-3/+8
document that ptr cmp is unsigned Fixes #77497
2025-02-01Rollup merge of #136307 - WaffleLapkin:minminmin, r=scottmcmMatthias Krüger-33/+137
Implement all mix/max functions in a (hopefully) more optimization amendable way Previously the graph was like this: ``` min -> Ord::min -> min_by -> match on compare() (in these cases compare = Ord::cmp) ^ | min_by_key ``` now it looks like this: ``` min -> Ord::min -> `<=` <- min_by_key min_by -> `Ordering::is_le` of `compare()` ``` (`max*` and `minmax*` are the exact same, i.e. they also use `<=` and `is_le`) I'm not sure how to test this, but it should probably be easier for the backend to optimize. r? `@scottmcm` cc https://github.com/rust-lang/rust/issues/115939#issuecomment-2622161134
2025-02-01document ptr comparison being by addressMarijn Schouten-3/+8
2025-01-31More PR feedbackScott McMurray-7/+5
2025-01-31PR feedbackScott McMurray-9/+8
2025-01-31Add `unchecked_disjoint_bitor` with fallback intrinsic implementationScott McMurray-3/+116
2025-02-01Rollup merge of #136351 - Darksonn:coerce-pointee-docs, r=compiler-errorsMatthias Krüger-1/+189
Add documentation for derive(CoercePointee) Part of [RFC 3621][rfc] tracked by #123430. This text is heavily based on the guide-level explanation from the RFC. ``@rustbot`` label F-derive_coerce_pointee [rfc]: https://rust-lang.github.io/rfcs/3621-derive-smart-pointer.html
2025-02-01Rollup merge of #136163 - uellenberg:driftsort-off-by-one, r=Mark-SimulacrumMatthias Krüger-8/+22
Fix off-by-one error causing slice::sort to abort the program Fixes #136103. Based on the analysis by ``@jonathan-gruber-jg`` and ``@orlp.``
2025-01-31doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmoveMarijn Schouten-3/+6
2025-01-31Auto merge of #134424 - 1c3t3a:null-checks, r=saethlinbors-0/+16
Insert null checks for pointer dereferences when debug assertions are enabled Similar to how the alignment is already checked, this adds a check for null pointer dereferences in debug mode. It is implemented similarly to the alignment check as a `MirPass`. This inserts checks in the same places as the `CheckAlignment` pass and additionally also inserts checks for `Borrows`, so code like ```rust let ptr: *const u32 = std::ptr::null(); let val: &u32 = unsafe { &*ptr }; ``` will have a check inserted on dereference. This is done because null references are UB. The alignment check doesn't cover these places, because in `&(*ptr).field`, the exact requirement is that the final reference must be aligned. This is something to consider further enhancements of the alignment check. For now this is implemented as a separate `MirPass`, to make it easy to disable this check if necessary. This is related to a 2025H1 project goal for better UB checks in debug mode: https://github.com/rust-lang/rust-project-goals/pull/177. r? `@saethlin`
2025-01-31Add documentation for derive(CoercePointee)Alice Ryhl-1/+189
2025-01-31Insert null checks for pointer dereferences when debug assertions are enabledBastian Kersting-0/+16
Similar to how the alignment is already checked, this adds a check for null pointer dereferences in debug mode. It is implemented similarly to the alignment check as a MirPass. This is related to a 2025H1 project goal for better UB checks in debug mode: https://github.com/rust-lang/rust-project-goals/pull/177.
2025-01-31Update encode_utf16 to mention it is native endianMarijn Schouten-4/+5