Skip to content

Warn about non-printable characters in string literals #63682

Open
@matklad

Description

@matklad

Currently a string literal with control characters like \0 or \v is accepted without any warnings. The only exception is \r, which gives a hard error.

It makes more sense to treat all non-printable, non \t, \n ASCII characters as a warning.

Steps to fix:

  1. Add NonPrintableAsii to EscapeError
  2. Produce this error somewhere around here
  3. Add lexer-level tests
  4. Handle this "error" in unespcape_error_reporting. Note that, unlike other real errors, this one should be just a warning.
  5. Adjust the affected ui tests

I am not sure how to make this warning work with #[allow] lint infrastructure: we definitely can't do this in the lexer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions