Skip to content

Commit 0ae61d8

Browse files
committed
in which the non_ascii_idents lint appears (RFC 2457)
RFC 2457 declares: "A `non_ascii_idents` lint is added to the compiler. This lint is allow by default."
1 parent fc550d4 commit 0ae61d8

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

src/librustc_lint/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod nonstandard_style;
3131
pub mod builtin;
3232
mod types;
3333
mod unused;
34+
mod non_ascii_idents;
3435

3536
use rustc::lint;
3637
use rustc::lint::{EarlyContext, LateContext, LateLintPass, EarlyLintPass, LintPass, LintArray};
@@ -63,6 +64,7 @@ use nonstandard_style::*;
6364
use builtin::*;
6465
use types::*;
6566
use unused::*;
67+
use non_ascii_idents::*;
6668
use rustc::lint::internal::*;
6769

6870
/// Useful for other parts of the compiler.
@@ -98,6 +100,7 @@ macro_rules! early_lint_passes {
98100
EllipsisInclusiveRangePatterns: EllipsisInclusiveRangePatterns::default(),
99101
NonCamelCaseTypes: NonCamelCaseTypes,
100102
DeprecatedAttr: DeprecatedAttr::new(),
103+
NonAsciiIdents: NonAsciiIdents,
101104
]);
102105
)
103106
}

src/librustc_lint/non_ascii_idents.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
2+
use syntax::ast;
3+
4+
declare_lint! {
5+
pub NON_ASCII_IDENTS,
6+
Allow,
7+
"detects non-ASCII identifiers"
8+
}
9+
10+
declare_lint_pass!(NonAsciiIdents => [NON_ASCII_IDENTS]);
11+
12+
impl EarlyLintPass for NonAsciiIdents {
13+
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
14+
if !ident.name.as_str().is_ascii() {
15+
let mut err = cx.struct_span_lint(
16+
NON_ASCII_IDENTS,
17+
ident.span,
18+
"identifier contains non-ASCII characters",
19+
);
20+
err.emit();
21+
}
22+
}
23+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(non_ascii_idents)]
2+
#![deny(non_ascii_idents)]
3+
4+
const חלודה: usize = 2; //~ ERROR identifier contains non-ASCII characters
5+
6+
fn coöperation() {} //~ ERROR identifier contains non-ASCII characters
7+
8+
fn main() {
9+
let naïveté = 2; //~ ERROR identifier contains non-ASCII characters
10+
println!("{}", naïveté); //~ ERROR identifier contains non-ASCII characters
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: identifier contains non-ASCII characters
2+
--> $DIR/lint-non-ascii-idents.rs:4:7
3+
|
4+
LL | const חלודה: usize = 2;
5+
| ^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/lint-non-ascii-idents.rs:2:9
9+
|
10+
LL | #![deny(non_ascii_idents)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: identifier contains non-ASCII characters
14+
--> $DIR/lint-non-ascii-idents.rs:6:4
15+
|
16+
LL | fn coöperation() {}
17+
| ^^^^^^^^^^^
18+
19+
error: identifier contains non-ASCII characters
20+
--> $DIR/lint-non-ascii-idents.rs:9:9
21+
|
22+
LL | let naïveté = 2;
23+
| ^^^^^^^
24+
25+
error: identifier contains non-ASCII characters
26+
--> $DIR/lint-non-ascii-idents.rs:10:20
27+
|
28+
LL | println!("{}", naïveté);
29+
| ^^^^^^^
30+
31+
error: aborting due to 4 previous errors
32+

0 commit comments

Comments
 (0)