From 4a1336401072bdbac9601c97e278795b1a4b9763 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 17 Dec 2013 03:01:40 +0900 Subject: [PATCH] Remove obsolete mutability from ast::Ty --- src/librustc/middle/typeck/astconv.rs | 25 ++++++++++++++++--------- src/librustdoc/clean.rs | 8 ++++---- src/libsyntax/ast.rs | 6 +++--- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/format.rs | 2 +- src/libsyntax/fold.rs | 8 ++++---- src/libsyntax/parse/parser.rs | 17 ++++++++--------- src/libsyntax/print/pprust.rs | 18 +++++------------- src/libsyntax/visit.rs | 10 ++++++---- 9 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 5a437fce0a5..eb17955f050 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -282,6 +282,12 @@ pub fn ast_path_to_ty( pub fn ast_ty_to_ty( this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t { + fn ast_ty_to_mt( + this: &AC, rscope: &RS, ty: &ast::Ty) -> ty::mt { + + ty::mt {ty: ast_ty_to_ty(this, rscope, ty), mutbl: ast::MutImmutable} + } + fn ast_mt_to_mt( this: &AC, rscope: &RS, mt: &ast::mt) -> ty::mt { @@ -303,8 +309,8 @@ fn mk_pointer { - let mut mt = ast_mt_to_mt(this, rscope, mt); + ast::ty_vec(ty) => { + let mut mt = ast_ty_to_mt(this, rscope, ty); if a_seq_ty.mutbl == ast::MutMutable { mt = ty::mt { ty: mt.ty, mutbl: a_seq_ty.mutbl }; } @@ -394,14 +400,15 @@ fn check_path_args(tcx: ty::ctxt, mk_pointer(this, rscope, mt, ty::vstore_box, |tmt| ty::mk_box(tcx, tmt)) } - ast::ty_uniq(ref mt) => { - mk_pointer(this, rscope, mt, ty::vstore_uniq, + ast::ty_uniq(ty) => { + let mt = ast::mt { ty: ty, mutbl: ast::MutImmutable }; + mk_pointer(this, rscope, &mt, ty::vstore_uniq, |tmt| ty::mk_uniq(tcx, tmt)) } - ast::ty_vec(ref mt) => { + ast::ty_vec(ty) => { tcx.sess.span_err(ast_ty.span, "bare `[]` is not a type"); // return /something/ so they can at least get more errors - ty::mk_evec(tcx, ast_mt_to_mt(this, rscope, mt), ty::vstore_uniq) + ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty), ty::vstore_uniq) } ast::ty_ptr(ref mt) => { ty::mk_ptr(tcx, ast_mt_to_mt(this, rscope, mt)) @@ -532,15 +539,15 @@ fn check_path_args(tcx: ty::ctxt, } } } - ast::ty_fixed_length_vec(ref a_mt, e) => { + ast::ty_fixed_length_vec(ty, e) => { match const_eval::eval_const_expr_partial(&tcx, e) { Ok(ref r) => { match *r { const_eval::const_int(i) => - ty::mk_evec(tcx, ast_mt_to_mt(this, rscope, a_mt), + ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty), ty::vstore_fixed(i as uint)), const_eval::const_uint(i) => - ty::mk_evec(tcx, ast_mt_to_mt(this, rscope, a_mt), + ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty), ty::vstore_fixed(i as uint)), _ => { tcx.sess.span_fatal( diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index e4f0b8ceb81..443293818af 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -621,10 +621,10 @@ fn clean(&self) -> Type { BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(), type_: ~m.ty.clean()}, ty_box(ref m) => Managed(m.mutbl.clean(), ~m.ty.clean()), - ty_uniq(ref m) => Unique(~m.ty.clean()), - ty_vec(ref m) => Vector(~m.ty.clean()), - ty_fixed_length_vec(ref m, ref e) => FixedVector(~m.ty.clean(), - e.span.to_src()), + ty_uniq(ty) => Unique(~ty.clean()), + ty_vec(ty) => Vector(~ty.clean()), + ty_fixed_length_vec(ty, ref e) => FixedVector(~ty.clean(), + e.span.to_src()), ty_tup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()), ty_path(ref p, ref tpbs, id) => resolve_type(p.clean(), tpbs.clean(), id), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e64e1615041..8e6e0625138 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -875,9 +875,9 @@ pub enum ty_ { ty_nil, ty_bot, /* bottom type */ ty_box(mt), - ty_uniq(mt), - ty_vec(mt), - ty_fixed_length_vec(mt, @Expr), + ty_uniq(P), + ty_vec(P), + ty_fixed_length_vec(P, @Expr), ty_ptr(mt), ty_rptr(Option, mt), ty_closure(@TyClosure), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 8a8de3906c4..930d25e7443 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -312,7 +312,7 @@ fn ty_rptr(&self, ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl))) } fn ty_uniq(&self, span: Span, ty: P) -> P { - self.ty(span, ast::ty_uniq(self.ty_mt(ty, ast::MutImmutable))) + self.ty(span, ast::ty_uniq(ty)) } fn ty_box(&self, span: Span, ty: P, mutbl: ast::Mutability) -> P { diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 9193a9cee17..98ebc24427d 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -593,7 +593,7 @@ fn to_expr(&self, extra: @ast::Expr) -> @ast::Expr { ~[] ), None); let ty = ast::ty_fixed_length_vec( - self.ecx.ty_mt(piece_ty, ast::MutImmutable), + piece_ty, self.ecx.expr_uint(self.fmtsp, self.pieces.len()) ); let ty = self.ecx.ty(self.fmtsp, ty); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 3547fa8251b..a7faeee494e 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -241,8 +241,8 @@ fn fold_ty(&self, t: P) -> P { let node = match t.node { ty_nil | ty_bot | ty_infer => t.node.clone(), ty_box(ref mt) => ty_box(fold_mt(mt, self)), - ty_uniq(ref mt) => ty_uniq(fold_mt(mt, self)), - ty_vec(ref mt) => ty_vec(fold_mt(mt, self)), + ty_uniq(ty) => ty_uniq(self.fold_ty(ty)), + ty_vec(ty) => ty_vec(self.fold_ty(ty)), ty_ptr(ref mt) => ty_ptr(fold_mt(mt, self)), ty_rptr(ref region, ref mt) => { ty_rptr(fold_opt_lifetime(region, self), fold_mt(mt, self)) @@ -272,8 +272,8 @@ fn fold_ty(&self, t: P) -> P { fold_opt_bounds(bounds, self), self.new_id(id)) } - ty_fixed_length_vec(ref mt, e) => { - ty_fixed_length_vec(fold_mt(mt, self), self.fold_expr(e)) + ty_fixed_length_vec(ty, e) => { + ty_fixed_length_vec(self.fold_ty(ty), self.fold_expr(e)) } ty_typeof(expr) => ty_typeof(self.fold_expr(expr)), }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 33e3bae99a7..9ab6cc96d33 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1213,11 +1213,11 @@ pub fn parse_ty(&self, _: bool) -> P { } else if *self.token == token::AT { // MANAGED POINTER self.bump(); - self.parse_box_or_uniq_pointee(ManagedSigil, ty_box) + self.parse_box_or_uniq_pointee(ManagedSigil) } else if *self.token == token::TILDE { // OWNED POINTER self.bump(); - self.parse_box_or_uniq_pointee(OwnedSigil, ty_uniq) + self.parse_box_or_uniq_pointee(OwnedSigil) } else if *self.token == token::BINOP(token::STAR) { // STAR POINTER (bare pointer?) self.bump(); @@ -1225,13 +1225,13 @@ pub fn parse_ty(&self, _: bool) -> P { } else if *self.token == token::LBRACKET { // VECTOR self.expect(&token::LBRACKET); - let mt = mt { ty: self.parse_ty(false), mutbl: MutImmutable }; + let t = self.parse_ty(false); // Parse the `, ..e` in `[ int, ..e ]` // where `e` is a const expression let t = match self.maybe_parse_fixed_vstore() { - None => ty_vec(mt), - Some(suffix) => ty_fixed_length_vec(mt, suffix) + None => ty_vec(t), + Some(suffix) => ty_fixed_length_vec(t, suffix) }; self.expect(&token::RBRACKET); t @@ -1284,8 +1284,7 @@ pub fn parse_ty(&self, _: bool) -> P { // parse the type following a @ or a ~ pub fn parse_box_or_uniq_pointee(&self, - sigil: ast::Sigil, - ctor: |v: mt| -> ty_) + sigil: ast::Sigil) -> ty_ { // ~'foo fn() or ~fn() are parsed directly as obsolete fn types: match *self.token { @@ -1309,9 +1308,9 @@ pub fn parse_box_or_uniq_pointee(&self, // rather than boxed ptrs. But the special casing of str/vec is not // reflected in the AST type. if sigil == OwnedSigil { - ctor(mt { ty: self.parse_ty(false), mutbl: MutImmutable }) + ty_uniq(self.parse_ty(false)) } else { - ctor(self.parse_mt()) + ty_box(self.parse_mt()) } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 568501a73bb..7cea2ed3f9c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -401,14 +401,10 @@ pub fn print_type(s: @ps, ty: &ast::Ty) { ast::ty_nil => word(s.s, "()"), ast::ty_bot => word(s.s, "!"), ast::ty_box(ref mt) => { word(s.s, "@"); print_mt(s, mt); } - ast::ty_uniq(ref mt) => { word(s.s, "~"); print_mt(s, mt); } - ast::ty_vec(ref mt) => { + ast::ty_uniq(ty) => { word(s.s, "~"); print_type(s, ty); } + ast::ty_vec(ty) => { word(s.s, "["); - match mt.mutbl { - ast::MutMutable => word_space(s, "mut"), - ast::MutImmutable => () - } - print_type(s, mt.ty); + print_type(s, ty); word(s.s, "]"); } ast::ty_ptr(ref mt) => { word(s.s, "*"); print_mt(s, mt); } @@ -444,13 +440,9 @@ pub fn print_type(s: @ps, ty: &ast::Ty) { Some(&generics), None); } ast::ty_path(ref path, ref bounds, _) => print_bounded_path(s, path, bounds), - ast::ty_fixed_length_vec(ref mt, v) => { + ast::ty_fixed_length_vec(ty, v) => { word(s.s, "["); - match mt.mutbl { - ast::MutMutable => word_space(s, "mut"), - ast::MutImmutable => () - } - print_type(s, mt.ty); + print_type(s, ty); word(s.s, ", .."); print_expr(s, v); word(s.s, "]"); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 5d36109e454..f5471373b62 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -298,8 +298,10 @@ pub fn skip_ty>(_: &mut V, _: &Ty, _: E) { pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { match typ.node { - ty_box(ref mutable_type) | ty_uniq(ref mutable_type) | - ty_vec(ref mutable_type) | ty_ptr(ref mutable_type) => { + ty_uniq(ty) | ty_vec(ty) => { + visitor.visit_ty(ty, env) + } + ty_box(ref mutable_type) | ty_ptr(ref mutable_type) => { visitor.visit_ty(mutable_type.ty, env) } ty_rptr(ref lifetime, ref mutable_type) => { @@ -340,8 +342,8 @@ pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { walk_ty_param_bounds(visitor, bounds, env.clone()) } } - ty_fixed_length_vec(ref mutable_type, expression) => { - visitor.visit_ty(mutable_type.ty, env.clone()); + ty_fixed_length_vec(ty, expression) => { + visitor.visit_ty(ty, env.clone()); visitor.visit_expr(expression, env) } ty_typeof(expression) => { -- GitLab