&[char;_]:
doesn't implement Pattern
while &[char]
does
#86329
Labels
C-bug
Category: This is a bug.
I tried this code:
I expected to see this happen: Outputs
["foo","bar"]
Instead, this happened (playground output: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018):
Meta
rustc --version --verbose
:No backtrace for diagnostic
Further Information
There are two issues here, for one, the diagnostic is somewhat confusing. I expect that an array is not a closure, but I would expect it to be a pattern (Thus, telling me it isn't a closure isn't helpful to me). The second is the actual issue that references to arrays aren't Patterns.
According to the
.split
docs, it's valid to pass a slice ofchar
tosplit
as the pattern. It should follow that you can pass a reference to an array to.split
, because references to arrays coerce to references to slices.Both issues could be fixed with
impl<const N: usize> Pattern for &[char;N]{...}
in the stdlib. It may also be useful (and was brought up in discussion on the Rust Community Discord), for a non-reference implimpl<const N: usize> Pattern for [char;N]{...}
. In the former case, it should be achievable by delegating to the slice impl. I am unfamiliar with the implementation in particular, but the same may also be reasonable for the by-value array case.The text was updated successfully, but these errors were encountered: