`invalid_regex` example is wrong
See https://clippy.rust-lang.org/master/#invalid_regex
Use instead:
Regex::new("\(")
produces:
error: unknown character escape: `(`
--> src/lib.rs:1:14
|
1 | Regex::new("\(")
| ^ unknown character escape
|
= help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals>
help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal
|
1 | Regex::new(r"\(")
| +
Proposed Fix
In clippy_lints/src/regex.rs, the INVALID_REGEX documentation example suggested Regex::new("\("). In standard Rust string literals, \( is not a valid escape sequence and causes error: unknown character escape: \(.
We updated the example to use an idiomatic raw string literal:
/// Use instead:
/// ```ignore
/// Regex::new(r"\(")
/// ```
Verification
cargo dev fmt --check: Clean (no diff).cargo check -p clippy_lints: Clean (zero errors, zero warnings).
Committed and pushed to fork branch:
duongynhi000005-oss/rust-clippy:fix/issue-17926-invalid-regex-doc-example (commit e235e50).
Happy to submit a PR if you would like!
Hi, I’d like to work on this documentation fix. Is anyone already preparing a PR for it? If not, I’m happy to submit one with the corrected raw string example and verify the documentation build.
@Bimal-ray99 you could claim the issue by typing the @rustbot claim text.
@rustbot claim