1
Fork 0

rustc: Accept 'const' as synonym for 'mutable?'

This commit is contained in:
Brian Anderson 2011-11-16 13:52:08 -08:00
parent f157d0b32c
commit 045a437556
5 changed files with 10 additions and 7 deletions

View file

@ -746,10 +746,13 @@ fn parse_path_and_ty_param_substs(p: parser) -> ast::path {
fn parse_mutability(p: parser) -> ast::mutability {
if eat_word(p, "mutable") {
if p.peek() == token::QUES { p.bump(); ret ast::maybe_mut; }
ret ast::mut;
if p.peek() == token::QUES { p.bump(); ast::maybe_mut }
else { ast::mut }
} else if eat_word(p, "const") {
ast::maybe_mut
} else {
ast::imm
}
ret ast::imm;
}
fn parse_field(p: parser, sep: token::token) -> ast::field {

View file

@ -264,7 +264,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
word(s.s, "[");
alt mt.mut {
ast::mut. { word_space(s, "mutable"); }
ast::maybe_mut. { word_space(s, "mutable?"); }
ast::maybe_mut. { word_space(s, "const"); }
ast::imm. { }
}
print_type(s, mt.ty);

View file

@ -2,7 +2,7 @@
// -*- rust -*-
fn len(v: [mutable? int]) -> uint {
fn len(v: [const int]) -> uint {
let i = 0u;
for x: int in v { i += 1u; }
ret i;

View file

@ -6,7 +6,7 @@ fn main() {
// This is ok because the outer vec is covariant with respect
// to the inner vec. If the outer vec was mutable then we
// couldn't do this.
fn f(&&v: [[mutable? int]]) {
fn f(&&v: [[const int]]) {
}
f(v);

View file

@ -6,7 +6,7 @@ fn main() {
// This is ok because the outer vec is covariant with respect
// to the inner vec. If the outer vec was mutable then we
// couldn't do this.
fn f(&&v: [mutable? [mutable? int]]) {
fn f(&&v: [const [const int]]) {
}
f(v);