Add TryFromIntError::kind method and IntErrorKind::NotAPowerOfTwo variant#153178
Conversation
|
@rustbot label +T-libs-api -T-libs |
38cf8bf to
20c70f9
Compare
TryFromIntError::kindTryFromIntError::kind method and IntErrorKind::NotAPowerOfTwo variant
TryFromIntError::kind method and IntErrorKind::NotAPowerOfTwo variantTryFromIntError::kind method and IntErrorKind::NotAPowerOfTwo variant
20c70f9 to
a0a5c69
Compare
a0a5c69 to
989926f
Compare
989926f to
e8c4298
Compare
|
r? libs-api |
This comment has been minimized.
This comment has been minimized.
e8c4298 to
775108a
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
r? tgross35 |
b6f5330 to
ace8aa1
Compare
ace8aa1 to
c35ed1a
Compare
|
Thanks! |
…uwer Rollup of 5 pull requests Successful merges: - #154781 (Fix attribute order implementation) - #155242 (resolve: Introduce `(Local,Extern)Module` newtypes for local and external modules respectively) - #149614 (Use `MaybeDangling` in `std`) - #153178 (Add `TryFromIntError::kind` method and `IntErrorKind::NotAPowerOfTwo` variant) - #155049 (Documenting the case of `Weak::upgrade` returning `None` when the value behind the reference is missing) Failed merges: - #155308 (Make `OnDuplicate::Error` the default for attributes)
…uwer Rollup of 5 pull requests Successful merges: - #154781 (Fix attribute order implementation) - #155242 (resolve: Introduce `(Local,Extern)Module` newtypes for local and external modules respectively) - #149614 (Use `MaybeDangling` in `std`) - #153178 (Add `TryFromIntError::kind` method and `IntErrorKind::NotAPowerOfTwo` variant) - #155049 (Documenting the case of `Weak::upgrade` returning `None` when the value behind the reference is missing) Failed merges: - #155308 (Make `OnDuplicate::Error` the default for attributes)
Rollup merge of #153178 - sorairolake:feature/try-from-int-error-kind, r=tgross35 Add `TryFromIntError::kind` method and `IntErrorKind::NotAPowerOfTwo` variant - ACP: rust-lang/libs-team#746 - Tracking issue: #153978 This pull request adds `kind` method to [`TryFromIntError`](https://doc.rust-lang.org/core/num/struct.TryFromIntError.html), which outputs the detailed cause of converting an integer failing. This is primarily intended for use in cases where there are multiple causes for failure, such as converting from a large signed integer type to a small signed integer type. At the moment, this method returns [`&IntErrorKind`](https://doc.rust-lang.org/core/num/enum.IntErrorKind.html). This type implements the `Copy` trait and could return `IntErrorKind`, but returns a reference to align with the behavior of [`ParseIntError::kind`](https://doc.rust-lang.org/core/num/struct.ParseIntError.html#method.kind). If it is not necessary to align the behavior of `TryFromIntError::kind` with `ParseIntError::kind`, I'll change this method to return `IntErrorKind`. Before this pull request, `IntErrorKind` was only used by [`ParseIntError`](https://doc.rust-lang.org/core/num/struct.ParseIntError.html), but I changed it to be used by `TryFromIntError` as well, so I updated `IntErrorKind`'s documentation. [`impl TryFrom<usize> for Alignment`](https://doc.rust-lang.org/std/ptr/struct.Alignment.html#impl-TryFrom%3Cusize%3E-for-Alignment) returns `TryFromIntError` as an error if the given value is not a power of two. However, `IntErrorKind` does not have a variant that represents this. So I added the variant `NotAPowerOfTwo` to represent this. For this variant to stabilize, both `try_from_int_error_kind` and `ptr_alignment_type` features must be stabilized.
|
@rust-timer build c1d01b6 |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (c1d01b6): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -2.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.2%, secondary -3.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.0%, secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 490.91s -> 492.735s (0.37%) |
|
Caused the perf regression in #155432 |
View all comments
TryFromIntError::kindmethod andIntErrorKind::NotAPowerOfTwovariant libs-team#746try_from_int_error_kind#153978This pull request adds
kindmethod toTryFromIntError, which outputs the detailed cause of converting an integer failing.This is primarily intended for use in cases where there are multiple causes for failure, such as converting from a large signed integer type to a small signed integer type.
At the moment, this method returns
&IntErrorKind. This type implements theCopytrait and could returnIntErrorKind, but returns a reference to align with the behavior ofParseIntError::kind. If it is not necessary to align the behavior ofTryFromIntError::kindwithParseIntError::kind, I'll change this method to returnIntErrorKind.Before this pull request,
IntErrorKindwas only used byParseIntError, but I changed it to be used byTryFromIntErroras well, so I updatedIntErrorKind's documentation.impl TryFrom<usize> for AlignmentreturnsTryFromIntErroras an error if the given value is not a power of two. However,IntErrorKinddoes not have a variant that represents this. So I added the variantNotAPowerOfTwoto represent this. For this variant to stabilize, bothtry_from_int_error_kindandptr_alignment_typefeatures must be stabilized.