Skip to content

Commit

Permalink
Feature gate non-ASCII lifetime identifiers
Browse files Browse the repository at this point in the history
Fixes #19069.
  • Loading branch information
Jakub Bukaj committed Nov 18, 2014
1 parent c8d6e3b commit bde225e
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/librustc/lint/builtin.rs
Expand Up @@ -992,7 +992,7 @@ impl LintPass for NonSnakeCase {
self.check_snake_case(cx, "trait method", t.ident, t.span);
}

fn check_lifetime_decl(&mut self, cx: &Context, t: &ast::LifetimeDef) {
fn check_lifetime_def(&mut self, cx: &Context, t: &ast::LifetimeDef) {
self.check_snake_case(cx, "lifetime", t.lifetime.name.ident(), t.lifetime.span);
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Expand Up @@ -725,8 +725,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
run_lints!(self, check_lifetime_ref, lt);
}

fn visit_lifetime_decl(&mut self, lt: &ast::LifetimeDef) {
run_lints!(self, check_lifetime_decl, lt);
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) {
run_lints!(self, check_lifetime_def, lt);
}

fn visit_explicit_self(&mut self, es: &ast::ExplicitSelf) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Expand Up @@ -155,7 +155,7 @@ pub trait LintPass {
fn check_variant_post(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<ast::Lifetime>) { }
fn check_lifetime_ref(&mut self, _: &Context, _: &ast::Lifetime) { }
fn check_lifetime_decl(&mut self, _: &Context, _: &ast::LifetimeDef) { }
fn check_lifetime_def(&mut self, _: &Context, _: &ast::LifetimeDef) { }
fn check_explicit_self(&mut self, _: &Context, _: &ast::ExplicitSelf) { }
fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
fn check_path(&mut self, _: &Context, _: &ast::Path, _: ast::NodeId) { }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -226,7 +226,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
self.with(LateScope(&trait_ref.bound_lifetimes, self.scope), |this| {
this.check_lifetime_defs(&trait_ref.bound_lifetimes);
for lifetime in trait_ref.bound_lifetimes.iter() {
this.visit_lifetime_decl(lifetime);
this.visit_lifetime_def(lifetime);
}
this.visit_trait_ref(&trait_ref.trait_ref)
})
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_back/svh.rs
Expand Up @@ -181,7 +181,7 @@ mod svh_visitor {
SawStructDef(token::InternedString),

SawLifetimeRef(token::InternedString),
SawLifetimeDecl(token::InternedString),
SawLifetimeDef(token::InternedString),

SawMod,
SawViewItem,
Expand Down Expand Up @@ -414,8 +414,8 @@ mod svh_visitor {
SawLifetimeRef(content(l.name)).hash(self.st);
}

fn visit_lifetime_decl(&mut self, l: &LifetimeDef) {
SawLifetimeDecl(content(l.lifetime.name)).hash(self.st);
fn visit_lifetime_def(&mut self, l: &LifetimeDef) {
SawLifetimeDef(content(l.lifetime.name)).hash(self.st);
}

// We do recursively walk the bodies of functions/methods
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_map/mod.rs
Expand Up @@ -866,7 +866,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
self.insert(lifetime.id, NodeLifetime(lifetime));
}

fn visit_lifetime_decl(&mut self, def: &'ast LifetimeDef) {
fn visit_lifetime_def(&mut self, def: &'ast LifetimeDef) {
self.visit_lifetime_ref(&def.lifetime);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_util.rs
Expand Up @@ -535,7 +535,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
self.operation.visit_id(lifetime.id);
}

fn visit_lifetime_decl(&mut self, def: &'v LifetimeDef) {
fn visit_lifetime_def(&mut self, def: &'v LifetimeDef) {
self.visit_lifetime_ref(&def.lifetime);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -141,8 +141,8 @@ impl<'a> Context<'a> {
}

impl<'a, 'v> Visitor<'v> for Context<'a> {
fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
if !token::get_ident(id).get().is_ascii() {
fn visit_name(&mut self, sp: Span, name: ast::Name) {
if !token::get_name(name).get().is_ascii() {
self.gate_feature("non_ascii_idents", sp,
"non-ascii idents are not fully supported.");
}
Expand Down
26 changes: 19 additions & 7 deletions src/libsyntax/visit.rs
Expand Up @@ -55,8 +55,11 @@ pub enum FnKind<'a> {
/// new default implementation gets introduced.)
pub trait Visitor<'v> {

fn visit_ident(&mut self, _sp: Span, _ident: Ident) {
/*! Visit the idents */
fn visit_name(&mut self, _span: Span, _name: Name) {
// Nothing to do.
}
fn visit_ident(&mut self, span: Span, ident: Ident) {
self.visit_name(span, ident.name);
}
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
fn visit_view_item(&mut self, i: &'v ViewItem) { walk_view_item(self, i) }
Expand Down Expand Up @@ -102,11 +105,11 @@ pub trait Visitor<'v> {
None => ()
}
}
fn visit_lifetime_ref(&mut self, _lifetime: &'v Lifetime) {
/*! Visits a reference to a lifetime */
fn visit_lifetime_ref(&mut self, lifetime: &'v Lifetime) {
self.visit_name(lifetime.span, lifetime.name)
}
fn visit_lifetime_decl(&mut self, _lifetime: &'v LifetimeDef) {
/*! Visits a declaration of a lifetime */
fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
walk_lifetime_def(self, lifetime)
}
fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
walk_explicit_self(self, es)
Expand Down Expand Up @@ -207,6 +210,14 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
walk_expr_opt(visitor, &local.init);
}

pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V,
lifetime_def: &'v LifetimeDef) {
visitor.visit_lifetime_ref(&lifetime_def.lifetime);
for bound in lifetime_def.bounds.iter() {
visitor.visit_lifetime_ref(bound);
}
}

pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V,
explicit_self: &'v ExplicitSelf) {
match explicit_self.node {
Expand Down Expand Up @@ -424,7 +435,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
pub fn walk_lifetime_decls_helper<'v, V: Visitor<'v>>(visitor: &mut V,
lifetimes: &'v Vec<LifetimeDef>) {
for l in lifetimes.iter() {
visitor.visit_lifetime_decl(l);
visitor.visit_lifetime_def(l);
}
}

Expand Down Expand Up @@ -555,6 +566,7 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V,

pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
for type_parameter in generics.ty_params.iter() {
visitor.visit_ident(type_parameter.span, type_parameter.ident);
walk_ty_param_bounds_helper(visitor, &type_parameter.bounds);
match type_parameter.default {
Some(ref ty) => visitor.visit_ty(&**ty),
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/utf8_idents.rs
@@ -0,0 +1,24 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// ignore-lexer-test FIXME #15679

fn foo<
'β, //~ ERROR non-ascii idents are not fully supported.
γ //~ ERROR non-ascii idents are not fully supported.
>() {}

struct X {
δ: uint //~ ERROR non-ascii idents are not fully supported.
}

pub fn main() {
let α = 0.00001f64; //~ ERROR non-ascii idents are not fully supported.
}

0 comments on commit bde225e

Please sign in to comment.