Skip to content

Remove obsolete mutability from ast::Ty #11005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ pub static NO_TPS: uint = 2;
pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t {

fn ast_ty_to_mt<AC:AstConv, RS:RegionScope>(
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<AC:AstConv, RS:RegionScope>(
this: &AC, rscope: &RS, mt: &ast::mt) -> ty::mt {

Expand All @@ -303,8 +309,8 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
debug!("mk_pointer(vst={:?})", vst);

match a_seq_ty.ty.node {
ast::ty_vec(ref mt) => {
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 };
}
Expand Down Expand Up @@ -394,14 +400,15 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
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))
Expand Down Expand Up @@ -532,15 +539,15 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
}
}
}
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(
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,10 @@ impl Clean<Type> for ast::Ty {
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),
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
ty_vec(P<Ty>),
ty_fixed_length_vec(P<Ty>, @Expr),
ty_ptr(mt),
ty_rptr(Option<Lifetime>, mt),
ty_closure(@TyClosure),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl AstBuilder for @ExtCtxt {
ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl)))
}
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
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<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ impl Context {
~[]
), 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);
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ pub trait ast_fold {
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))
Expand Down Expand Up @@ -272,8 +272,8 @@ pub trait ast_fold {
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)),
};
Expand Down
17 changes: 8 additions & 9 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,25 +1213,25 @@ impl Parser {
} 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();
ty_ptr(self.parse_mt())
} 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
Expand Down Expand Up @@ -1284,8 +1284,7 @@ impl Parser {

// 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 {
Expand All @@ -1309,9 +1308,9 @@ impl Parser {
// 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())
}
}

Expand Down
18 changes: 5 additions & 13 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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, "]");
Expand Down
10 changes: 6 additions & 4 deletions src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ pub fn skip_ty<E, V:Visitor<E>>(_: &mut V, _: &Ty, _: E) {

pub fn walk_ty<E:Clone, V:Visitor<E>>(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) => {
Expand Down Expand Up @@ -340,8 +342,8 @@ pub fn walk_ty<E:Clone, V:Visitor<E>>(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) => {
Expand Down