Skip to content

constify From impls for the Cow::Borrowed variant - #146525

Closed
npmccallum wants to merge 1 commit into
rust-lang:mainfrom
npmccallum:cow2
Closed

constify From impls for the Cow::Borrowed variant#146525
npmccallum wants to merge 1 commit into
rust-lang:mainfrom
npmccallum:cow2

Conversation

@npmccallum

Copy link
Copy Markdown
Contributor

This issue is a follow-up PR from #146067 with the controversial impls removed.

This is useful in at least two cases:

  1. Generic interfaces which may be const.
  2. Conditional compilation (&str vs Cow<str>).

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 13, 2025
@rustbot

rustbot commented Sep 13, 2025

Copy link
Copy Markdown
Collaborator

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@tgross35

Copy link
Copy Markdown
Contributor

Anybody reviewing this, please take a look at #146067 (comment)

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@ibraheemdev

Copy link
Copy Markdown
Member

This issue is a follow-up PR from #146067 with the controversial impls removed.

Which controversial parts were removed? If I understand @tgross35's comments correctly, we want to avoid introducing more rustc_const_unstable attributes into alloc to keep the API surface small before stabilization.

@npmccallum

Copy link
Copy Markdown
Contributor Author

@ibraheemdev The original objection was const constructors for types like String. @tgross35's comments came later.

@rustbot

rustbot commented Oct 15, 2025

Copy link
Copy Markdown
Collaborator

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.

@clarfonthey

Copy link
Copy Markdown
Contributor

Poking through old PRs: this seems to not have conflicts and be okay with the latest library constification policies.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit c6cb702 has been approved by clarfonthey

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 25, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 26, 2026
constify `From` impls for the `Cow::Borrowed` variant

This issue is a follow-up PR from rust-lang#146067 with the controversial impls removed.

This is useful in at least two cases:

1. Generic interfaces which may be `const`.
2. Conditional compilation (`&str` vs `Cow<str>`).
@jhpratt

jhpratt commented Jul 26, 2026

Copy link
Copy Markdown
Member

@bors r- #159941 (comment)

fmt check
error: expected a trait, found type
##[error] --> /checkout/library/alloc/src/vec/cow.rs:6:20
  |
6 | impl<'a, T: Clone> const From<&'a [T]> for Cow<'a, [T]> {
  |                    ^^^^^^^^^^^^^^^^^^^

error: expected a trait, found type
##[error]    --> /checkout/library/alloc/src/string.rs:3245:10
     |
3245 | impl<'a> const From<&'a str> for Cow<'a, str> {
     |          ^^^^^^^^^^^^^^^^^^^

error: expected a trait, found type
##[error]   --> /checkout/library/alloc/src/bstr.rs:598:10
    |
598 | impl<'a> const From<&'a ByteStr> for Cow<'a, ByteStr> {
    |          ^^^^^^^^^^^^^^^^^^^^^^^

error: expected a trait, found type
##[error]   --> /checkout/library/alloc/src/ffi/c_str.rs:885:10
    |
885 | impl<'a> const From<&'a CStr> for Cow<'a, CStr> {
    |          ^^^^^^^^^^^^^^^^^^^^

fmt: checked 7052 files
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Currently active steps:

@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 26, 2026
@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 26, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

Right, the syntax has changed since this was written. My bad.

@jhpratt

jhpratt commented Jul 26, 2026

Copy link
Copy Markdown
Member

Off the top of my head I believe it's now const impl Foo, but I could be wrong on that.

@clarfonthey

Copy link
Copy Markdown
Contributor

In that case, going to close this as being super old. Can be reopened if fixed.

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants