Skip to content

Lint to warn against unnecessary extra hashes in raw string literals #10882

Closed
@SabrinaJewson

Description

@SabrinaJewson

What it does

Checks for the use of more hashes that are necessary in r#…#-style literals, and emits a warning about it telling you to use fewer hashes. Suggested name: needless_raw_string_hashes; suggested categories: style or pedantic.

Advantage

  • Code is kept more consistent; there are fewer ways to express one piece of logic.
  • Code automatically self-documents the level of “rawness” needed in the string literal.

Drawbacks

  • Sometimes for alignment purposes one might want to add more hashes than necessary.
  • Maybe this should be in rustfmt instead?

Example

let s = r##"Hello "world"!"##;

Could be written as:

let s = r#"Hello "world"!"#;

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions