Skip to content

Lint "string literals".as_bytes() #560

@fhartwig

Description

@fhartwig

I think it would make sense to suggest using byte string literals instead of calling as_bytes() on &str literals, since byte string literals are less noisy. There is a surprising amount of rust code that uses as_bytes on string literals. Some of it exists because beginners might not know that they can do b"foo" instead of "foo".as_bytes(), some of it seems to pre-date the introduction of byte-string literals.

Complication: the two aren't equivalent if the string literal contains non-ascii characters, so we cannot suggest using b"☃" instead of "☃".as_bytes(), because the former would not compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions