about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-07-05Auto merge of #113287 - RalfJung:miri-test-libstd, r=JohnTitorbors-1/+0
enable test_join test in Miri Miri for quite a while now has a hack to support self-referential generators: non-`Unique` mutable references are exempt from aliasing conditions. So we can run this test now. (It passes.) Also extend a comment in a Vec test, while I am at it.
2023-07-05Add support for NetBSD/riscv64 aka. riscv64gc-unknown-netbsd.Havard Eidnes-1/+6
2023-07-03enable test_join test in MiriRalf Jung-1/+0
2023-07-01Auto merge of #113194 - lu-zero:intrinsics-inline, r=thomccbors-3/+3
Mark wrapped intrinsics as inline(always) This should mitigate having the inliner decide not to inline when the architecture is lacking an implementation of TargetTransformInfo::areInlineCompatible aware of the target features (e.g. PowerPC as today). See https://github.com/rust-lang/stdarch/pull/1443#issuecomment-1613788080
2023-07-01Rollup merge of #113072 - tshepang:patch-1, r=cuviperMatthias Krüger-40/+0
str docs: remove "Basic usage" text where not useful Not "useful" in that there is only one example given
2023-06-30Mark wrapped intrinsics as inline(always)Luca Barbato-3/+3
This should mitigate having the inliner decide not to inline when the architecture is lacking an implementation of TargetTransformInfo::areInlineCompatible aware of the target features (e.g. PowerPC as today).
2023-06-30Rollup merge of #107624 - tgross35:const-cstr-methods, r=dtolnayMatthias Krüger-8/+10
Stabilize `const_cstr_methods` This PR seeks to stabilize `const_cstr_methods`. Fixes most of #101719 ## New const stable API ```rust impl CStr { // depends: memchr pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError> {...} // depends: const_slice_index pub const fn to_bytes(&self) -> &[u8] {} // depends: pointer casts pub const fn to_bytes_with_nul(&self) -> &[u8] {} // depends: str::from_utf8 pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {} } ``` I don't think any of these methods will have any issue when `CStr` becomes a thin pointer as long as `memchr` is const (which also allows for const `strlen`) . ## Notes - `from_bytes_until_nul` relies on `const_slice_index`, which relies on `const_trait_impls`, and generally this should be avoided. After talking with Oli, it should be OK in this case because we could replace the ranges with pointer tricks if needed (worst case being those feature gates disappear). https://github.com/rust-lang/rust/pull/107624#discussion_r1101468480 - Making `from_ptr` const is deferred because it depends on `const_eval_select`. I have moved this under the new flag `const_cstr_from_ptr` https://github.com/rust-lang/rust/pull/107624#discussion_r1101555239 cc ``@oli-obk`` I think you're the const expert ``@rustbot`` modify labels: +T-libs-api +needs-fcp
2023-06-29Rollup merge of #113054 - ↵Matthias Krüger-30/+60
Rageking8:make-`rustc_on_unimplemented`-std-agnostic, r=WaffleLapkin Make `rustc_on_unimplemented` std-agnostic See #112923 r? `@WaffleLapkin`
2023-06-29Rollup merge of #112670 - petrochenkov:typriv, r=eholkMatthias Krüger-6/+6
privacy: Type privacy lints fixes and cleanups See individual commits. Follow up to https://github.com/rust-lang/rust/pull/111801.
2023-06-27Make `rustc_on_unimplemented` std-agnosticRageking8-30/+60
2023-06-26str docs: remove "Basic usage" text where not usefulTshepang Mbambo-40/+0
Not "useful" in that there is only one example given
2023-06-26Auto merge of #113024 - Jerrody:master, r=thomccbors-1/+1
`Default`: Always inline primitive data types.
2023-06-26Auto merge of #111850 - the8472:external-step-by, r=scottmcmbors-36/+482
Specialize `StepBy<Range<{integer}>>` OLD iter::bench_range_step_by_fold_u16 700.00ns/iter +/- 10.00ns iter::bench_range_step_by_fold_usize 519.00ns/iter +/- 6.00ns iter::bench_range_step_by_loop_u32 555.00ns/iter +/- 7.00ns iter::bench_range_step_by_sum_reducible 37.00ns/iter +/- 0.00ns NEW iter::bench_range_step_by_fold_u16 49.00ns/iter +/- 0.00ns iter::bench_range_step_by_fold_usize 194.00ns/iter +/- 1.00ns iter::bench_range_step_by_loop_u32 98.00ns/iter +/- 0.00ns iter::bench_range_step_by_sum_reducible 1.00ns/iter +/- 0.00ns NEW + `-Ctarget-cpu=x86-64-v3` iter::bench_range_step_by_fold_u16 22.00ns/iter +/- 0.00ns iter::bench_range_step_by_fold_usize 80.00ns/iter +/- 1.00ns iter::bench_range_step_by_loop_u32 41.00ns/iter +/- 0.00ns iter::bench_range_step_by_sum_reducible 1.00ns/iter +/- 0.00ns I have only optimized for walltime of those methods, I haven't tested whether it eliminates bounds checks when indexing into slices via things like `(0..slice.len()).step_by(16)`.
2023-06-25Mark the StepBy specialization as unsafeThe 8472-8/+8
2023-06-25StepBy<Range<{int <= usize}>> can be TrustedLenThe 8472-1/+7
2023-06-25doccomments for StepBy specializationsThe 8472-0/+41
2023-06-25Always inline primitive data types.George-1/+1
2023-06-23Rollup merge of #112704 - RalfJung:dont-wrap-slices, r=ChrisDentonMatthias Krüger-10/+14
slice::from_raw_parts: mention no-wrap-around condition Cc https://github.com/rust-lang/rust/issues/83996. This probably needs to be mentioned in more places, so I am not closing that issue, but this here should help at least.
2023-06-23add inline annotation to concrete implsThe 8472-0/+7
otherwise they wouldn't be eligible for cross-crate inlining
2023-06-23Specialize StepBy<Range<{integer}>>The 8472-36/+428
For ranges < usize we determine the number of items StepBy would yield and then store that in the range.end instead of the actual end. This significantly simplifies calculation of the loop induction variable especially in cases where StepBy::step (an usize) could overflow the Range's item type
2023-06-21Finish up preliminary tvos support in libstdThom Chiovoloni-7/+16
2023-06-21Auto merge of #111684 - ChayimFriedman2:unused-offset-of, r=WaffleLapkinbors-2/+3
Warn on unused `offset_of!()` result The usage of `core::hint::must_use()` means that we don't get a specialized message. I figured out that since there are plenty of other methods that just have `#[must_use]` with no message it'll be fine, but it is a bit unfortunate that the error mentions `must_use` and not `offset_of!`. Fixes #111669.
2023-06-21Warn on unused offset_of!() resultChayim Refael Friedman-2/+3
2023-06-20Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnrbors-7/+16
Add `implement_via_object` to `rustc_deny_explicit_impl` to control object candidate assembly Some built-in traits are special, since they are used to prove facts about the program that are important for later phases of compilation such as codegen and CTFE. For example, the `Unsize` trait is used to assert to the compiler that we are able to unsize a type into another type. It doesn't have any methods because it doesn't actually *instruct* the compiler how to do this unsizing, but this is later used (alongside an exhaustive match of combinations of unsizeable types) during codegen to generate unsize coercion code. Due to this, these built-in traits are incompatible with the type erasure provided by object types. For example, the existence of `dyn Unsize<T>` does not mean that the compiler is able to unsize `Box<dyn Unsize<T>>` into `Box<T>`, since `Unsize` is a *witness* to the fact that a type can be unsized, and it doesn't actually encode that unsizing operation in its vtable as mentioned above. The old trait solver gets around this fact by having complex control flow that never considers object bounds for certain built-in traits: https://github.com/rust-lang/rust/blob/2f896da247e0ee8f0bef7cd7c54cfbea255b9f68/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs#L61-L132 However, candidate assembly in the new solver is much more lovely, and I'd hate to add this list of opt-out cases into the new solver. Instead of maintaining this complex and hard-coded control flow, instead we can make this a property of the trait via a built-in attribute. We already have such a build attribute that's applied to every single trait that we care about: `rustc_deny_explicit_impl`. This PR adds `implement_via_object` as a meta-item to that attribute that allows us to opt a trait out of object-bound candidate assembly as well. r? `@lcnr`
2023-06-20Merge attrs, better validationMichael Goulet-13/+16
2023-06-20Add rustc_do_not_implement_via_objectMichael Goulet-0/+6
2023-06-19Rollup merge of #112606 - clarfonthey:ip-display, r=thomccMichael Goulet-12/+6
Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses ACP: rust-lang/libs-team#239
2023-06-19Rollup merge of #112499 - tgross35:py-ruff-fixes, r=Mark-SimulacrumMichael Goulet-1/+1
Fix python linting errors These were flagged by `ruff`, run using the config in https://github.com/rust-lang/rust/pull/112482
2023-06-19Rollup merge of #112757 - Danvil:patch-1, r=Mark-SimulacrumMatthias Krüger-2/+2
Use BorrowFlag instead of explicit isize The integer type tracking borrow count has a typedef called `BorrowFlag`. This type should be used instead of explicit `isize`.
2023-06-19Rollup merge of #109970 - ↵Matthias Krüger-0/+87
danielhenrymantilla:add-poll-fn-pin-clarifications, r=thomcc [doc] `poll_fn`: explain how to `pin` captured state safely Usage of `Pin::new_unchecked(&mut …)` is dangerous with `poll_fn`, even though the `!Unpin`-infectiousness has made things smoother. Nonetheless, there are easy ways to avoid the need for any `unsafe` altogether, be it through `Box::pin`ning, or the `pin!` macro. Since the latter only works within an `async` context, showing an example artificially introducing one ought to help people navigate this subtlety with safety and confidence. ## Preview https://user-images.githubusercontent.com/9920355/230092494-da22fdcb-0b8f-4ff4-a2ac-aa7d9ead077a.mov ```@rustbot``` label +A-docs
2023-06-19Auto merge of #112724 - scottmcm:simpler-unchecked-shifts, r=Mark-Simulacrumbors-12/+5
[libs] Simplify `unchecked_{shl,shr}` There's no need for the `const_eval_select` dance here. And while I originally wrote the `.try_into().unwrap_unchecked()` implementation here, it's kinda a mess in MIR -- this new one is substantially simpler, as shown by the old one being above the inlining threshold but the new one being below it in the `mir-opt/inline/unchecked_shifts` tests. We don't need `u32::checked_shl` doing a dance through both `Result` *and* `Option` 🙃
2023-06-18[doc] poll_fn: explain how to pin captured state safelyDaniel Henry-Mantilla-0/+87
Usage of `Pin::new_unchecked(&mut …)` is dangerous with `poll_fn`, even though the `!Unpin`-infectiousness has made things smoother. Nonetheless, there are easy ways to avoid the need for any `unsafe` altogether, be it through `Box::pin`ning, or the `pin!` macro. Since the latter only works within an `async` context, showing an example artifically introducing one ought to help people navigate this subtlety with safety and confidence.
2023-06-18Same for BorrowRefDavid Weikersdorfer-1/+1
2023-06-18Use BorrowFlag instead of explicit isizeDavid Weikersdorfer-1/+1
The integer type tracking borrow count has a typedef called `BorrowFlag`. This type should be used instead of explicit `isize`.
2023-06-18Auto merge of #112599 - saethlin:cleaner-panics, r=thomccbors-2/+3
Launch a non-unwinding panic for misaligned pointer deref This panic already never unwinds, but that's only because it always hits the unwind guard that's created by our `UnwindAction::Terminate`. Hitting the unwind guard generates a huge double-panic backtrace. Now we generate a normal-looking panic message when this check is hit. r? `@thomcc`
2023-06-17Rollup merge of #112644 - zica87:nonZeroTypes, r=Mark-SimulacrumMatthias Krüger-9/+12
Correct types in method descriptions of `NonZero*` types - `$Int`: e.g. i32, usize - `$Ty`: e.g. NonZeroI32, NonZeroUsize |method|current description|after my changes| |-|-|-| |`saturating_add`|...Return `$Int`::MAX on overflow.|...Return `$Ty`::MAX on overflow.| |`checked_abs`|...returns None if self == `$Int`::MIN.|...returns None if self == `$Ty`::MIN.| |`checked_neg`|...returning None if self == i32::MIN.|...returning None if self == `$Ty`::MIN.| |`saturating_neg`|...returning MAX if self == i32::MIN...|...returning `$Ty`::MAX if self == `$Ty`::MIN...| |`saturating_mul`|...Return `$Int`::MAX...|...Return `$Ty`::MAX...| |`saturating_pow`|...Return `$Int`::MIN or `$Int`::MAX...|...Return `$Ty`::MIN or `$Ty`::MAX...| --- For example: ```rust pub const fn saturating_neg(self) -> NonZeroI128 ``` - current - Saturating negation. Computes `-self`, returning `MAX` if `self == i32::MIN` instead of overflowing. - after my changes - Saturating negation. Computes `-self`, returning `NonZeroI128::MAX` if `self == NonZeroI128::MIN` instead of overflowing.
2023-06-16Apply changes to fix python linting errorsTrevor Gross-1/+1
2023-06-16[libs] Simplify `unchecked_{shl,shr}`Scott McMurray-12/+5
There's no need for the `const_eval_select` dance here. And while I originally wrote the `.try_into().unwrap_unchecked()` implementation here, it's kinda a mess in MIR -- this new one is substantially simpler, as shown by the old one being above the inlining threshold but the new one being below it.
2023-06-16Rollup merge of #112662 - Vanille-N:symbol_unique, r=RalfJungMichael Goulet-0/+2
`#[lang_item]` for `core::ptr::Unique` Tree Borrows is about to introduce experimental special handling of `core::ptr::Unique` in Miri to give it a semantics. As of now there does not seem to be a clean way (i.e. other than `&format!("{adt:?}") == "std::ptr::Unique"`) to check if an `AdtDef` represents a `Unique`. r? `@RalfJung` Draft: making a lang item
2023-06-16`#[lang_item]` for `core::ptr::Unique`Neven Villani-0/+2
2023-06-16Launch a non-unwinding panic for misaligned pointer derefBen Kimock-2/+3
2023-06-16slice::from_raw_parts: mention no-wrap-around conditionRalf Jung-10/+14
2023-06-15Rollup merge of #112529 - jieyouxu:block-expr-unused-must-use, r=oli-obkGuillaume Gomez-2/+2
Extend `unused_must_use` to cover block exprs Given code like ```rust #[must_use] fn foo() -> i32 { 42 } fn warns() { { foo(); } } fn does_not_warn() { { foo() }; } fn main() { warns(); does_not_warn(); } ``` ### Before This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: 1 warning emitted ``` ### After This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: unused return value of `foo` that must be used --> test.rs:14:9 | 14 | foo() | ^^^^^ | help: use `let _ = ...` to ignore the resulting value | 14 | let _ = foo(); | +++++++ + warning: 2 warnings emitted ``` Fixes #104253.
2023-06-15privacy: Do not mark items reachable farther than their nominal visibilityVadim Petrochenkov-6/+6
This commit reverts a change made in #111425. It was believed that this change was necessary for implementing type privacy lints, but #111801 showed that it was not necessary. Quite opposite, the revert fixes some issues.
2023-06-15Rollup merge of #112621 - GrigorenkoPV:env, r=jyn514Matthias Krüger-0/+2
Mention `env!` in `option_env!`'s docs `env!` mentions that there is an alternative that returns an `Option<...>` instead of emitting a compile error. Now `option_env!` also mentions that there is an alternative that emits a compile error instead of returning an `Option<...>`.
2023-06-15Extend `unused_must_use` to cover block exprs许杰友 Jieyou Xu (Joe)-2/+2
2023-06-15Auto merge of #106343 - the8472:slice-iter-fold, r=scottmcmbors-0/+42
optimize slice::Iter::fold Fixes 2 of 4 cases from #106288 ``` OLD: test slice::fold_to_last ... bench: 248 ns/iter (+/- 3) NEW: test slice::fold_to_last ... bench: 0 ns/iter (+/- 0) ```
2023-06-15Correct types in method descriptions of `NonZero*` typeszica-9/+12
2023-06-14use indexed loop instead of ptr bumpingThe 8472-10/+20
this seems to produce less IR
2023-06-14Auto merge of #112625 - matthiaskrgr:rollup-jcobj3g, r=matthiaskrgrbors-1/+1
Rollup of 7 pull requests Successful merges: - #112584 (loongarch64-none*: Remove environment component from llvm target) - #112600 (Introduce a `Stable` trait to translate MIR to SMIR) - #112605 (Improve docs/clean up negative overlap functions) - #112611 (Error on unconstrained lifetime in RPITIT) - #112612 (Fix explicit-outlives-requirements lint span) - #112613 (Fix rustdoc-gui tests on Windows) - #112620 (Fix small typo) r? `@ghost` `@rustbot` modify labels: rollup