about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-12-22Auto merge of #118847 - eholk:for-await, r=compiler-errorsbors-0/+1
Add support for `for await` loops This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library. Given a loop like: ```rust for await i in iter { ... } ``` this is desugared to something like: ```rust let mut iter = iter.into_async_iter(); while let Some(i) = loop { match core::pin::Pin::new(&mut iter).poll_next(cx) { Poll::Ready(i) => break i, Poll::Pending => yield, } } { ... } ``` This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this. I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue. r? `@compiler-errors`
2023-12-20Auto merge of #119037 - RalfJung:repr-c-abi-mismatch, r=scottmcmbors-2/+0
do not allow ABI mismatches inside repr(C) types In https://github.com/rust-lang/rust/pull/115476 we allowed ABI mismatches inside `repr(C)` types. This wasn't really discussed much; I added it because from how I understand calling conventions, this should actually be safe in practice. However I entirely forgot to actually allow this in Miri, and in the mean time I have learned that too much ABI compatibility can be a problem for CFI (it can reject fewer calls so that gives an attacker more room to play with). So I propose we take back that part about ABI compatibility in `repr(C)`. It is anyway something that C and C++ do not allow, as far as I understand. In the future we might want to introduce a class of ABI compatibilities where we say "this is a bug and it may lead to aborting the process, but it won't lead to arbitrary misbehavior -- worst case it'll just transmute the arguments from the caller type to the callee type". That would give CFI leeway to reject such calls without introducing the risk of arbitrary UB. (The UB can still happen if the transmute leads to bad results, of course, but it wouldn't be due to ABI weirdness.) #115476 hasn't reached beta yet so if we land this before Dec 22nd we can just pretend this all never happened. ;) Otherwise we should do a beta backport (of the docs change at least). Cc `@rust-lang/opsem` `@rust-lang/types`
2023-12-19Desugar for await loopsEric Holk-0/+1
2023-12-18Disable new intrinsics for bootstrapCaleb Zulawski-0/+2
2023-12-17Add new intrinsicsCaleb Zulawski-0/+39
2023-12-17Further explain semanticsCaleb Zulawski-2/+13
2023-12-17Apply suggestions from code reviewCaleb Zulawski-2/+3
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-12-17Improve simd_bitmask documentation and other minor fixesCaleb Zulawski-8/+15
2023-12-17State type requirements firstCaleb Zulawski-61/+62
2023-12-17Clarify UB and improve grammarCaleb Zulawski-4/+4
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-12-17Add core::intrinsics::simdCaleb Zulawski-0/+413
2023-12-17do not allow ABI mismatches inside repr(C) typesRalf Jung-2/+0
2023-12-15Rollup merge of #118523 - okaneco:trim_ascii, r=Mark-SimulacrumJubilee-0/+82
Add ASCII whitespace trimming functions to `&str` - Add `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` functions to `&str` for trimming ASCII whitespace - Add `#[inline]` to `[u8]` `trim_ascii` functions These functions are feature-gated by `#![feature(byte_slice_trim_ascii)]` #94035
2023-12-15Rollup merge of #118998 - jstasiak:improve-doc, r=workingjubileeJubilee-1/+1
Link to is_benchmark from the Ipv6Addr::is_global documentation All other relevant is_* methods are mentioned in the list of addresses here, is_benchmarking has been the only one missing.
2023-12-15Rollup merge of #118956 - danielhuang:patch-2, r=workingjubileeJubilee-2/+2
Make CStr documentation consistent ("nul" instead of "null") "nul" is used in method names and appears more often in the documentation than "null", so make all instances "nul" to keep it consistent.
2023-12-15Add link to is_benchmark from the Ipv6Addr::is_global documentationJakub Stasiak-1/+1
All other relevant is_* methods are mentioned in the list of addresses here, is_benchmarking has been the only one missing.
2023-12-15Rollup merge of #118234 - tgross35:type_name_of_value, r=dtolnayMatthias Krüger-21/+18
Stabilize `type_name_of_val` Make the following API stable: ```rust // in core::any pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str ``` This is a convenience method to get the type name of a value, as opposed to `type_name` that takes a type as a generic. Const stability is not added because this relies on `type_name` which is also not const. That has a blocking issue https://github.com/rust-lang/rust/issues/97156. Wording was also changed to direct most of the details to `type_name` so we don't have as much duplicated documentation. Fixes tracking issue #66359. There were two main concerns in the tracking issue: 1. Naming: `type_name_of` and `type_name_of_val` seem like the only mentioned options. Differences in opinion here come from `std::mem::{size_of, align_of, size_of_val, align_of_val}`. This PR leaves the name as `type_name_of_val`, but I can change if desired since it is pretty verbose. 2. What this displays for `&dyn`: I don't think that having `type_name_of_val` function resolve those is worth the headache it would be, see https://github.com/rust-lang/rust/issues/66359#issuecomment-1718480774 for some workarounds. I also amended the docs wording to leave it open-ended, in case we have means to change that behavior in the future. ``@rustbot`` label -T-libs +T-libs-api +needs-fcp r? libs-api
2023-12-15Stabilize `ptr::{from_ref, from_mut}`Maybe Waffle-2/+5
2023-12-14Update c_str.rsDaniel Huang-2/+2
2023-12-13Auto merge of #117050 - c410-f3r:here-we-go-again, r=petrochenkovbors-0/+143
[`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at https://github.com/rust-lang/rust/issues/83527#issuecomment-1744822345 to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
2023-12-12Rollup merge of #118873 - lukas-code:fix_waker_getter_tracking_issue_number, ↵Jubilee-3/+3
r=workingjubilee fix `waker_getters` tracking issue number The feature currently links to the closed issue https://github.com/rust-lang/rust/issues/87021. Make it link to the tracking issue https://github.com/rust-lang/rust/issues/96992 instead.
2023-12-12Rollup merge of #118858 - mu001999:dead_code/clean, r=cuviperJubilee-3/+3
Remove dead codes in core Detected by #118257
2023-12-12Add ASCII whitespace trimming functions to `&str`okaneco-0/+82
Add `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` functions to `&str` for trimming ASCII whitespace under the `byte_slice_trim_ascii` feature gate. Add `inline` to `[u8]` `trim_ascii` functions
2023-12-12fix `waker_getters` tracking issue numberLukas Markeffsky-3/+3
2023-12-12Remove dead codes in corer01and-3/+3
2023-12-11Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwcobors-0/+16
Add lint against ambiguous wide pointer comparisons This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang. ## `ambiguous_wide_pointer_comparisons` *warn-by-default* The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands. ### Example ```rust let ab = (A, B); let a = &ab.0 as *const dyn T; let b = &ab.1 as *const dyn T; let _ = a == b; ``` ### Explanation The comparison includes metadata which may not be expected. ------- This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one. ~~One thing: is the current naming right? `invalid` seems a bit too much.~~ Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, ↵bors-0/+12
r=compiler-errors Restore `const PartialEq` And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now. r? `@compiler-errors`
2023-12-11Auto merge of #118032 - RalfJung:char-u32, r=Mark-Simulacrumbors-4/+5
guarantee that char and u32 are ABI-compatible In https://github.com/rust-lang/rust/pull/116894 we added a guarantee that `char` has the same alignment as `u32`, but there is still one axis where these types could differ: function call ABI. So let's nail that down as well: in a function signature, `char` and `u32` are completely equivalent. This is a new stable guarantee, so it will need t-lang approval.
2023-12-10Restore `const PartialEq`Deadbeef-0/+12
2023-12-10remove redundant importssurechen-35/+20
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-08Implement `async gen` blocksMichael Goulet-0/+25
2023-12-08Rollup merge of #118505 - CLEckhardt:update_ip_addr_bits_docs, r=cuviperMatthias Krüger-4/+48
Elaborate on ip_addr bit conversion endianness Adds explanation of how endianness is handled when converting `Ipv4Addr` and `Ipv6Addr` to and from bits. This is intended to unblock stabilization of the affected methods. Addresses #113744
2023-12-07Elaborate on ip_addr bit conversion endiannessChris Eckhardt-4/+48
Adds explanation of how endianness is handled when converting `Ipv4Addr` and `Ipv6Addr` to and from bits. Addresses #113744
2023-12-06Allow ambiguous_wide_pointer_comparisons lint for std methodsUrgau-0/+14
2023-12-05Rollup merge of #118450 - marcin-serwin:master, r=workingjubileeMichael Goulet-4/+4
Use OnceCell in cell module documentation The spanning tree example in the std cell module implementation was created before `OnceCell` was added to Rust so it uses `RefCell`. However, in this case using `OnceCell` seems more appropriate and produces simpler code. As a bonus, this also means that all three cell types are presented in the examples of std cell module.
2023-12-05Rollup merge of #118350 - DaniPopes:tuple-default, r=workingjubileeMichael Goulet-9/+6
Simplify Default for tuples Doesn't need a separate block for each element
2023-12-05Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errorsMichael Goulet-0/+7
Add support for making lib features internal We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug. This extends that idea to lib features as well. It is an alternative to https://github.com/rust-lang/rust/pull/115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal. Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes https://github.com/rust-lang/rust/issues/115597.
2023-12-05Stabilize `type_name_of_val`Trevor Gross-21/+18
Make the following API stable: // in core::any pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str Const stability is not added because this relies on `type_name` which is also not const. That has a blocking issue. Fixes #66359
2023-12-05Auto merge of #118362 - RalfJung:panic_nounwind, r=thomccbors-3/+6
make sure panic_nounwind_fmt can still be fully inlined (e.g. for panic_immediate_abort) Follow-up to https://github.com/rust-lang/rust/pull/110303.
2023-12-04Improve example in `slice::windows()` docGurinder Singh-5/+5
Now using a window of 3 instead 2 because it removes any confusion about exactly how consecutive windows overlap
2023-12-04Auto merge of #116915 - bend-n:unwet, r=saethlinbors-1/+4
Add an assume that the index is inbounds to slice::get_unchecked Fixes #116878
2023-12-04use `assume(idx < self.len())` in `[T]::get_unchecked`bendn-1/+4
2023-12-03move calling miri_promise_symbolic_alignment to a shared helperRalf Jung-65/+38
2023-12-03miri: support 'promising' alignment for symbolic alignment checkRalf Jung-6/+85
2023-12-03Auto merge of #118487 - RalfJung:exposed-provenance, r=thomccbors-56/+70
move exposed-provenance APIs into separate feature gate We have already stated explicitly for all the 'exposed' functions that > Using this method means that code is *not* following strict provenance rules. However, they were part of the same feature gate and still described as part of the strict provenance experiment. Unfortunately, their semantics are much less clear and certainly nowhere near stabilization, so in preparation for an attempt to stabilize the strict provenance APIs, I suggest we split the things related to "exposed" into their own feature gate. I also used this opportunity to better explain how Exposed Provenance fits into the larger plan here: this is *one possible candidate* for `as` semantics, but we don't know if it is actually viable, so we can't really promise that it is equivalent to `as`. If it works out we probably want to make `as` equivalent to the 'exposed' APIs; if it doesn't, we will remove them again and try to find some other semantics for `as`.
2023-12-03Auto merge of #118128 - RalfJung:bad-intrinsics, r=the8472bors-0/+10
warn against using intrinsics that leave the scope of our memory model
2023-12-02Auto merge of #118077 - calebzulawski:sync-portable-simd-2023-11-19, ↵bors-13/+13
r=workingjubilee Portable SIMD subtree update Syncs nightly to the latest changes from rust-lang/portable-simd r? `@rust-lang/libs`
2023-12-02Add diagnostic item to PartialEq::{eq,ne}Urgau-0/+2
2023-12-01Attempt to try to resolve blocking concernsCaio-0/+143
2023-12-01update addr docsRalf Jung-8/+8