about summary refs log tree commit diff
path: root/library/core/src/ops
AgeCommit message (Collapse)AuthorLines
2025-09-27move Reborrow to ops, fix fmt issuesAapo Alasuutari-2/+8
2025-09-15fix: Move CoerceShared into opsAapo Alasuutari-0/+13
2025-09-12Constify Eq, Ord, PartialOrdEvgenii Zheltonozhskii-1/+2
2025-09-06clean up some old const trait impl syntaxNathaniel McCallum-66/+33
2025-09-04Rollup merge of #146136 - ↵Stuart Cook-0/+1
AudaciousAxiom:docs/missing-closing-code-block-fences, r=tgross35 docs(std): add missing closing code block fences in doc comments This PR adds a few closing code block fences which I believe are missing in some doc comments. It seems that rustdoc just autocloses code blocks at the end of doc comments and thus these were easily overlooked: I do not think these code blocks are special in any way. I found these when working on a Clippy lint that checks the last sentence of doc comments for terminal punctuation, and these were failing cases when testing against the std. Therefore I am not entirely sure these are all such cases, but still have high hopes that they are (or at least a well-defined subset of them).
2025-09-03Rollup merge of #145279 - clarfonthey:const-convert-initial, r=tgross35Stuart Cook-5/+5
Constify conversion traits (part 1) This is the first part of rust-lang/rust#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` There are a few methods that are intrinsically tied to these traits which I've included in the feature. Particularly, those which are wrappers over `AsRef`: * `ByteStr::new` (unstable under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as rust-lang/rust#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? ``@tgross35`` (who mostly already reviewed this)
2025-09-02docs(std): add missing closing code block fences in doc commentsAudaciousAxiom-0/+1
2025-09-01Constify conversion traitsltdk-5/+5
2025-09-01constify impl Try for ControlFlowNathaniel McCallum-2/+4
2025-08-30Add `#[must_use] and update `cloned` documentationConnor Tsui-2/+6
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com> Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2025-08-30add feature gate in doc testConnor Tsui-0/+2
2025-08-30add `Bound::copied`Connor Tsui-0/+22
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-12fix typoAda Alakbarova-1/+1
2025-08-10Constify remaining operatorsltdk-42/+118
2025-08-10Let forward_ref_* macros accept multiple attributes, and require attributes ↵ltdk-24/+48
explicitly
2025-08-07Auto merge of #145043 - Zalathar:rollup-3dbvdrm, r=Zalatharbors-0/+147
Rollup of 19 pull requests Successful merges: - rust-lang/rust#137831 (Tweak auto trait errors) - rust-lang/rust#138689 (add nvptx_target_feature) - rust-lang/rust#140267 (implement continue_ok and break_ok for ControlFlow) - rust-lang/rust#143028 (emit `StorageLive` and schedule `StorageDead` for `let`-`else`'s bindings after matching) - rust-lang/rust#143764 (lower pattern bindings in the order they're written and base drop order on primary bindings' order) - rust-lang/rust#143808 (Port `#[should_panic]` to the new attribute parsing infrastructure ) - rust-lang/rust#143906 (Miri: non-deterministic floating point operations in `foreign_items`) - rust-lang/rust#143929 (Mark all deprecation lints in name resolution as deny-by-default and report-in-deps) - rust-lang/rust#144133 (Stabilize const TypeId::of) - rust-lang/rust#144369 (Upgrade semicolon_in_expressions_from_macros from warn to deny) - rust-lang/rust#144439 (Introduce ModernIdent type to unify macro 2.0 hygiene handling) - rust-lang/rust#144473 (Address libunwind.a inconsistency issues in the bootstrap program) - rust-lang/rust#144601 (Allow `cargo fix` to partially apply `mismatched_lifetime_syntaxes`) - rust-lang/rust#144650 (Additional tce tests) - rust-lang/rust#144659 (bootstrap: refactor mingw dist and fix gnullvm) - rust-lang/rust#144682 (Stabilize `strict_overflow_ops`) - rust-lang/rust#145026 (Update books) - rust-lang/rust#145033 (Reimplement `print_region` in `type_name.rs`.) - rust-lang/rust#145040 (rustc-dev-guide subtree update) Failed merges: - rust-lang/rust#143857 (Port #[macro_export] to the new attribute parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-06tidyBoxy-8/+8
2025-07-29Rollup merge of #144167 - zachs18:rangebounds-not-unsized-reason, r=tgross35Stuart Cook-0/+30
Document why `Range*<&T> as RangeBounds<T>` impls are not `T: ?Sized`, and give an alternative. `Range*<&T> as RangeBounds<T>` impls have been tried to be relaxed to `T: ?Sized` at least twice: * https://github.com/rust-lang/rust/pull/61584 * https://github.com/rust-lang/rust/pull/64327 I also was just about to make another PR to do it again until I `./x.py test library/alloc` and rediscovered the type inference regression, then searched around and found the previous PRs. Hence this PR instead so hopefully that doesn't keep happening :stuck_out_tongue:. These impls cannot be relaxed for two reasons: 1. Type inference regressions: See ``@SimonSapin's`` explanation from a previous PR: https://github.com/rust-lang/rust/pull/61584#issuecomment-499601046 2. It's a breaking change: `impl RangeBounds<MyUnsizedType> for std::ops::Range<&MyUnsizedType>` is allowed after the coherence rebalance ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f704a6fe53bfc33e55b2fc246d895ec2)), and relaxing these impls would conflict with that downstream impl. This PR adds doc-comments explaining that not having `T: ?Sized` is intentional[^1], and gives an explicit alternative: `(Bound<&T>, Bound<&T>)`. Technically, the impls for the unstable new `std::range` types could be relaxed, as they are still unstable so the change would not be breaking, but having them be different in this regard seems worse (and the non-iterable `RangeTo/RangeToInclusive` range types are shared between the "new" and "old" so cannot be changed anyway), and then the type inference regression would pop up in whatever edition the new range types stabilize in. The "see \<link\> for discussion of those issues" is intentionally left as a non-doc comment just for whoever may try to relax these impls again in the future, but if it is preferred to have the link in the docs I can add that. Closes https://github.com/rust-lang/rust/issues/107196 (as wontfix) CC https://github.com/rust-lang/rust/issues/64027 [^1]: "intentional" is maybe a bit of strong wording, should it instead say something like "was stabilized without it and it would be breaking to change it now"?
2025-07-25Rollup merge of #143424 - hkBst:auto-deref, r=jhprattMatthias Krüger-3/+3
clippy fix: rely on autoderef Changes instances of `&**self` to `self`.
2025-07-23Document (internally) that `Range*<&T> as RangeBounds<T>` impls are ↵Zachary S-0/+30
intentionally not `T: ?Sized`, and document (publically) an alternative.
2025-07-21Constify Try, From, TryFromEvgenii Zheltonozhskii-1/+7
2025-07-15constify `Index` trait and its slice implsOli Scherer-1/+5
2025-07-13update issue number for `const_trait_impl`Deadbeef-8/+8
2025-07-11fix const_ops tracking issueRalf Jung-12/+12
2025-07-10Rollup merge of #143640 - oli-obk:const-fn-traits, r=compiler-errorsMatthias Krüger-13/+21
Constify `Fn*` traits r? `@compiler-errors` `@fee1-dead` this should unlock a few things. A few `const_closures` tests have broken even more than before, but that feature is marked as incomplete anyway cc rust-lang/rust#67792
2025-07-08Rollup merge of #143426 - hkBst:clippy-fix-indent-1, r=jhprattTrevor Gross-1/+1
clippy fix: indentation Fixes indentation of markdown comments.
2025-07-08Constify `Fn*` traitsOli Scherer-13/+21
2025-07-04Rollup merge of #143040 - SciMind2460:patch-1, r=workingjubileeJubilee-1/+1
Add `const Rem`
2025-07-04Make Rem const for floatsKurt Heiritz (pseudo)-1/+1
2025-07-04clippy fix: indentationMarijn Schouten-1/+1
2025-07-04clippy fix: rely on autoderefMarijn Schouten-3/+3
2025-07-02Remove some unsized tuple impls now that we don't support unsizing tuples ↵Oli Scherer-1/+1
anymore
2025-06-25Add Sub, Mul, Div, Rem as const_traitsKurt Heiritz (pseudo)-5/+19
2025-06-16lint: don't consider sizedness in upcastable lintDavid Wood-1/+0
Adding a sizedness supertrait shouldn't require multiple vtables so shouldn't be linted against.
2025-06-16library/compiler: add `PointeeSized` boundsDavid Wood-22/+25
As core uses an extern type (`ptr::VTable`), the default `?Sized` to `MetaSized` migration isn't sufficient, and some code that previously accepted `VTable` needs relaxed to continue to accept extern types. Similarly, the compiler uses many extern types in `rustc_codegen_llvm` and in the `rustc_middle::ty::List` implementation (`OpaqueListContents`) some bounds must be relaxed to continue to accept these types. Unfortunately, due to the current inability to relax `Deref::Target`, some of the bounds in the standard library are forced to be stricter than they ideally would be.
2025-06-12Tracking the old name of renamed unstable library attributexizheyin-10/+10
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-27Auto merge of #129658 - saethlin:spare-a-crumb, r=jhprattbors-0/+1
Add some track_caller info to precondition panics Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful. I thought of this while looking at https://github.com/rust-lang/rust/pull/129642#issuecomment-2311703898. The changes to `tests/ui/const*` happen because the const-eval interpreter skips `#[track_caller]` frames in its backtraces. The perf implications of this are: * Increased debug binary sizes. The caller_location implementation requires that the additional data we want to display here be stored in const allocations, which are deduplicated but not across crates. There is no impact on optimized build sizes. The panic path and the caller location data get optimized out. * The compile time hit to opt-incr-patched bitmaps happens because the patch changes the line number of some function calls with precondition checks, causing us to go from 0 dirty CGUs to 1 dirty CGU. * The other compile time hits are marginal but real, and due to doing a handful of new queries. Adding more useful data isn't completely free.
2025-05-21Add some track_caller info to precondition panicsBen Kimock-0/+1
2025-05-17Switch library rustc_unimplemented to use `Self` and `This`mejrs-17/+17
2025-05-12update cfg(bootstrap)Pietro Albini-2/+2
2025-04-28Auto merge of #123948 - azhogin:azhogin/async-drop, r=oli-obkbors-8/+0
Async drop codegen Async drop implementation using templated coroutine for async drop glue generation. Scopes changes to generate `async_drop_in_place()` awaits, when async droppable objects are out-of-scope in async context. Implementation details: https://github.com/azhogin/posts/blob/main/async-drop-impl.md New fields in Drop terminator (drop & async_fut). Processing in codegen/miri must validate that those fields are empty (in full version async Drop terminator will be expanded at StateTransform pass or reverted to sync version). Changes in terminator visiting to consider possible new successor (drop field). ResumedAfterDrop messages for panic when coroutine is resumed after it is started to be async drop'ed. Lang item for generated coroutine for async function async_drop_in_place. `async fn async_drop_in_place<T>()::{{closure0}}`. Scopes processing for generate async drop preparations. Async drop is a hidden Yield, so potentially async drops require the same dropline preparation as for Yield terminators. Processing in StateTransform: async drops are expanded into yield-point. Generation of async drop of coroutine itself added. Shims for AsyncDropGlueCtorShim, AsyncDropGlue and FutureDropPoll. ```rust #[lang = "async_drop"] pub trait AsyncDrop { #[allow(async_fn_in_trait)] async fn drop(self: Pin<&mut Self>); } impl Drop for Foo { fn drop(&mut self) { println!("Foo::drop({})", self.my_resource_handle); } } impl AsyncDrop for Foo { async fn drop(self: Pin<&mut Self>) { println!("Foo::async drop({})", self.my_resource_handle); } } ``` First async drop glue implementation re-worked to use the same drop elaboration code as for sync drop. `async_drop_in_place` changed to be `async fn`. So both `async_drop_in_place` ctor and produced coroutine have their lang items (`AsyncDropInPlace`/`AsyncDropInPlacePoll`) and shim instances (`AsyncDropGlueCtorShim`/`AsyncDropGlue`). ``` pub async unsafe fn async_drop_in_place<T: ?Sized>(_to_drop: *mut T) { } ``` AsyncDropGlue shim generation uses `elaborate_drops::elaborate_drop` to produce drop ladder (in the similar way as for sync drop glue) and then `coroutine::StateTransform` to convert function into coroutine poll. AsyncDropGlue coroutine's layout can't be calculated for generic T, it requires known final dropee type to be generated (in StateTransform). So, `templated coroutine` was introduced here (`templated_coroutine_layout(...)` etc). Such approach overrides the first implementation using mixing language-level futures in https://github.com/rust-lang/rust/pull/121801.
2025-04-28AsyncDrop implementation using shim codegen of ↵Andrew Zhogin-8/+0
async_drop_in_place::{closure}, scoped async drop added.
2025-04-26moved simple test to coretests, introduced more fleshed out doctests for ↵Jonathan Gruner-4/+107
break_ok/continue_ok
2025-04-24implement continue_ok and break_ok for ControlFlowJonathan Gruner-0/+44
2025-04-20Add `#[rustc_no_implicit_autorefs]` and apply it to std methodsUrgau-0/+2
2025-04-05Polymorphize `array::IntoIter`'s iterator implScott McMurray-0/+55
2025-03-16Make ControlFlow must_useMichael Goulet-0/+1
2025-03-06Remove #[cfg(not(test))] gates in coreThalia Archibald-1/+1
These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-03fix order on shl implSpeedy_Lex-1/+1
this doesn't fix any bugs, it just looks more consistent with the other impl's
2025-03-01fix `RangeBounds::is_empty` documentationPeter Jaszkowiak-1/+1
One-sided ranges are never empty