-
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
Fixed-size byte string literals (RFC 339) #22838
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Notes:
|
I personally considered the breakage of this behavior to be a showstopper for the previous attempt: match foo {
b"foo" => { /* ... */ }
} Others may have a different opinion though! I'm also getting quite worried about how we're just spraying impls of traits for cc @nrc, @nikomatsakis on the coercions aspect, do we perhaps have any RFCs in the pipeline to help here? This relatively small change ended up having quite a large fallout! |
re coercions: There's nothing in the pipeline re coercions in matches - there was some RFC recently about array patterns in matches, but I think that makes things stricter. I'm not quite sure what it means to coerce in a pattern - if it means that |
@alexcrichton I don't think it's a showstopper for several reasons:
So, I'd like to land this PR until it's too late and to work on the fix for patterns independently of it (I currently study the implementation of pattern matching in the compiler). |
|
Everything about fixed-size arrays feels not quite right until some form of rust-lang/rfcs#884 is implemented, but it doesn't mean that they should be second class citizens. In principle I can kill the new impls and spend some more time manually coercing |
@alexcrichton I think it's possible to remove some of the metadata bloat with the next trick (where the coherence rules allow it):
|
@petrochenkov that's a pretty good idea! I like how it's turned out for fixed-size arrays. I'm not super happy that this has cc @aturon, I'm curious what you think about the ergonomic fall out here as well as the |
I think I know what to do with byte string literal patterns - they will behave exactly like array patterns - they will denote |
☔ The latest upstream changes (presumably #23107) made this pull request unmergeable. Please resolve the merge conflicts. |
Fixed byte string literal patterns and rebased |
Wow, nice work @petrochenkov! cc @aturon, I'm curious as to your opinion of |
@alexcrichton @petrochenkov Sorry for the delay giving feedback on this. I'm not too worried about In any case, I don't think we should hold up the PR just for that reason, since it's a minor impl detail that can be improved later on. |
@aturon while the trait itself remains stable, we are leaking stable functionality via the trait itself. Right now the stability pass does not consider the stability of an
I'm a little uncomfortable with the two and would prefer coercions to take over, but just want to confirm that you're on board with this information as well. |
What coercions exactly? I remember someone (maybe @japaric or @eddyb ?) proposing "impl lookup with coercions" - if we are not able to find an impl of trait |
@blaenk came up with that idea, I merely gave it a name (bound-targeting coercions). |
@petrochenkov yeah that's basically what I was thinking, although I'm not sure if it's actually plausible. I'm just wary of committing to providing impls for these traits for all these fixed size arrays. |
@alexcrichton |
Gah sorry about the delay on this @petrochenkov! I meant to discuss this with @aturon in more depth in the meantime, but we never got around to it :(. Due to the conservative nature of this, however, I'm fine landing this for now, thanks for being patient! As an aside, |
@bors: r+ a7e1c1d |
⌛ Testing commit a7e1c1d with merge 4f63ae2... |
💔 Test failed - auto-win-64-nopt-t |
Changed in rust-lang#22838. audited (raw) byte string literals @ rust-lang#16676
Changed in rust-lang#22838. audited (raw) byte string literals @ rust-lang#16676
Changed in rust-lang#22838. audited (raw) byte string literals @ rust-lang#16676
Changed in rust-lang#22838. audited (raw) byte string literals @ rust-lang#16676
Changed in rust-lang#22838. audited (raw) byte string literals @ rust-lang#16676
Changed in rust-lang#22838. audited (raw) byte string literals @ rust-lang#16676
This patch changes the type of byte string literals from
&[u8]
to&[u8; N]
.It also implements some necessary traits (
IntoBytes
,Seek
,Read
,BufRead
) for fixed-size arrays (also related to #21725) and adds test for #17233, which seems to be resolved.Fixes #18465
[breaking-change]