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

impl From<T> for [T; 1] #68392

Closed
wants to merge 3 commits into from
Closed

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Jan 20, 2020

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(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 Jan 20, 2020
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
@jonas-schievink jonas-schievink added needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 20, 2020
@jonas-schievink jonas-schievink added this to the 1.42 milestone Jan 20, 2020
@sfackler
Copy link
Member

How would this implementation allow your example to compile?

@jyn514
Copy link
Member Author

jyn514 commented Jan 20, 2020

@sfackler looking back at it, it probably wouldn't have. I think this feature stands on its own, though.

impl AsRef<[T]> for T is closer to what I want, but I get an error I don't really understand when I try to implement it:

error[E0119]: conflicting implementations of trait `convert::AsRef<[&_]>` for type `&_`:
    --> src/libcore/slice/mod.rs:5532:1
     |
5532 |   impl<T: ?Sized> AsRef<[T]> for T {
     |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
     | 
    ::: src/libcore/convert/mod.rs:504:1
     |
504  | / impl<T: ?Sized, U: ?Sized> AsRef<U> for &T
505  | | where
506  | |     T: AsRef<U>,
507  | | {
...    |
510  | |     }
511  | | }
     | |_- first implementation here

@tesuji
Copy link
Contributor

tesuji commented Jan 21, 2020

What about accepting impl Iterator<usize> and using slice::from_ref on callsite?

@jyn514
Copy link
Member Author

jyn514 commented Jan 21, 2020

@lzutao the idea was to avoid requiring additional effort from the caller. In any case I solved it a different way that still only took one argument.

@clarfonthey
Copy link
Contributor

I feel like an example like this would require From<T> for (T,) too. And honestly, I feel like adding implementations of things for singleton tuples and arrays can start to get very excessive as time goes on, but I'm not personally against it if people have use cases.

@Centril Centril modified the milestones: 1.42, 1.43 Jan 31, 2020
@Dylan-DPC-zz
Copy link

r? @Amanieu

@rust-highfive rust-highfive assigned Amanieu and unassigned joshtriplett Mar 7, 2020
@Amanieu
Copy link
Member

Amanieu commented Mar 7, 2020

@jyn514 You said you've solved your issue. Does that mean that you don't need this feature any more?

@jyn514
Copy link
Member Author

jyn514 commented Mar 7, 2020

I guess not. I'm ok with closing this if you think it's not worth the hassle. #68692 would still be super useful though.

@Dylan-DPC-zz Dylan-DPC-zz added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. labels Mar 7, 2020
@Centril Centril removed this from the 1.43 milestone Mar 10, 2020
@jyn514 jyn514 deleted the array-from-single branch September 12, 2020 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants