Skip to content

Undeprecate and update bytes! macro. #18702

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
wants to merge 2 commits into from
Closed

Undeprecate and update bytes! macro. #18702

wants to merge 2 commits into from

Conversation

mahkoh
Copy link
Contributor

@mahkoh mahkoh commented Nov 6, 2014

  1. Undeprecate bytes!
  2. Make it possible to use bytes! on the RHS of a const.

See rust-lang/rfcs#69 (comment) and the following for a discussion.

This will now expand to

{
    const BYTES: [u8, ..N] = [...];
    &BYTES
}

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 6, 2014

Also note that the problems found by @SimonSapin in #13955 have been fixed.

@SimonSapin
Copy link
Contributor

How does this expansion differ from &[…] ? How is #13955 fixed?

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 6, 2014

@SimonSapin: I don't know if it differs from &[...]. I just changed the existing code from static to const. #13955 has been fixed in #18504

@SimonSapin
Copy link
Contributor

#18504 doesn’t fix #13955, bytes!("ä") and bytes!("\u00FF") still encode to UTF-8.

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 6, 2014

Which is not confusing at all. rust will just use the exact representation found in the source code file (which already has to be UTF8.) The problem you described in #13955 was about \xHH which is indeed confusing because it behaves differently in other languages. \uHHHH translating to the UTF8 representation is the expected behavior which you can also find in other languages.

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 6, 2014

E.g.

#include <stdio.h>
#include <string.h>

int main(void) {
    printf("%zu\n", strlen("ä"));
    printf("%zu\n", strlen("\u00FF"));
    printf("%zu\n", strlen("\xFF"));
}
2
2
1

@SimonSapin
Copy link
Contributor

This is about #13955, so I responded there.

@bstrie
Copy link
Contributor

bstrie commented Nov 21, 2014

Given that this undeprecates something that was deprecated by a prior RFC, I'd like some more opinions on this. @cmr, in the original RFC you seemed to think that bytestrings did not warrant deprecation of bytes!. Care to chime in?

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 21, 2014

Note that the previous RFC did not deprecate bytes!. This is only mentioned in the unresolved questions.

@emberian
Copy link
Member

@bstrie I still think it's valuable.

@alexcrichton
Copy link
Member

As modifications to the prelude require an RFC, I'm going to close this for that requirement and out of inactivity. While it is true that byte string literals did not obsolete this macro entirely, this is one of the main reasons we will be developing the syntax extension interface after 1.0 so a semi-niche macro such as this can live outside of the compiler.

lnicola pushed a commit to lnicola/rust that referenced this pull request Dec 23, 2024
minor: Use a record struct instead of a tuple for each namespace in `PerNs`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants