-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add some AsRef
implementations for smart pointers
#139318
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
e73eea9
to
d9b73e1
Compare
AsRef
/AsMut
implementations for smart pointers AsRef
implementations for smart pointers
This comment has been minimized.
This comment has been minimized.
as something that needs FCP, r? libs |
CI failed. You can check for success locally before pushing. :) |
Thanks for the suggestion, thats very useful :) |
r? libs-api |
I think |
This comment has been minimized.
This comment has been minimized.
e5c5d66
to
cc5a7bd
Compare
Yes that was my initial plan as well. However, adding the same impl blocks for I could try to resolve the errors produced by adding back |
I think we're going to get inference failures with any amount of I think this PR should either be only |
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.
Thanks for the PR!
I am not confident than any of these can be added without widespread breakage. For example, the new Box impls break pretty reasonable-looking code like the following:
fn main() {
let b = "...".to_owned().into_boxed_str();
println!("{}", b.as_ref());
}
error[E0283]: type annotations needed
--> src/main.rs:3:22
|
3 | println!("{}", b.as_ref());
| ^^^^^^
|
= note: multiple `impl`s satisfying `Box<str>: AsRef<_>` found in the following crates: `alloc`, `std`:
- impl AsRef<OsStr> for Box<str>;
- impl AsRef<Path> for Box<str>;
- impl<A> AsRef<[u8]> for Box<str, A>
where A: Allocator;
- impl<T, A> AsRef<T> for Box<T, A>
where A: Allocator, T: ?Sized;
help: try using a fully qualified path to specify the expected types
|
3 - println!("{}", b.as_ref());
3 + println!("{}", <Box<str> as AsRef<T>>::as_ref(&b));
|
If you'd like to see a crater run, I would recommend starting with just 1 single new impl, whichever of these is your favorite. Please send a separate PR for each impl that we should crater, and we can keep this PR as-is to keep track of all the impls we'd ideally like to add.
Implements part of #132138
This is my first time contributing to the Rust Project.
Please let me know if I need to make any changes, or update the PR in any way.
I have read the contributing guidelines.