-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Improve raw string diagnostic #61255
Conversation
f8d3b2d
to
541d42e
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
541d42e
to
6e90f7f
Compare
cc @matklad |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Should I rebase the 7 commits into one before the actual merge happens? |
No, it's fine. Each commit actually follows reasonable work units. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach. Please clean up indentation throughout and make the wording changes.
Does this PR change how code is broken up into tokens? (It shouldn't.)
|
Do you have a prefered folder for that testcase (and name maybe)? |
Unfortunately it does :(
I'll try to fix that tomorrow. |
@@ -2,9 +2,7 @@ error: unterminated raw string | |||
--> $DIR/raw-str-unterminated.rs:2:5 | |||
| | |||
LL | r#" string literal goes on | |||
| ^ unterminated raw string | |||
| | |||
= note: this raw string should be terminated with `"#` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should keep the current note
for this case where no likely close is found.
@petrochenkov good catch. Wasn't aware of that behavior.
The parser now tracks what parser is doing the parsing, and @petrochenkov will probably be able to answer this with certainty, but I believe that you might be able check |
Sadly that's not possible, if I'm correct. rust/src/libsyntax/parse/parser.rs Lines 196 to 236 in c28084a
but I'm not using the |
Don't consume the extra |
☔ The latest upstream changes (presumably #61418) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry, I was away over the last couple of days (holidays in germany :) ). I'm looking into this probably wendsday. I'll going to rebase everything. @estebank Should I remove the error completly or should I instead print a warning? Should I just comment out the code, but leave it there, or remove it? |
If possible, I'd love for these changes to also account for #60793, which unifies the (raw/raw byte) actual scanning and defers the error reporting/validation step. It'd be great to keep these separate, if possible ❤️ |
Leave the prior error behavior there.
Remove the code, there shouldn't ever be commented out code, it only raises questions like "why is this here" or "why wasn't this deleted". Follow the path of least resistance. It's preferable to have solve a part of the whole problem and the rest later than letting the whole problem linger on. |
ping from triage @hellow554 any updates on this? |
@Dylan-DPC not really. Problem is that I hadn't time in a while and last week I started looking at this again. #60793 changed a lot. Need some time to look at the code again. Will update this. |
e63f19d
to
d94b2ff
Compare
Hey @estebank , long time no seen 😊 |
cc @matklad wrt changed raw strings lexer code |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
d94b2ff
to
89bab08
Compare
89bab08
to
0719d0d
Compare
@estebank do you have some time to spare? |
help: you might have meant to end the raw string here | ||
| | ||
LL | '##; | ||
| ^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried about the '##
not being "##
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, the reason for it is, that I look for #
, not for "#[...]
. I think I can change this.
|
||
fn main() { | ||
m!(r#"abc"##); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add another tests with the following combinations?
macro_rules! m {
($tt:tt) => ()
}
fn main() {
m!(r#"abc"##);
}
macro_rules! m {
($tt:tt #) => ()
}
fn main() {
m!(r#"abc"#);
}
Just want us to catch any regressions in the future.
What can I help with? |
Reviewing this PR ^^ Sorry, if I used the not-quite-correct terms :) |
src/libsyntax/parse/lexer/mod.rs
Outdated
fn fail_unterminated_raw_string(&self, start: Span, hash_count: u16, spans: Vec<Span>) -> ! { | ||
const SPAN_THRESHOLD: usize = 3; | ||
const MSG_STR: &str = "you might have meant to end the raw string here"; | ||
let hash_str = format!("\'{}", "#".repeat(hash_count as usize)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let hash_str = format!("\'{}", "#".repeat(hash_count as usize)); | |
let hash_str = format!("\"{}", "#".repeat(hash_count as usize)); |
The lexer now emits a suggestion for `cargo fix`
0719d0d
to
0c00d9f
Compare
With #59706 a lot has changed. I'm not sure if I can keep up with it. :/ |
Ping from triage: Hi @hellow554, Have you had a chance to look at #59706? |
@Alexendoo unfortunately no, I'm going to close this, because I don't feel like I have the time for this. Sorry to say. |
This PR tries to improve unbalanced raw string literals, e.g. too many or too little hashtags in the end.
Unified parsing of rwa byte and raw string literals by introducing a new enum. The difference is that '\r' cannot appear solely in raw strings and that raw byte is ascii only.
Resolves #60762
r? @estebank