Skip to content

Commit ab2a99f

Browse files
committed
Put non-ascii identifiers behind a feature gate.
cf. https://mail.mozilla.org/pipermail/rust-dev/2013-November/006920.html
1 parent efe9d74 commit ab2a99f

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

src/librustc/front/feature_gate.rs

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use syntax::attr::AttrMetaMethods;
2323
use syntax::codemap::Span;
2424
use syntax::visit;
2525
use syntax::visit::Visitor;
26+
use syntax::parse::token;
2627

2728
use driver::session::Session;
2829

@@ -36,6 +37,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
3637
("once_fns", Active),
3738
("asm", Active),
3839
("managed_boxes", Active),
40+
("non_ascii_idents", Active),
3941

4042
// These are used to test this portion of the compiler, they don't actually
4143
// mean anything
@@ -76,6 +78,15 @@ impl Context {
7678
}
7779

7880
impl Visitor<()> for Context {
81+
fn visit_ident(&mut self, sp: Span, id: ast::Ident, _: ()) {
82+
let s = token::ident_to_str(&id);
83+
84+
if !s.is_ascii() {
85+
self.gate_feature("non_ascii_idents", sp,
86+
"non-ascii idents are not fully supported.");
87+
}
88+
}
89+
7990
fn visit_view_item(&mut self, i: &ast::view_item, _: ()) {
8091
match i.node {
8192
ast::view_item_use(ref paths) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast feature doesn't work.
12+
13+
#[feature(struct_variant)];
14+
15+
extern mod bäz; //~ ERROR non-ascii idents
16+
17+
use föö::bar; //~ ERROR non-ascii idents
18+
19+
mod föö { //~ ERROR non-ascii idents
20+
pub fn bar() {}
21+
}
22+
23+
fn bär( //~ ERROR non-ascii idents
24+
bäz: int //~ ERROR non-ascii idents
25+
) {
26+
let: int; //~ ERROR non-ascii idents
27+
28+
match (1, 2) {
29+
(, _) => {} //~ ERROR non-ascii idents
30+
}
31+
}
32+
33+
struct Föö { //~ ERROR non-ascii idents
34+
föö: int //~ ERROR non-ascii idents
35+
}
36+
37+
enum Bär { //~ ERROR non-ascii idents
38+
Bäz { //~ ERROR non-ascii idents
39+
qüx: int //~ ERROR non-ascii idents
40+
}
41+
}
42+
43+
extern {
44+
fn qüx(); //~ ERROR non-ascii idents
45+
}
46+
47+
fn main() {}

src/test/run-pass/lint-non-camel-case-types-non-uppercase-statics-unicode.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-fast feature doesn't work.
12+
1113
#[forbid(non_camel_case_types)];
1214
#[forbid(non_uppercase_statics)];
15+
#[feature(non_ascii_idents)];
1316

1417
// Some scripts (e.g. hiragana) don't have a concept of
1518
// upper/lowercase

src/test/run-pass/utf8_idents.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-fast feature doesn't work.
12+
13+
#[feature(non_ascii_idents)];
14+
1115
use std::num;
1216

1317
pub fn main() {

0 commit comments

Comments
 (0)