Skip to content

Commit

Permalink
[breaking-change] don't pub export ast::Ty_ variants
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 11, 2016
1 parent ec61e63 commit 05d4cef
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 128 deletions.
27 changes: 14 additions & 13 deletions src/librustc_front/lowering.rs
Expand Up @@ -268,28 +268,29 @@ pub fn lower_ty_binding(lctx: &LoweringContext, b: &TypeBinding) -> hir::TypeBin
}

pub fn lower_ty(lctx: &LoweringContext, t: &Ty) -> P<hir::Ty> {
use syntax::ast::TyKind::*;
P(hir::Ty {
id: t.id,
node: match t.node {
TyInfer => hir::TyInfer,
TyVec(ref ty) => hir::TyVec(lower_ty(lctx, ty)),
TyPtr(ref mt) => hir::TyPtr(lower_mt(lctx, mt)),
TyRptr(ref region, ref mt) => {
Infer => hir::TyInfer,
Vec(ref ty) => hir::TyVec(lower_ty(lctx, ty)),
Ptr(ref mt) => hir::TyPtr(lower_mt(lctx, mt)),
Rptr(ref region, ref mt) => {
hir::TyRptr(lower_opt_lifetime(lctx, region), lower_mt(lctx, mt))
}
TyBareFn(ref f) => {
BareFn(ref f) => {
hir::TyBareFn(P(hir::BareFnTy {
lifetimes: lower_lifetime_defs(lctx, &f.lifetimes),
unsafety: lower_unsafety(lctx, f.unsafety),
abi: f.abi,
decl: lower_fn_decl(lctx, &f.decl),
}))
}
TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(lctx, ty)).collect()),
TyParen(ref ty) => {
Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(lctx, ty)).collect()),
Paren(ref ty) => {
return lower_ty(lctx, ty);
}
TyPath(ref qself, ref path) => {
Path(ref qself, ref path) => {
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: lower_ty(lctx, ty),
Expand All @@ -298,19 +299,19 @@ pub fn lower_ty(lctx: &LoweringContext, t: &Ty) -> P<hir::Ty> {
});
hir::TyPath(qself, lower_path(lctx, path))
}
TyObjectSum(ref ty, ref bounds) => {
ObjectSum(ref ty, ref bounds) => {
hir::TyObjectSum(lower_ty(lctx, ty), lower_bounds(lctx, bounds))
}
TyFixedLengthVec(ref ty, ref e) => {
FixedLengthVec(ref ty, ref e) => {
hir::TyFixedLengthVec(lower_ty(lctx, ty), lower_expr(lctx, e))
}
TyTypeof(ref expr) => {
Typeof(ref expr) => {
hir::TyTypeof(lower_expr(lctx, expr))
}
TyPolyTraitRef(ref bounds) => {
PolyTraitRef(ref bounds) => {
hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(lctx, b)).collect())
}
TyMac(_) => panic!("TyMac should have been expanded by now."),
Mac(_) => panic!("TyMac should have been expanded by now."),
},
span: t.span,
})
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/dump_csv.rs
Expand Up @@ -1063,7 +1063,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
fn visit_ty(&mut self, t: &ast::Ty) {
self.process_macro_use(t.span, t.id);
match t.node {
ast::TyPath(_, ref path) => {
ast::TyKind::Path(_, ref path) => {
match self.lookup_type_ref(t.id) {
Some(id) => {
let sub_span = self.span.sub_span_for_type_name(t.span);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/mod.rs
Expand Up @@ -316,7 +316,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {

match typ.node {
// Common case impl for a struct or something basic.
ast::TyPath(None, ref path) => {
ast::TyKind::Path(None, ref path) => {
sub_span = self.span_utils.sub_span_for_type_name(path.span);
filter!(self.span_utils, sub_span, path.span, None);
type_data = self.lookup_ref_id(typ.id).map(|id| {
Expand Down
35 changes: 17 additions & 18 deletions src/libsyntax/ast.rs
Expand Up @@ -24,7 +24,6 @@ pub use self::Stmt_::*;
pub use self::StrStyle::*;
pub use self::StructFieldKind::*;
pub use self::TraitItem_::*;
pub use self::Ty_::*;
pub use self::TyParamBound::*;
pub use self::UnsafeSource::*;
pub use self::ViewPath_::*;
Expand Down Expand Up @@ -1523,7 +1522,7 @@ pub struct TypeBinding {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Ty {
pub id: NodeId,
pub node: Ty_,
pub node: TyKind,
pub span: Span,
}

Expand All @@ -1543,36 +1542,36 @@ pub struct BareFnTy {

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
/// The different kinds of types recognized by the compiler
pub enum Ty_ {
TyVec(P<Ty>),
pub enum TyKind {
Vec(P<Ty>),
/// A fixed length array (`[T; n]`)
TyFixedLengthVec(P<Ty>, P<Expr>),
FixedLengthVec(P<Ty>, P<Expr>),
/// A raw pointer (`*const T` or `*mut T`)
TyPtr(MutTy),
Ptr(MutTy),
/// A reference (`&'a T` or `&'a mut T`)
TyRptr(Option<Lifetime>, MutTy),
Rptr(Option<Lifetime>, MutTy),
/// A bare function (e.g. `fn(usize) -> bool`)
TyBareFn(P<BareFnTy>),
BareFn(P<BareFnTy>),
/// A tuple (`(A, B, C, D,...)`)
TyTup(Vec<P<Ty>> ),
Tup(Vec<P<Ty>> ),
/// A path (`module::module::...::Type`), optionally
/// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`.
///
/// Type parameters are stored in the Path itself
TyPath(Option<QSelf>, Path),
Path(Option<QSelf>, Path),
/// Something like `A+B`. Note that `B` must always be a path.
TyObjectSum(P<Ty>, TyParamBounds),
ObjectSum(P<Ty>, TyParamBounds),
/// A type like `for<'a> Foo<&'a Bar>`
TyPolyTraitRef(TyParamBounds),
PolyTraitRef(TyParamBounds),
/// No-op; kept solely so that we can pretty-print faithfully
TyParen(P<Ty>),
Paren(P<Ty>),
/// Unused for now
TyTypeof(P<Expr>),
/// TyInfer means the type should be inferred instead of it having been
Typeof(P<Expr>),
/// TyKind::Infer means the type should be inferred instead of it having been
/// specified. This can appear anywhere in a type.
TyInfer,
Infer,
// A macro in the type position.
TyMac(Mac)
Mac(Mac),
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
Expand Down Expand Up @@ -1617,7 +1616,7 @@ impl Arg {
// HACK(eddyb) fake type for the self argument.
ty: P(Ty {
id: DUMMY_NODE_ID,
node: TyInfer,
node: TyKind::Infer,
span: DUMMY_SP,
}),
pat: P(Pat {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/diagnostics/plugin.rs
Expand Up @@ -212,10 +212,10 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,

let ty = ecx.ty(
span,
ast::TyFixedLengthVec(
ast::TyKind::FixedLengthVec(
ecx.ty(
span,
ast::TyTup(vec![ty_str.clone(), ty_str])
ast::TyKind::Tup(vec![ty_str.clone(), ty_str])
),
ecx.expr_usize(span, count),
),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/base.rs
Expand Up @@ -367,7 +367,7 @@ impl DummyResult {
pub fn raw_ty(sp: Span) -> P<ast::Ty> {
P(ast::Ty {
id: ast::DUMMY_NODE_ID,
node: ast::TyInfer,
node: ast::TyKind::Infer,
span: sp
})
}
Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/ext/build.rs
Expand Up @@ -52,7 +52,7 @@ pub trait AstBuilder {
// types
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;

fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>;
fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty>;
fn ty_path(&self, ast::Path) -> P<ast::Ty>;
fn ty_sum(&self, ast::Path, ast::TyParamBounds) -> P<ast::Ty>;
fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
Expand Down Expand Up @@ -385,7 +385,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
}

fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty> {
fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty> {
P(ast::Ty {
id: ast::DUMMY_NODE_ID,
span: span,
Expand All @@ -394,12 +394,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}

fn ty_path(&self, path: ast::Path) -> P<ast::Ty> {
self.ty(path.span, ast::TyPath(None, path))
self.ty(path.span, ast::TyKind::Path(None, path))
}

fn ty_sum(&self, path: ast::Path, bounds: ast::TyParamBounds) -> P<ast::Ty> {
self.ty(path.span,
ast::TyObjectSum(self.ty_path(path),
ast::TyKind::ObjectSum(self.ty_path(path),
bounds))
}

Expand All @@ -417,7 +417,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
mutbl: ast::Mutability)
-> P<ast::Ty> {
self.ty(span,
ast::TyRptr(lifetime, self.ty_mt(ty, mutbl)))
ast::TyKind::Rptr(lifetime, self.ty_mt(ty, mutbl)))
}

fn ty_ptr(&self,
Expand All @@ -426,7 +426,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
mutbl: ast::Mutability)
-> P<ast::Ty> {
self.ty(span,
ast::TyPtr(self.ty_mt(ty, mutbl)))
ast::TyKind::Ptr(self.ty_mt(ty, mutbl)))
}

fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
Expand All @@ -440,7 +440,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}

fn ty_infer(&self, span: Span) -> P<ast::Ty> {
self.ty(span, ast::TyInfer)
self.ty(span, ast::TyKind::Infer)
}

fn typaram(&self,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -562,7 +562,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
DeclKind::Local(local) => {
// take it apart:
let rewritten_local = local.map(|Local {id, pat, ty, init, span, attrs}| {
// expand the ty since TyFixedLengthVec contains an Expr
// expand the ty since TyKind::FixedLengthVec contains an Expr
// and thus may have a macro use
let expanded_ty = ty.map(|t| fld.fold_ty(t));
// expand the pat (it might contain macro uses):
Expand Down Expand Up @@ -1133,7 +1133,7 @@ fn expand_and_rename_method(sig: ast::MethodSig, body: P<ast::Block>,

pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
let t = match t.node.clone() {
ast::Ty_::TyMac(mac) => {
ast::TyKind::Mac(mac) => {
if fld.cx.ecfg.features.unwrap().type_macros {
let expanded_ty = match expand_mac_invoc(mac, t.span,
|r| r.make_ty(),
Expand Down
42 changes: 21 additions & 21 deletions src/libsyntax/fold.rs
Expand Up @@ -380,46 +380,46 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
t.map(|Ty {id, node, span}| Ty {
id: fld.new_id(id),
node: match node {
TyInfer => node,
TyVec(ty) => TyVec(fld.fold_ty(ty)),
TyPtr(mt) => TyPtr(fld.fold_mt(mt)),
TyRptr(region, mt) => {
TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
TyKind::Infer => node,
TyKind::Vec(ty) => TyKind::Vec(fld.fold_ty(ty)),
TyKind::Ptr(mt) => TyKind::Ptr(fld.fold_mt(mt)),
TyKind::Rptr(region, mt) => {
TyKind::Rptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
}
TyBareFn(f) => {
TyBareFn(f.map(|BareFnTy {lifetimes, unsafety, abi, decl}| BareFnTy {
TyKind::BareFn(f) => {
TyKind::BareFn(f.map(|BareFnTy {lifetimes, unsafety, abi, decl}| BareFnTy {
lifetimes: fld.fold_lifetime_defs(lifetimes),
unsafety: unsafety,
abi: abi,
decl: fld.fold_fn_decl(decl)
}))
}
TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))),
TyParen(ty) => TyParen(fld.fold_ty(ty)),
TyPath(qself, path) => {
TyKind::Tup(tys) => TyKind::Tup(tys.move_map(|ty| fld.fold_ty(ty))),
TyKind::Paren(ty) => TyKind::Paren(fld.fold_ty(ty)),
TyKind::Path(qself, path) => {
let qself = qself.map(|QSelf { ty, position }| {
QSelf {
ty: fld.fold_ty(ty),
position: position
}
});
TyPath(qself, fld.fold_path(path))
TyKind::Path(qself, fld.fold_path(path))
}
TyObjectSum(ty, bounds) => {
TyObjectSum(fld.fold_ty(ty),
TyKind::ObjectSum(ty, bounds) => {
TyKind::ObjectSum(fld.fold_ty(ty),
fld.fold_bounds(bounds))
}
TyFixedLengthVec(ty, e) => {
TyFixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
TyKind::FixedLengthVec(ty, e) => {
TyKind::FixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
}
TyTypeof(expr) => {
TyTypeof(fld.fold_expr(expr))
TyKind::Typeof(expr) => {
TyKind::Typeof(fld.fold_expr(expr))
}
TyPolyTraitRef(bounds) => {
TyPolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
TyKind::PolyTraitRef(bounds) => {
TyKind::PolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
}
TyMac(mac) => {
TyMac(fld.fold_mac(mac))
TyKind::Mac(mac) => {
TyKind::Mac(fld.fold_mac(mac))
}
},
span: fld.new_span(span)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/mod.rs
Expand Up @@ -916,7 +916,7 @@ mod tests {
node: ast::ItemFn(P(ast::FnDecl {
inputs: vec!(ast::Arg{
ty: P(ast::Ty{id: ast::DUMMY_NODE_ID,
node: ast::TyPath(None, ast::Path{
node: ast::TyKind::Path(None, ast::Path{
span:sp(10,13),
global:false,
segments: vec!(
Expand Down

0 comments on commit 05d4cef

Please sign in to comment.