Skip to content

Commit 91d8a4f

Browse files
committed
sanity -> validation
Add missing check_path for paths in import prefixes
1 parent 676a719 commit 91d8a4f

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

src/librustc_driver/driver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc_privacy;
3838
use rustc_plugin::registry::Registry;
3939
use rustc_plugin as plugin;
4040
use rustc::hir::lowering::lower_crate;
41-
use rustc_passes::{ast_sanity, no_asm, loops, consts, rvalues, static_recursion};
41+
use rustc_passes::{ast_validation, no_asm, loops, consts, rvalues, static_recursion};
4242
use rustc_const_eval::check_match;
4343
use super::Compilation;
4444

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

169169
time(sess.time_passes(),
170-
"AST sanity checking",
171-
|| ast_sanity::check_crate(sess, &expanded_crate));
170+
"AST validation",
171+
|| ast_validation::check_crate(sess, &expanded_crate));
172172

173173
let (analysis, resolutions, mut hir_forest) = {
174174
lower_and_resolve(sess, &id, &mut defs, &expanded_crate,

src/librustc_passes/ast_sanity.rs renamed to src/librustc_passes/ast_validation.rs

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

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

27-
struct SanityChecker<'a> {
27+
struct AstValidator<'a> {
2828
session: &'a Session,
2929
}
3030

31-
impl<'a> SanityChecker<'a> {
31+
impl<'a> AstValidator<'a> {
3232
fn err_handler(&self) -> &errors::Handler {
3333
&self.session.parse_sess.span_diagnostic
3434
}
@@ -55,9 +55,21 @@ impl<'a> SanityChecker<'a> {
5555
err.emit();
5656
}
5757
}
58+
59+
fn check_path(&self, path: &Path, id: NodeId) {
60+
if path.global && path.segments.len() > 0 {
61+
let ident = path.segments[0].identifier;
62+
if token::Ident(ident).is_path_segment_keyword() {
63+
self.session.add_lint(
64+
lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
65+
format!("global paths cannot start with `{}`", ident)
66+
);
67+
}
68+
}
69+
}
5870
}
5971

60-
impl<'a, 'v> Visitor<'v> for SanityChecker<'a> {
72+
impl<'a, 'v> Visitor<'v> for AstValidator<'a> {
6173
fn visit_lifetime(&mut self, lt: &Lifetime) {
6274
if lt.name.as_str() == "'_" {
6375
self.session.add_lint(
@@ -85,19 +97,17 @@ impl<'a, 'v> Visitor<'v> for SanityChecker<'a> {
8597
}
8698

8799
fn visit_path(&mut self, path: &Path, id: NodeId) {
88-
if path.global && path.segments.len() > 0 {
89-
let ident = path.segments[0].identifier;
90-
if token::Ident(ident).is_path_segment_keyword() {
91-
self.session.add_lint(
92-
lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
93-
format!("global paths cannot start with `{}`", ident)
94-
);
95-
}
96-
}
100+
self.check_path(path, id);
97101

98102
visit::walk_path(self, path)
99103
}
100104

105+
fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) {
106+
self.check_path(prefix, item.node.id());
107+
108+
visit::walk_path_list_item(self, prefix, item)
109+
}
110+
101111
fn visit_item(&mut self, item: &Item) {
102112
match item.node {
103113
ItemKind::Use(ref view_path) => {
@@ -169,5 +179,5 @@ impl<'a, 'v> Visitor<'v> for SanityChecker<'a> {
169179
}
170180

171181
pub fn check_crate(session: &Session, krate: &Crate) {
172-
visit::walk_crate(&mut SanityChecker { session: session }, krate)
182+
visit::walk_crate(&mut AstValidator { session: session }, krate)
173183
}

src/librustc_passes/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern crate rustc_const_math;
3737

3838
pub mod diagnostics;
3939

40-
pub mod ast_sanity;
40+
pub mod ast_validation;
4141
pub mod consts;
4242
pub mod loops;
4343
pub mod no_asm;

src/test/compile-fail/use-super-global-path.rs

+9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@
99
// except according to those terms.
1010

1111
#![feature(rustc_attrs)]
12+
#![allow(unused_imports, dead_code)]
13+
14+
struct S;
15+
struct Z;
1216

1317
mod foo {
18+
use ::super::{S, Z}; //~ WARN global paths cannot start with `super`
19+
//~^ WARN global paths cannot start with `super`
20+
//~^^ WARN this was previously accepted by the compiler but is being phased out
21+
//~^^^ WARN this was previously accepted by the compiler but is being phased out
22+
1423
pub fn g() {
1524
use ::super::main; //~ WARN global paths cannot start with `super`
1625
//~^ WARN this was previously accepted by the compiler but is being phased out

0 commit comments

Comments
 (0)