Skip to content
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

invalid_regex: Show full error when string value doesn't match source #10231

Merged
merged 1 commit into from
Jan 29, 2023

Conversation

Alexendoo
Copy link
Member

changelog: [invalid_regex]: Show full error when parsing non-literals or regular strings containing escape sequences

Fixes #4170, the escape sequence there causes the span to be incorrect which will have caused most of the confusion

@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2023

r? @llogiq

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 26, 2023
Comment on lines +97 to +106
error: regex parse error:
/b/c
^^
error: unrecognized escape sequence
--> $DIR/regex.rs:40:42
|
LL | let escaped_string_span = Regex::new("/b/c");
| ^^^^^^^^
|
= help: consider using a raw string literal: `r".."`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compiletest is doing its windows path normalisation thing, it looks like this normally:

error: regex parse error:
           \b\c
             ^^
       error: unrecognized escape sequence
 --> ../t.rs:6:42
  |
6 |     let escaped_string_span = Regex::new("\\b\\c");
  |                                          ^^^^^^^^
  |
  = help: consider using a raw string literal: `r".."`

Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the missing quotation marks when linting a const, this looks good to me. Let me know if you want to tackle this as part of this PR or if you want to leave it for a followup.

tests/ui/regex.stderr Show resolved Hide resolved
@llogiq
Copy link
Contributor

llogiq commented Jan 29, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Jan 29, 2023

📌 Commit 986f40f has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jan 29, 2023

⌛ Testing commit 986f40f with merge 96c28d1...

@bors
Copy link
Contributor

bors commented Jan 29, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 96c28d1 to master...

@bors bors merged commit 96c28d1 into rust-lang:master Jan 29, 2023
@Alexendoo Alexendoo deleted the regex-spans branch January 29, 2023 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unrecognized escape sequence
4 participants