Skip to content

non_ascii_literal should not be machine-applicable to raw strings #9805

Open
@alexjago

Description

@alexjago

Summary

non_ascii_literal is machine-applied by substituting unicode escapes. However, those are incompatible with raw strings.

(And if like me you try using raw strings as formatting targets, you'll then get errors about invalid references to positional arguments.)

Reproducer

This code should trigger the lint:

format!(r#"a raw string with a range {}–{} (and an en dash)"#, 31, 0);

cargo clippy --fix reported the following:

The following errors were reported:
error: invalid reference to positional argument 2013 (there are (...) arguments)
   --> src/filename.rs:(line):(col)
    |
line |         format!(r#"a raw string with a range {}\u{2013}{} (and an en dash)"#, 31, 0);

Version

rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-apple-darwin
release: 1.62.1
LLVM version: 14.0.5

Additional Labels

@rustbot +label I-suggestion-causes-error I-false-positive

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions