-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Literal &[char]
patterns clumsily require an as
conversion
#39511
Comments
Shorter version: |
cc @Kimundi |
Lovely! This hadn't occurred to me. |
Yeah, this was a known issue from the start. This concrete impl is basically a originally-nice API that is old enough that it got gradually worse over time in multiple iterations. If I remember right, there was originally a hardcoded method that just took a I think the only real "fix" for this is deprecating this pattern, and/or holding out till we have char array generics and can have a |
Triage:
Seems like the same status today; we are making progress on const generics, but it's not ready yet. |
Many
str
methods accept patterns of any type that implements thestd::str::pattern::Pattern
trait. One such type is&[char]
, which matches any single character mentioned in the pattern slice.However,
&[char]
patterns are not as nice to use as one might hope. This does not compile:Rust complains:
The
trim_left_matches
method constrains its argument typeP
withP: Pattern
, and Rust won't apply the usual type coercions like&[T; N]
to&[T]
in order to satisfy trait bounds.One must instead write:
It's not a tragedy, but it's not pretty either.
CC @alexcrichton
The text was updated successfully, but these errors were encountered: