forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#61883 - zackmdavis:non_ascii_idents_lint, r…
…=Manishearth `non_ascii_idents` lint (part of RFC 2457) RFC 2457 [declares](https://github.com/rust-lang/rfcs/blob/121bbeff500c3274cea22c7e0ca176274d592646/text/2457-non-ascii-idents.md): "A `non_ascii_idents` lint is added to the compiler. This lint is allow by default." (Part of rust-lang#55467.) r? @Manishearth
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; | ||
use syntax::ast; | ||
|
||
declare_lint! { | ||
pub NON_ASCII_IDENTS, | ||
Allow, | ||
"detects non-ASCII identifiers" | ||
} | ||
|
||
declare_lint_pass!(NonAsciiIdents => [NON_ASCII_IDENTS]); | ||
|
||
impl EarlyLintPass for NonAsciiIdents { | ||
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) { | ||
if !ident.name.as_str().is_ascii() { | ||
let mut err = cx.struct_span_lint( | ||
NON_ASCII_IDENTS, | ||
ident.span, | ||
"identifier contains non-ASCII characters", | ||
); | ||
err.emit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(non_ascii_idents)] | ||
#![deny(non_ascii_idents)] | ||
|
||
const חלודה: usize = 2; //~ ERROR identifier contains non-ASCII characters | ||
|
||
fn coöperation() {} //~ ERROR identifier contains non-ASCII characters | ||
|
||
fn main() { | ||
let naïveté = 2; //~ ERROR identifier contains non-ASCII characters | ||
println!("{}", naïveté); //~ ERROR identifier contains non-ASCII characters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
error: identifier contains non-ASCII characters | ||
--> $DIR/lint-non-ascii-idents.rs:4:7 | ||
| | ||
LL | const חלודה: usize = 2; | ||
| ^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/lint-non-ascii-idents.rs:2:9 | ||
| | ||
LL | #![deny(non_ascii_idents)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: identifier contains non-ASCII characters | ||
--> $DIR/lint-non-ascii-idents.rs:6:4 | ||
| | ||
LL | fn coöperation() {} | ||
| ^^^^^^^^^^^ | ||
|
||
error: identifier contains non-ASCII characters | ||
--> $DIR/lint-non-ascii-idents.rs:9:9 | ||
| | ||
LL | let naïveté = 2; | ||
| ^^^^^^^ | ||
|
||
error: identifier contains non-ASCII characters | ||
--> $DIR/lint-non-ascii-idents.rs:10:20 | ||
| | ||
LL | println!("{}", naïveté); | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|