Skip to content
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

Remove redundant lifetime bound from impl Borrow for Cow #99578

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

steffahn
Copy link
Member

@steffahn steffahn commented Jul 21, 2022

The lifetime bound B::Owned: 'a is redundant and doesn't make a difference,
because Cow<'a, B> comes with an implicit B: 'a, and associated types
will outlive lifetimes outlived by the Self type (and all the trait's
generic parameters, of which there are none in this case), so the implicit B: 'a
implies B::Owned: 'a anyway.

The explicit lifetime bound here does however end up in documentation,
and that's confusing in my opinion, so let's remove it ^^

(Documentation right now, compare to AsRef, too:)
Screenshot_20220722_014055

The lifetime bound `B::Owned: 'a` is redundant and doesn't make a difference,
because `Cow<'a, B>` comes with an implicit `B: 'a`, and associated types
will outlive lifetimes outlived by the `Self` type (and all the trait's
generic parameters, of which there are none in this case), so the implicit `B: 'a`
implies `B::Owned: 'a` anyway.

The explicit lifetime bound here does however end up in documentation,
and that's confusing in my opinion, so let's remove it ^^
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jul 21, 2022
@rustbot
Copy link
Collaborator

rustbot commented Jul 21, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 21, 2022
@@ -21,7 +21,6 @@ use Cow::*;
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want it to look the same as the AsRef impl, you can also remove the 'a lifetime:

Suggested change
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
impl<B: ?Sized> Borrow<B> for Cow<'_, B>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of how the rendered documentation comes out, I actually prefer the way it looks with the explicit lifetime, since otherwise it still renders as invalid Rust code with the impl<'_> part.

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2022
@thomcc
Copy link
Member

thomcc commented Oct 23, 2022

This is a small improvement that doesn't change semantics at all, but helps the generated documentation.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 23, 2022

📌 Commit c03d10c has been approved by thomcc

It is now in the queue for this repository.

@bors bors 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 Oct 23, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
…thomcc

Remove redundant lifetime bound from `impl Borrow for Cow`

The lifetime bound `B::Owned: 'a` is redundant and doesn't make a difference,
because `Cow<'a, B>` comes with an implicit `B: 'a`, and associated types
will outlive lifetimes outlived by the `Self` type (and all the trait's
generic parameters, of which there are none in this case), so the implicit `B: 'a`
implies `B::Owned: 'a` anyway.

The explicit lifetime bound here does however [end up in documentation](https://doc.rust-lang.org/std/borrow/enum.Cow.html#impl-Borrow%3CB%3E),
and that's confusing in my opinion, so let's remove it ^^

_(Documentation right now, compare to `AsRef`, too:)_
![Screenshot_20220722_014055](https://user-images.githubusercontent.com/3986214/180332665-424d0c05-afb3-40d8-a330-a57a2c9a494b.png)
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 24, 2022
…thomcc

Remove redundant lifetime bound from `impl Borrow for Cow`

The lifetime bound `B::Owned: 'a` is redundant and doesn't make a difference,
because `Cow<'a, B>` comes with an implicit `B: 'a`, and associated types
will outlive lifetimes outlived by the `Self` type (and all the trait's
generic parameters, of which there are none in this case), so the implicit `B: 'a`
implies `B::Owned: 'a` anyway.

The explicit lifetime bound here does however [end up in documentation](https://doc.rust-lang.org/std/borrow/enum.Cow.html#impl-Borrow%3CB%3E),
and that's confusing in my opinion, so let's remove it ^^

_(Documentation right now, compare to `AsRef`, too:)_
![Screenshot_20220722_014055](https://user-images.githubusercontent.com/3986214/180332665-424d0c05-afb3-40d8-a330-a57a2c9a494b.png)
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 24, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#99578 (Remove redundant lifetime bound from `impl Borrow for Cow`)
 - rust-lang#99939 (Sort tests at compile time, not at startup)
 - rust-lang#102271 (Stabilize `duration_checked_float`)
 - rust-lang#102766 (Don't link to `libresolv` in libstd on Darwin)
 - rust-lang#103277 (Update libstd's libc to 0.2.135 (to make `libstd` no longer pull in `libiconv.dylib` on Darwin))
 - rust-lang#103437 (Sync rustc_codegen_cranelift)
 - rust-lang#103466 (Fix grammar in docs for std::io::Read)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fbb3650 into rust-lang:master Oct 24, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 24, 2022
@steffahn steffahn deleted the remove_redundant_bound branch January 7, 2023 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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