-
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
Raw string literal escape depth is technically limited #50111
Comments
On the other hand, this should make for a fairly straightforward beginner's contribution to the compiler: adding a specific error message for too many If anyone wants to do this to get started, I'm happy to mentor it (assuming it hasn't been closed 😄). |
@rust-lang/lang do you want to make some kind of guarantee here or just leave it open for implementations ? |
This seems like a nice first issue for a beginner like me to contribute to, so I'd be happy to tackle this one (w/ some mentoring help)! |
@CMDD: Great! There are two places you'll need to modify in the parser for a custom error message: rust/src/libsyntax/parse/lexer/mod.rs Lines 1439 to 1446 in 52ed3d8
(Which parses raw string literals.) And: rust/src/libsyntax/parse/lexer/mod.rs Lines 1669 to 1676 in 52ed3d8
(Which parses raw byte string literals.) For both, Then you can lower the hash count field in the tokens themselves: rust/src/libsyntax/parse/token.rs Lines 76 to 78 in 52ed3d8
You might need to update some other variables for this to type check ( ./x.py check is helpful here, and 4d34bfd is a similar commit).
Finally, make a new UI test (in src/test/ui — there are lots of examples there) testing the new error. Let me know if you need any more pointers! |
I don't understand why those use |
I think #49993 (comment) confirms my suspicions. I find it odd though, that @nnethercote relied on field reordering instead of putting the |
@nnethercote It was just not immediately obvious why @varkor Also note that there are other limitations in rustc, although most of them are |
@nnethercote: I think I saw your PR and noticed that the limit was (slightly) more reachable. @eddyb: yeah, that's not surprising. I decided to report as in the vein of #40161 (in which the examples are also often unrealistic), but it's probably sensible just to ignore these in general. |
Removing T-doc; this is basically an "implementation defined" kind of thing, and if we were to guarantee any length here, that would go on the reference. Leaving the issue open because it's tracking the diagnostic aspect. |
Add error message for using >= 65535 hashes for raw string literal escapes Fixes #50111.
Add error message for using >= 65535 hashes for raw string literal escapes Fixes #50111.
This is not entirely serious, because I can't imagine this plausibly happening in real-world code (generated or otherwise), but in Nightly (Stable has a higher threshold):
fails to parse with:
This limit is not mentioned in the reference.
I think we should document the maximum number of
#
s. We could also reduce the number permitted: 255 should be enough for anyone (#49993 (comment)).Alternatively, we could ignore it as being a non-problem. Feel free just to close the issue 😄
The text was updated successfully, but these errors were encountered: