Skip to content

Commit

Permalink
sanity -> validation
Browse files Browse the repository at this point in the history
Add test for `::super` in import prefix
  • Loading branch information
petrochenkov committed May 28, 2016
1 parent c02c6e8 commit 731144b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use rustc_privacy;
use rustc_plugin::registry::Registry;
use rustc_plugin as plugin;
use rustc::hir::lowering::lower_crate;
use rustc_passes::{ast_sanity, no_asm, loops, consts, rvalues, static_recursion};
use rustc_passes::{ast_validation, no_asm, loops, consts, rvalues, static_recursion};
use rustc_const_eval::check_match;
use super::Compilation;

Expand Down Expand Up @@ -167,8 +167,8 @@ pub fn compile_input(sess: &Session,
|| lint::check_ast_crate(sess, &expanded_crate));

time(sess.time_passes(),
"AST sanity checking",
|| ast_sanity::check_crate(sess, &expanded_crate));
"AST validation",
|| ast_validation::check_crate(sess, &expanded_crate));

let (analysis, resolutions, mut hir_forest) = {
lower_and_resolve(sess, &id, &mut defs, &expanded_crate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Sanity check AST before lowering it to HIR
// Validate AST before lowering it to HIR
//
// This pass is supposed to catch things that fit into AST data structures,
// but not permitted by the language. It runs after expansion when AST is frozen,
Expand All @@ -24,11 +24,11 @@ use syntax::errors;
use syntax::parse::token::{self, keywords};
use syntax::visit::{self, Visitor};

struct SanityChecker<'a> {
struct AstValidator<'a> {
session: &'a Session,
}

impl<'a> SanityChecker<'a> {
impl<'a> AstValidator<'a> {
fn err_handler(&self) -> &errors::Handler {
&self.session.parse_sess.span_diagnostic
}
Expand Down Expand Up @@ -57,7 +57,7 @@ impl<'a> SanityChecker<'a> {
}
}

impl<'a, 'v> Visitor<'v> for SanityChecker<'a> {
impl<'a, 'v> Visitor<'v> for AstValidator<'a> {
fn visit_lifetime(&mut self, lt: &Lifetime) {
if lt.name.as_str() == "'_" {
self.session.add_lint(
Expand All @@ -72,9 +72,7 @@ impl<'a, 'v> Visitor<'v> for SanityChecker<'a> {
fn visit_expr(&mut self, expr: &Expr) {
match expr.node {
ExprKind::While(_, _, Some(ident)) | ExprKind::Loop(_, Some(ident)) |
ExprKind::WhileLet(_, _, _, Some(ident)) | ExprKind::ForLoop(_, _, _, Some(ident)) => {
self.check_label(ident, expr.span, expr.id);
}
ExprKind::WhileLet(_, _, _, Some(ident)) | ExprKind::ForLoop(_, _, _, Some(ident)) |
ExprKind::Break(Some(ident)) | ExprKind::Again(Some(ident)) => {
self.check_label(ident.node, ident.span, expr.id);
}
Expand Down Expand Up @@ -169,5 +167,5 @@ impl<'a, 'v> Visitor<'v> for SanityChecker<'a> {
}

pub fn check_crate(session: &Session, krate: &Crate) {
visit::walk_crate(&mut SanityChecker { session: session }, krate)
visit::walk_crate(&mut AstValidator { session: session }, krate)
}
2 changes: 1 addition & 1 deletion src/librustc_passes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern crate rustc_const_math;

pub mod diagnostics;

pub mod ast_sanity;
pub mod ast_validation;
pub mod consts;
pub mod loops;
pub mod no_asm;
Expand Down
1 change: 0 additions & 1 deletion src/rustc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/test/compile-fail/use-super-global-path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
// except according to those terms.

#![feature(rustc_attrs)]
#![allow(unused_imports, dead_code)]

struct S;
struct Z;

mod foo {
use ::super::{S, Z}; //~ WARN global paths cannot start with `super`
//~^ WARN this was previously accepted by the compiler but is being phased out

pub fn g() {
use ::super::main; //~ WARN global paths cannot start with `super`
//~^ WARN this was previously accepted by the compiler but is being phased out
Expand Down

0 comments on commit 731144b

Please sign in to comment.