Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non_ascii_literal example should be more verbose #4117

Closed
ghost opened this issue May 20, 2019 · 1 comment · Fixed by #4119
Closed

non_ascii_literal example should be more verbose #4117

ghost opened this issue May 20, 2019 · 1 comment · Fixed by #4119

Comments

@ghost
Copy link

ghost commented May 20, 2019

Currently, the doc for non_ascii_literal isn't showing what to do better.

I think including a "Could be written:" example would be helpful. Just like clippy does in the console.

Instead of just let x = "Hä?".
Something like this would be better.

 String::from("€");
    |         ^^^
    |
    = help: Consider replacing the string with:
            ""\u{20ac}""

I can make a PR, if someone tells me where I can find this lint :)

@flip1995
Copy link
Member

You can find the documentation of this lint here:

/// **Example:**
/// ```rust
/// let x = "Hä?"
/// ```


If you want to do some extra work, to make the lint even better, you can change these span_help_and_lint:

span_help_and_lint(
cx,
NON_ASCII_LITERAL,
span,
"literal non-ASCII character detected",
&format!(
"Consider replacing the string with:\n\"{}\"",
if is_allowed(cx, UNICODE_NOT_NFC, id) {
escape(string.chars())
} else {
escape(string.nfc())
}
),
);

with span_lint_and_sugg, so that the suggestion is displayed more idiomatically and is auto-fixable.

The applicability should me MachineApplicable.

@ghost ghost mentioned this issue May 20, 2019
flip1995 added a commit to flip1995/rust-clippy that referenced this issue May 27, 2019
Improve non ascii literal

This PR improves the example of the [non_ascii_literal](https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal) lint.
It also makes it auto-fixable.

Please review. This is my first PR to this project.
(Thanks @flip1995 for the help :)

changelog: none
fixes rust-lang#4117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant