Skip to content

Commit

Permalink
rustc: avoid use-ing syntax::ast::*.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Nov 19, 2014
1 parent e09d986 commit 21da750
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 450 deletions.
153 changes: 77 additions & 76 deletions src/librustc/metadata/encoder.rs

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/librustc/metadata/tydecode.rs
Expand Up @@ -27,7 +27,6 @@ use std::str;
use std::string::String;
use syntax::abi;
use syntax::ast;
use syntax::ast::*;
use syntax::parse::token;

// Compact string representation for ty::t values. API ty_str &
Expand Down Expand Up @@ -525,10 +524,10 @@ fn parse_hex(st: &mut PState) -> uint {
};
}

fn parse_fn_style(c: char) -> FnStyle {
fn parse_fn_style(c: char) -> ast::FnStyle {
match c {
'u' => UnsafeFn,
'n' => NormalFn,
'u' => ast::UnsafeFn,
'n' => ast::NormalFn,
_ => panic!("parse_fn_style: bad fn_style {}", c)
}
}
Expand Down
43 changes: 21 additions & 22 deletions src/librustc/metadata/tyencode.rs
Expand Up @@ -23,7 +23,6 @@ use util::nodemap::FnvHashMap;

use syntax::abi::Abi;
use syntax::ast;
use syntax::ast::*;
use syntax::diagnostic::SpanHandler;
use syntax::parse::token;

Expand All @@ -34,7 +33,7 @@ macro_rules! mywrite( ($($arg:tt)*) => ({ write!($($arg)*); }) )
pub struct ctxt<'a, 'tcx: 'a> {
pub diag: &'a SpanHandler,
// Def -> str Callback:
pub ds: fn(DefId) -> String,
pub ds: fn(ast::DefId) -> String,
// The type context.
pub tcx: &'a ty::ctxt<'tcx>,
pub abbrevs: &'a abbrev_map
Expand Down Expand Up @@ -75,8 +74,8 @@ pub fn enc_ty(w: &mut SeekableMemWriter, cx: &ctxt, t: ty::t) {

fn enc_mutability(w: &mut SeekableMemWriter, mt: ast::Mutability) {
match mt {
MutImmutable => (),
MutMutable => mywrite!(w, "m"),
ast::MutImmutable => (),
ast::MutMutable => mywrite!(w, "m"),
}
}

Expand Down Expand Up @@ -203,26 +202,26 @@ fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
ty::ty_char => mywrite!(w, "c"),
ty::ty_int(t) => {
match t {
TyI => mywrite!(w, "i"),
TyI8 => mywrite!(w, "MB"),
TyI16 => mywrite!(w, "MW"),
TyI32 => mywrite!(w, "ML"),
TyI64 => mywrite!(w, "MD")
ast::TyI => mywrite!(w, "i"),
ast::TyI8 => mywrite!(w, "MB"),
ast::TyI16 => mywrite!(w, "MW"),
ast::TyI32 => mywrite!(w, "ML"),
ast::TyI64 => mywrite!(w, "MD")
}
}
ty::ty_uint(t) => {
match t {
TyU => mywrite!(w, "u"),
TyU8 => mywrite!(w, "Mb"),
TyU16 => mywrite!(w, "Mw"),
TyU32 => mywrite!(w, "Ml"),
TyU64 => mywrite!(w, "Md")
ast::TyU => mywrite!(w, "u"),
ast::TyU8 => mywrite!(w, "Mb"),
ast::TyU16 => mywrite!(w, "Mw"),
ast::TyU32 => mywrite!(w, "Ml"),
ast::TyU64 => mywrite!(w, "Md")
}
}
ty::ty_float(t) => {
match t {
TyF32 => mywrite!(w, "Mf"),
TyF64 => mywrite!(w, "MF"),
ast::TyF32 => mywrite!(w, "Mf"),
ast::TyF64 => mywrite!(w, "MF"),
}
}
ty::ty_enum(def, ref substs) => {
Expand Down Expand Up @@ -295,10 +294,10 @@ fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
}
}

fn enc_fn_style(w: &mut SeekableMemWriter, p: FnStyle) {
fn enc_fn_style(w: &mut SeekableMemWriter, p: ast::FnStyle) {
match p {
NormalFn => mywrite!(w, "n"),
UnsafeFn => mywrite!(w, "u"),
ast::NormalFn => mywrite!(w, "n"),
ast::UnsafeFn => mywrite!(w, "u"),
}
}

Expand All @@ -308,10 +307,10 @@ fn enc_abi(w: &mut SeekableMemWriter, abi: Abi) {
mywrite!(w, "]")
}

fn enc_onceness(w: &mut SeekableMemWriter, o: Onceness) {
fn enc_onceness(w: &mut SeekableMemWriter, o: ast::Onceness) {
match o {
Once => mywrite!(w, "o"),
Many => mywrite!(w, "m")
ast::Once => mywrite!(w, "o"),
ast::Many => mywrite!(w, "m")
}
}

Expand Down
84 changes: 42 additions & 42 deletions src/librustc/middle/check_const.rs
Expand Up @@ -14,7 +14,7 @@ use middle::ty;
use middle::typeck;
use util::ppaux;

use syntax::ast::*;
use syntax::ast;
use syntax::ast_util;
use syntax::visit::Visitor;
use syntax::visit;
Expand All @@ -40,13 +40,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
}

impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
fn visit_item(&mut self, i: &Item) {
fn visit_item(&mut self, i: &ast::Item) {
check_item(self, i);
}
fn visit_pat(&mut self, p: &Pat) {
fn visit_pat(&mut self, p: &ast::Pat) {
check_pat(self, p);
}
fn visit_expr(&mut self, ex: &Expr) {
fn visit_expr(&mut self, ex: &ast::Expr) {
if check_expr(self, ex) {
visit::walk_expr(self, ex);
}
Expand All @@ -59,13 +59,13 @@ pub fn check_crate(tcx: &ty::ctxt) {
tcx.sess.abort_if_errors();
}

fn check_item(v: &mut CheckCrateVisitor, it: &Item) {
fn check_item(v: &mut CheckCrateVisitor, it: &ast::Item) {
match it.node {
ItemStatic(_, _, ref ex) |
ItemConst(_, ref ex) => {
ast::ItemStatic(_, _, ref ex) |
ast::ItemConst(_, ref ex) => {
v.inside_const(|v| v.visit_expr(&**ex));
}
ItemEnum(ref enum_definition, _) => {
ast::ItemEnum(ref enum_definition, _) => {
for var in (*enum_definition).variants.iter() {
for ex in var.node.disr_expr.iter() {
v.inside_const(|v| v.visit_expr(&**ex));
Expand All @@ -76,12 +76,12 @@ fn check_item(v: &mut CheckCrateVisitor, it: &Item) {
}
}

fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) {
fn is_str(e: &Expr) -> bool {
fn check_pat(v: &mut CheckCrateVisitor, p: &ast::Pat) {
fn is_str(e: &ast::Expr) -> bool {
match e.node {
ExprBox(_, ref expr) => {
ast::ExprBox(_, ref expr) => {
match expr.node {
ExprLit(ref lit) => ast_util::lit_is_str(&**lit),
ast::ExprLit(ref lit) => ast_util::lit_is_str(&**lit),
_ => false,
}
}
Expand All @@ -90,36 +90,36 @@ fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) {
}
match p.node {
// Let through plain ~-string literals here
PatLit(ref a) => if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); },
PatRange(ref a, ref b) => {
ast::PatLit(ref a) => if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); },
ast::PatRange(ref a, ref b) => {
if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); }
if !is_str(&**b) { v.inside_const(|v| v.visit_expr(&**b)); }
}
_ => v.outside_const(|v| visit::walk_pat(v, p))
}
}

fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
if !v.in_const { return true }

match e.node {
ExprUnary(UnDeref, _) => {}
ExprUnary(UnUniq, _) => {
ast::ExprUnary(ast::UnDeref, _) => {}
ast::ExprUnary(ast::UnUniq, _) => {
span_err!(v.tcx.sess, e.span, E0010,
"cannot do allocations in constant expressions");
return false;
}
ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {}
ExprBinary(..) | ExprUnary(..) => {
ast::ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {}
ast::ExprBinary(..) | ast::ExprUnary(..) => {
let method_call = typeck::MethodCall::expr(e.id);
if v.tcx.method_map.borrow().contains_key(&method_call) {
span_err!(v.tcx.sess, e.span, E0011,
"user-defined operators are not allowed in constant \
expressions");
}
}
ExprLit(_) => (),
ExprCast(ref from, _) => {
ast::ExprLit(_) => (),
ast::ExprCast(ref from, _) => {
let toty = ty::expr_ty(v.tcx, e);
let fromty = ty::expr_ty(v.tcx, &**from);
if !ty::type_is_numeric(toty) && !ty::type_is_unsafe_ptr(toty) {
Expand All @@ -133,7 +133,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
expression");
}
}
ExprPath(ref pth) => {
ast::ExprPath(ref pth) => {
// NB: In the future you might wish to relax this slightly
// to handle on-demand instantiation of functions via
// foo::<bar> in a const. Currently that is only done on
Expand Down Expand Up @@ -161,7 +161,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
}
}
}
ExprCall(ref callee, _) => {
ast::ExprCall(ref callee, _) => {
match v.tcx.def_map.borrow().get(&callee.id) {
Some(&DefStruct(..)) |
Some(&DefVariant(..)) => {} // OK.
Expand All @@ -173,25 +173,25 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
}
}
}
ExprBlock(ref block) => {
ast::ExprBlock(ref block) => {
// Check all statements in the block
for stmt in block.stmts.iter() {
let block_span_err = |span|
span_err!(v.tcx.sess, span, E0016,
"blocks in constants are limited to items and \
tail expressions");
match stmt.node {
StmtDecl(ref span, _) => {
ast::StmtDecl(ref span, _) => {
match span.node {
DeclLocal(_) => block_span_err(span.span),
ast::DeclLocal(_) => block_span_err(span.span),

// Item statements are allowed
DeclItem(_) => {}
ast::DeclItem(_) => {}
}
}
StmtExpr(ref expr, _) => block_span_err(expr.span),
StmtSemi(ref semi, _) => block_span_err(semi.span),
StmtMac(..) => {
ast::StmtExpr(ref expr, _) => block_span_err(expr.span),
ast::StmtSemi(ref semi, _) => block_span_err(semi.span),
ast::StmtMac(..) => {
v.tcx.sess.span_bug(e.span, "unexpanded statement \
macro in const?!")
}
Expand All @@ -202,20 +202,20 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
None => {}
}
}
ExprVec(_) |
ExprAddrOf(MutImmutable, _) |
ExprParen(..) |
ExprField(..) |
ExprTupField(..) |
ExprIndex(..) |
ExprTup(..) |
ExprRepeat(..) |
ExprStruct(..) => {}

ExprAddrOf(_, ref inner) => {
ast::ExprVec(_) |
ast::ExprAddrOf(ast::MutImmutable, _) |
ast::ExprParen(..) |
ast::ExprField(..) |
ast::ExprTupField(..) |
ast::ExprIndex(..) |
ast::ExprTup(..) |
ast::ExprRepeat(..) |
ast::ExprStruct(..) => {}

ast::ExprAddrOf(_, ref inner) => {
match inner.node {
// Mutable slices are allowed.
ExprVec(_) => {}
ast::ExprVec(_) => {}
_ => span_err!(v.tcx.sess, e.span, E0017,
"references in constants may only refer \
to immutable values")
Expand Down

0 comments on commit 21da750

Please sign in to comment.