-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Constify conversion traits (part 1) #145279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| #![feature(const_default)] | ||
| #![feature(const_eval_select)] | ||
| #![feature(const_heap)] | ||
| #![feature(const_trait_impl)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was listed under library features, and is actually a language feature. Since the diff doesn't make that clear.
| // FIXME(const-hack): this should use map_err instead | ||
| match u8::try_from(u32::from(c)) { | ||
| Ok(b) => Ok(b), | ||
| Err(_) => Err(TryFromCharError(())), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned not wanting to add any more const-hacks, but I figured this one (+ for u16 below) was okay because we're already going to have to fix a lot of const code once things are stable, and I think that simple char <-> integer conversions are useful enough to get on nightly sooner. Especially since const closures seem pretty far off at the moment.
|
☔ The latest upstream changes (presumably #145334) made this pull request unmergeable. Please resolve the merge conflicts. |
365fcde to
97c330f
Compare
|
Rebasing over #144847 since that one conflicts with this one, which is why I was going to do this one before I got to that one, but, it's in the queue now, so, 🤷🏻. Only changes with the rebase are eliminating more additions of |
97c330f to
4ebb4b7
Compare
|
This PR was rebased onto a different master commit! Check out the changes with our |
|
☔ The latest upstream changes (presumably #145644) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Will rebase once that PR gets merged. I can mark it as blocked, but it still can be reviewed before to verify you're comfortable with the changes. |
4ebb4b7 to
4bcf7bd
Compare
This comment has been minimized.
This comment has been minimized.
|
(Un-rebased over that PR since it's no longer in the queue.) |
…oshtriplett `const`ify (the unstable) `str::as_str` Tracking issue: rust-lang#130366 The method was not initially marked `const` presumably because it is only useful with `Deref`. But now that const traits seem to be a thing that can actually become real, why not make it `const`? PR `const`ifying `Deref`: rust-lang#145279
Rollup merge of #145930 - GrigorenkoPV:const_str_as_str, r=joshtriplett `const`ify (the unstable) `str::as_str` Tracking issue: #130366 The method was not initially marked `const` presumably because it is only useful with `Deref`. But now that const traits seem to be a thing that can actually become real, why not make it `const`? PR `const`ifying `Deref`: #145279
4bcf7bd to
66dcd76
Compare
|
This PR was rebased onto a different master 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. |
This comment has been minimized.
This comment has been minimized.
66dcd76 to
636cfe4
Compare
636cfe4 to
1c64d3e
Compare
|
Incorporated the methods from #146101 and listed them in the issue description. |
|
All good! I didn't want to bug you since I figured you were busy. Thanks for getting to this. |
Constify conversion traits (part 1) This is the first part of #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 #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)
… r=tgross35 Constify conversion traits (part 1) This is the first part of rust-lang#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#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)
|
@bors retry |
Rollup of 8 pull requests Successful merges: - #139113 (unstable book: in a sanitizer example, check the code) - #145279 (Constify conversion traits (part 1)) - #145414 (unicode-table-generator refactors) - #145823 (editorconfig: don't use nonexistent syntax) - #145944 (std: Start supporting WASIp2 natively ) - #145961 (resolve: Avoid a regression from splitting prelude into two scopes) - #146032 (Explicity disable LSX feature for `loongarch64-unknown-none` target) - #146106 (fix(lexer): Only allow horizontal whitespace in frontmatter ) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 8 pull requests Successful merges: - #139113 (unstable book: in a sanitizer example, check the code) - #145279 (Constify conversion traits (part 1)) - #145414 (unicode-table-generator refactors) - #145823 (editorconfig: don't use nonexistent syntax) - #145944 (std: Start supporting WASIp2 natively ) - #145961 (resolve: Avoid a regression from splitting prelude into two scopes) - #146032 (Explicity disable LSX feature for `loongarch64-unknown-none` target) - #146106 (fix(lexer): Only allow horizontal whitespace in frontmatter ) r? `@ghost` `@rustbot` modify labels: rollup
… r=tgross35 Constify conversion traits (part 1) This is the first part of rust-lang#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#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)
Rollup of 9 pull requests Successful merges: - #145279 (Constify conversion traits (part 1)) - #145414 (unicode-table-generator refactors) - #145823 (editorconfig: don't use nonexistent syntax) - #145944 (std: Start supporting WASIp2 natively ) - #145961 (resolve: Avoid a regression from splitting prelude into two scopes) - #146032 (Explicity disable LSX feature for `loongarch64-unknown-none` target) - #146106 (fix(lexer): Only allow horizontal whitespace in frontmatter ) - #146112 (don't uppercase error messages) - #146154 (CI: rfl: move job forward to Linux v6.17-rc3 plus 2 commits) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 8 pull requests Successful merges: - #145279 (Constify conversion traits (part 1)) - #145414 (unicode-table-generator refactors) - #145823 (editorconfig: don't use nonexistent syntax) - #145944 (std: Start supporting WASIp2 natively ) - #145961 (resolve: Avoid a regression from splitting prelude into two scopes) - #146032 (Explicity disable LSX feature for `loongarch64-unknown-none` target) - #146106 (fix(lexer): Only allow horizontal whitespace in frontmatter ) - #146154 (CI: rfl: move job forward to Linux v6.17-rc3 plus 2 commits) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #145279 - clarfonthey:const-convert-initial, r=tgross35 Constify conversion traits (part 1) This is the first part of #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 #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)
…oshtriplett `const`ify (the unstable) `str::as_str` Tracking issue: rust-lang#130366 The method was not initially marked `const` presumably because it is only useful with `Deref`. But now that const traits seem to be a thing that can actually become real, why not make it `const`? PR `const`ifying `Deref`: rust-lang#145279
… r=tgross35 Constify conversion traits (part 1) This is the first part of rust-lang#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#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)
…r=oli-obk Revert constification of `AsRef for Cow` due to inference failure Reported issue: rust-lang#147964 Original PR: rust-lang#145279 `const AsRef` tracking issue: rust-lang#143773 Should have additional crater run to verify this fixes the issue.
…, r=cuviper Revert constification of `Borrow` and `Deref for Cow` due to inference failure Reported issue: rust-lang#147964 Original PR: rust-lang#145279 Previous revert: rust-lang#148011 `const Borrow`/`Deref` tracking issue: rust-lang#143773 Should have additional crater run to verify this fixes the issue. Since other PR is in the queue, this will need to be rebased after that merges. Also will want a beta nomination.
…, r=cuviper Revert constification of `Borrow` and `Deref for Cow` due to inference failure Reported issue: rust-lang#147964 Original PR: rust-lang#145279 Previous revert: rust-lang#148011 `const Borrow`/`Deref` tracking issue: rust-lang#143773 Should have additional crater run to verify this fixes the issue. Since other PR is in the queue, this will need to be rebased after that merges. Also will want a beta nomination.
Rollup merge of #148016 - clarfonthey:const-convert-revert-2, r=cuviper Revert constification of `Borrow` and `Deref for Cow` due to inference failure Reported issue: #147964 Original PR: #145279 Previous revert: #148011 `const Borrow`/`Deref` tracking issue: #143773 Should have additional crater run to verify this fixes the issue. Since other PR is in the queue, this will need to be rebased after that merges. Also will want a beta nomination.
This is the first part of #144289 being split into smaller pieces. It adds/moves constness of several traits under the
const_convertfeature:FromIntoTryFromTryIntoFromStrAsRefAsMutBorrowBorrowMutDerefDerefMutThere 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 underbstrfeature)OsStr::newPath::newThose which directly use
Into:Result::into_okResult::into_errAnd those which use
DerefandDerefMut:Pin::as_refPin::as_mutPin::as_deref_mutOption::as_derefOption::as_deref_mutResult::as_derefResult::as_deref_mut(note: the
OptionandResultmethods were suggested by @npmccallum initially as #146101)The parts which are missing from this PR are:
OsStrorPath(note: this mostly makes these methods useless sincestrdoesn't implementAsRef<OsStr>yet, but it's better to track the method for now and add impls later, IMHO)r? @tgross35 (who mostly already reviewed this)