Skip to content

Binary string literals are of type &[u8] instead of &[u8, ..n] #17626

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

Closed
ftxqxd opened this issue Sep 29, 2014 · 2 comments
Closed

Binary string literals are of type &[u8] instead of &[u8, ..n] #17626

ftxqxd opened this issue Sep 29, 2014 · 2 comments
Labels
A-type-system Area: Type system

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Sep 29, 2014

Intuitively, I would expect b"abc" to behave identically to &[97, 98, 99], but it does not: b"abc" is of type &[u8] instead of &[u8, ..3] like &[97, 98, 99] is. Changing this to &[u8, ..n] would provide more flexibility, as &[u8, ..n] can always be converted to &[u8], but not vice-versa.

Presumably this was either intentional or simply forgotten during the slice-related DST changes.

@kmcallister kmcallister added the A-type-system Area: Type system label Sep 29, 2014
@nham
Copy link
Contributor

nham commented Mar 19, 2015

Just bumping this to note that this still seems to be the case:

<anon>:2:23: 2:29 error: mismatched types:
 expected `&[u8; 3]`,
    found `&'static [u8]`
(expected array of 3 elements,
    found slice) [E0308]
<anon>:2     let x: &[u8; 3] = b"abc";
                               ^~~~~~

@ftxqxd
Copy link
Contributor Author

ftxqxd commented May 15, 2015

This is done. (See #18465.)

@ftxqxd ftxqxd closed this as completed May 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants