-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
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 ^^
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
@@ -21,7 +21,6 @@ use Cow::*; | |||
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B> |
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.
If you want it to look the same as the AsRef impl, you can also remove the 'a
lifetime:
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B> | |
impl<B: ?Sized> Borrow<B> for Cow<'_, B> |
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.
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.
This is a small improvement that doesn't change semantics at all, but helps the generated documentation. @bors r+ rollup |
…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)
…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)
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
The lifetime bound
B::Owned: 'a
is redundant and doesn't make a difference,because
Cow<'a, B>
comes with an implicitB: 'a
, and associated typeswill outlive lifetimes outlived by the
Self
type (and all the trait'sgeneric 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:)