From 045a4375561f80cc30ff15780fecc39a93c44a5b Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 16 Nov 2011 13:52:08 -0800 Subject: [PATCH] rustc: Accept 'const' as synonym for 'mutable?' --- src/comp/syntax/parse/parser.rs | 9 ++++++--- src/comp/syntax/print/pprust.rs | 2 +- src/test/run-pass/maybe-mutable.rs | 2 +- src/test/run-pass/mutable-huh-variance-vec1.rs | 2 +- src/test/run-pass/mutable-huh-variance-vec2.rs | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 05f508edfd0..4e393777d2a 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -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 { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 93a4293a5d1..e2d829f5217 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -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); diff --git a/src/test/run-pass/maybe-mutable.rs b/src/test/run-pass/maybe-mutable.rs index f8436fe0717..3d57531c8c6 100644 --- a/src/test/run-pass/maybe-mutable.rs +++ b/src/test/run-pass/maybe-mutable.rs @@ -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; diff --git a/src/test/run-pass/mutable-huh-variance-vec1.rs b/src/test/run-pass/mutable-huh-variance-vec1.rs index 5fb49cf88ce..b36ec502896 100644 --- a/src/test/run-pass/mutable-huh-variance-vec1.rs +++ b/src/test/run-pass/mutable-huh-variance-vec1.rs @@ -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); diff --git a/src/test/run-pass/mutable-huh-variance-vec2.rs b/src/test/run-pass/mutable-huh-variance-vec2.rs index 1e254e86806..82b0a029ba9 100644 --- a/src/test/run-pass/mutable-huh-variance-vec2.rs +++ b/src/test/run-pass/mutable-huh-variance-vec2.rs @@ -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);