about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
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-19Implement slice::split_once and slice::rsplit_onceBenjamin Lee-0/+77
Feature gate is slice_split_once and tracking issue is #112811.
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-16Remove `#[cfg(all())]` workarounds from `c_char`Alex Macleod-5/+0
2023-06-16Add more comprehensive tests for is_sorted and friends+merlan #flirora-1/+58
See #53485 and #55045.
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
2023-06-14Fix `SocketAddrV6: Display` testsltdk-1/+1
2023-06-14Fix `Ipv6Addr: Display` testsltdk-3/+3
2023-06-14Rollup merge of #111974 - Sp00ph:update_guarantees, r=AmanieuMatthias Krüger-6/+4
Update runtime guarantee for `select_nth_unstable` #106933 changed the runtime guarantee for `select_nth_unstable` from O(n) to O(n log n), since the old guarantee wasn't actually met by the implementation at the time. Now with #107522, `select_nth_unstable` should be truly linear in runtime, so we can revert its runtime guarantee to O(n). Since #106933 was considered a bug fix, this will probably need an FCP because it counts as a new API guarantee. r? `@Amanieu`
2023-06-14Mention `env!` in `option_env!`'s docsPavel Grigorenko-0/+2
2023-06-14Fix typoAntonios Barotsis-1/+1
2023-06-13Alter `Display` for `Ipv6Addr` for IPv4-compatible addressesltdk-8/+2
2023-06-13Auto merge of #112314 - ferrocene:pa-core-alloc-abort, r=bjorn3bors-12/+3
Ignore `core`, `alloc` and `test` tests that require unwinding on `-C panic=abort` Some of the tests for `core` and `alloc` require unwinding through their use of `catch_unwind`. These tests fail when testing using `-C panic=abort` (in my case through a target without unwinding support, and `-Z panic-abort-tests`), while they should be ignored as they don't indicate a failure. This PR marks all of these tests with this attribute: ```rust #[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")] ``` I'm not aware of a way to test this on rust-lang/rust's CI, as we don't test any target with `-C panic=abort`, but I tested this locally on a Ferrocene target and it does indeed make the test suite pass.
2023-06-13ignore core, alloc and test tests that require unwinding on panic=abortPietro Albini-12/+3
2023-06-12optimize slice::Iter::foldThe 8472-0/+23
2023-06-12add benchmarkThe 8472-0/+9
2023-06-12Revert "Fix intra-doc links from pointer appearing in windows HANDLE type alias"Guillaume Gomez-9/+9
This reverts commit 2ce7cd906bde70d8cbd9b07b31c6a7bf1131c345.
2023-06-10Auto merge of #111818 - Urgau:uplift_cmp_nan, r=cjgillotbors-0/+2
Uplift `clippy::cmp_nan` lint This PR aims at uplifting the `clippy::cmp_nan` lint into rustc. ## `invalid_nan_comparisons` ~~(deny-by-default)~~ (warn-by-default) The `invalid_nan_comparisons` lint checks comparison with `f32::NAN` or `f64::NAN` as one of the operand. ### Example ```rust,compile_fail let a = 2.3f32; if a == f32::NAN {} ``` ### Explanation NaN does not compare meaningfully to anything – not even itself – so those comparisons are always false. ----- Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 `@rustbot` label: +I-lang-nominated r? compiler
2023-06-09Add diagnostic items for `f32::NAN` and `f64::NAN`Urgau-0/+2
2023-06-09Auto merge of #112465 - GuillaumeGomez:rollup-gyh5buc, r=GuillaumeGomezbors-9/+9
Rollup of 3 pull requests Successful merges: - #112260 (Improve document of `unsafe_code` lint) - #112429 ([rustdoc] List matching impls on type aliases) - #112442 (Deduplicate identical region constraints in new solver) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-09Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errorsbors-0/+2
Uplift `clippy::undropped_manually_drops` lint This PR aims at uplifting the `clippy::undropped_manually_drops` lint. ## `undropped_manually_drops` (warn-by-default) The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop. ### Example ```rust struct S; drop(std::mem::ManuallyDrop::new(S)); ``` ### Explanation `ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either. ----- Mostly followed the instructions for uplifting an clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 `@rustbot` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2023-06-09Fix intra-doc links from pointer appearing in windows HANDLE type aliasGuillaume Gomez-9/+9
2023-06-08Rollup merge of #109953 - thomcc:thomcc/typeid128, r=WaffleLapkinMatthias Krüger-3/+45
Use 128 bits for TypeId hash Preliminary/Draft impl of https://github.com/rust-lang/compiler-team/issues/608 Prior art (probably incomplete list) - https://github.com/rust-lang/rust/pull/75923 - https://github.com/rust-lang/rust/pull/95845
2023-06-08Allow undropped_manually_drops for some testsUrgau-0/+2
2023-06-07Fix typoThom Chiovoloni-1/+1
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2023-06-07Don't panic in ceil_char_boundaryltdk-4/+3