From f553701da64dd70d1fa6b757208f012dbad118d7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 27 Dec 2013 11:51:18 -0800 Subject: libsyntax: De-`@mut` `ParseSess::included_mod_stack` --- src/libsyntax/parse/parser.rs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2428710087f..ed149c1a73e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4264,21 +4264,28 @@ impl Parser { path: Path, outer_attrs: ~[ast::Attribute], id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { - let maybe_i = self.sess.included_mod_stack.iter().position(|p| *p == path); - match maybe_i { - Some(i) => { - let stack = &self.sess.included_mod_stack; - let mut err = ~"circular modules: "; - for p in stack.slice(i, stack.len()).iter() { - p.display().with_str(|s| err.push_str(s)); - err.push_str(" -> "); + { + let mut included_mod_stack = self.sess + .included_mod_stack + .borrow_mut(); + let maybe_i = included_mod_stack.get() + .iter() + .position(|p| *p == path); + match maybe_i { + Some(i) => { + let mut err = ~"circular modules: "; + let len = included_mod_stack.get().len(); + for p in included_mod_stack.get().slice(i, len).iter() { + p.display().with_str(|s| err.push_str(s)); + err.push_str(" -> "); + } + path.display().with_str(|s| err.push_str(s)); + self.span_fatal(id_sp, err); } - path.display().with_str(|s| err.push_str(s)); - self.span_fatal(id_sp, err); + None => () } - None => () + included_mod_stack.get().push(path.clone()); } - self.sess.included_mod_stack.push(path.clone()); let mut p0 = new_sub_parser_from_file(self.sess, @@ -4289,7 +4296,12 @@ impl Parser { let mod_attrs = vec::append(outer_attrs, inner); let first_item_outer_attrs = next; let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs); - self.sess.included_mod_stack.pop(); + { + let mut included_mod_stack = self.sess + .included_mod_stack + .borrow_mut(); + included_mod_stack.get().pop(); + } return (ast::item_mod(m0), mod_attrs); } -- cgit 1.4.1-3-g733a5 From 3aa19a6b86ef8317cd95fd517dcc24216d857eb1 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 27 Dec 2013 11:56:29 -0800 Subject: librustc: De-`@mut` the parse session --- src/librustc/driver/session.rs | 2 +- src/librustc/middle/astencode.rs | 6 ++--- src/libsyntax/ext/base.rs | 6 ++--- src/libsyntax/ext/expand.rs | 4 +-- src/libsyntax/ext/tt/macro_parser.rs | 17 ++++++------ src/libsyntax/parse/mod.rs | 50 ++++++++++++++++++------------------ src/libsyntax/parse/parser.rs | 6 ++--- src/libsyntax/util/parser_testing.rs | 6 ++--- 8 files changed, 48 insertions(+), 49 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 3f9274bc901..dd9c52da14f 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -204,7 +204,7 @@ pub struct Session_ { targ_cfg: @config, opts: @options, cstore: @metadata::cstore::CStore, - parse_sess: @mut ParseSess, + parse_sess: @ParseSess, codemap: @codemap::CodeMap, // For a library crate, this is always none entry_fn: RefCell>, diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index f413dfd2451..d03c73a81a0 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1429,18 +1429,18 @@ fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item { #[cfg(test)] trait fake_ext_ctxt { fn cfg(&self) -> ast::CrateConfig; - fn parse_sess(&self) -> @mut parse::ParseSess; + fn parse_sess(&self) -> @parse::ParseSess; fn call_site(&self) -> Span; fn ident_of(&self, st: &str) -> ast::Ident; } #[cfg(test)] -type fake_session = @mut parse::ParseSess; +type fake_session = @parse::ParseSess; #[cfg(test)] impl fake_ext_ctxt for fake_session { fn cfg(&self) -> ast::CrateConfig { ~[] } - fn parse_sess(&self) -> @mut parse::ParseSess { *self } + fn parse_sess(&self) -> @parse::ParseSess { *self } fn call_site(&self) -> Span { codemap::Span { lo: codemap::BytePos(0), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 03e028ea1f1..b4888f1092f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -284,7 +284,7 @@ pub fn syntax_expander_table() -> SyntaxEnv { // when a macro expansion occurs, the resulting nodes have the backtrace() // -> expn_info of their expansion context stored into their span. pub struct ExtCtxt { - parse_sess: @mut parse::ParseSess, + parse_sess: @parse::ParseSess, cfg: ast::CrateConfig, backtrace: Option<@ExpnInfo>, @@ -293,7 +293,7 @@ pub struct ExtCtxt { } impl ExtCtxt { - pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::CrateConfig) + pub fn new(parse_sess: @parse::ParseSess, cfg: ast::CrateConfig) -> ExtCtxt { ExtCtxt { parse_sess: parse_sess, @@ -320,7 +320,7 @@ impl ExtCtxt { } pub fn codemap(&self) -> @CodeMap { self.parse_sess.cm } - pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } + pub fn parse_sess(&self) -> @parse::ParseSess { self.parse_sess } pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() } pub fn call_site(&self) -> Span { match self.backtrace { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 1d9620d405f..b8e39f80d47 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -889,7 +889,7 @@ impl ast_fold for Injector { // add a bunch of macros as though they were placed at the head of the // program (ick). This should run before cfg stripping. -pub fn inject_std_macros(parse_sess: @mut parse::ParseSess, +pub fn inject_std_macros(parse_sess: @parse::ParseSess, cfg: ast::CrateConfig, c: Crate) -> Crate { @@ -939,7 +939,7 @@ impl<'a> ast_fold for MacroExpander<'a> { } } -pub fn expand_crate(parse_sess: @mut parse::ParseSess, +pub fn expand_crate(parse_sess: @parse::ParseSess, cfg: ast::CrateConfig, c: Crate) -> Crate { let mut cx = ExtCtxt::new(parse_sess, cfg.clone()); diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 4d2923f391e..004fd3e325b 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -188,9 +188,9 @@ pub enum named_match { pub type earley_item = ~MatcherPos; -pub fn nameize(p_s: @mut ParseSess, ms: &[matcher], res: &[@named_match]) +pub fn nameize(p_s: @ParseSess, ms: &[matcher], res: &[@named_match]) -> HashMap { - fn n_rec(p_s: @mut ParseSess, m: &matcher, res: &[@named_match], + fn n_rec(p_s: @ParseSess, m: &matcher, res: &[@named_match], ret_val: &mut HashMap) { match *m { codemap::Spanned {node: match_tok(_), .. } => (), @@ -222,7 +222,7 @@ pub enum parse_result { } pub fn parse_or_else( - sess: @mut ParseSess, + sess: @ParseSess, cfg: ast::CrateConfig, rdr: @mut reader, ms: ~[matcher] @@ -243,12 +243,11 @@ pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool { } } -pub fn parse( - sess: @mut ParseSess, - cfg: ast::CrateConfig, - rdr: @mut reader, - ms: &[matcher] -) -> parse_result { +pub fn parse(sess: @ParseSess, + cfg: ast::CrateConfig, + rdr: @mut reader, + ms: &[matcher]) + -> parse_result { let mut cur_eis = ~[]; cur_eis.push(initial_matcher_pos(ms.to_owned(), None, rdr.peek().sp.lo)); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index b6139f0ae99..a20265e6d36 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -47,9 +47,9 @@ pub struct ParseSess { included_mod_stack: RefCell<~[Path]>, } -pub fn new_parse_sess(demitter: Option<@Emitter>) -> @mut ParseSess { +pub fn new_parse_sess(demitter: Option<@Emitter>) -> @ParseSess { let cm = @CodeMap::new(); - @mut ParseSess { + @ParseSess { cm: cm, span_diagnostic: mk_span_handler(mk_handler(demitter), cm), included_mod_stack: RefCell::new(~[]), @@ -58,8 +58,8 @@ pub fn new_parse_sess(demitter: Option<@Emitter>) -> @mut ParseSess { pub fn new_parse_sess_special_handler(sh: @mut SpanHandler, cm: @codemap::CodeMap) - -> @mut ParseSess { - @mut ParseSess { + -> @ParseSess { + @ParseSess { cm: cm, span_diagnostic: sh, included_mod_stack: RefCell::new(~[]), @@ -74,7 +74,7 @@ pub fn new_parse_sess_special_handler(sh: @mut SpanHandler, pub fn parse_crate_from_file( input: &Path, cfg: ast::CrateConfig, - sess: @mut ParseSess + sess: @ParseSess ) -> ast::Crate { new_parser_from_file(sess, /*bad*/ cfg.clone(), input).parse_crate_mod() // why is there no p.abort_if_errors here? @@ -83,7 +83,7 @@ pub fn parse_crate_from_file( pub fn parse_crate_attrs_from_file( input: &Path, cfg: ast::CrateConfig, - sess: @mut ParseSess + sess: @ParseSess ) -> ~[ast::Attribute] { let mut parser = new_parser_from_file(sess, cfg, input); let (inner, _) = parser.parse_inner_attrs_and_next(); @@ -94,7 +94,7 @@ pub fn parse_crate_from_source_str( name: @str, source: @str, cfg: ast::CrateConfig, - sess: @mut ParseSess + sess: @ParseSess ) -> ast::Crate { let mut p = new_parser_from_source_str(sess, /*bad*/ cfg.clone(), @@ -107,7 +107,7 @@ pub fn parse_crate_attrs_from_source_str( name: @str, source: @str, cfg: ast::CrateConfig, - sess: @mut ParseSess + sess: @ParseSess ) -> ~[ast::Attribute] { let mut p = new_parser_from_source_str(sess, /*bad*/ cfg.clone(), @@ -121,7 +121,7 @@ pub fn parse_expr_from_source_str( name: @str, source: @str, cfg: ast::CrateConfig, - sess: @mut ParseSess + sess: @ParseSess ) -> @ast::Expr { let mut p = new_parser_from_source_str(sess, cfg, name, source); maybe_aborted(p.parse_expr(), p) @@ -132,7 +132,7 @@ pub fn parse_item_from_source_str( source: @str, cfg: ast::CrateConfig, attrs: ~[ast::Attribute], - sess: @mut ParseSess + sess: @ParseSess ) -> Option<@ast::item> { let mut p = new_parser_from_source_str(sess, cfg, name, source); maybe_aborted(p.parse_item(attrs),p) @@ -142,7 +142,7 @@ pub fn parse_meta_from_source_str( name: @str, source: @str, cfg: ast::CrateConfig, - sess: @mut ParseSess + sess: @ParseSess ) -> @ast::MetaItem { let mut p = new_parser_from_source_str(sess, cfg, name, source); maybe_aborted(p.parse_meta_item(),p) @@ -153,7 +153,7 @@ pub fn parse_stmt_from_source_str( source: @str, cfg: ast::CrateConfig, attrs: ~[ast::Attribute], - sess: @mut ParseSess + sess: @ParseSess ) -> @ast::Stmt { let mut p = new_parser_from_source_str( sess, @@ -168,7 +168,7 @@ pub fn parse_tts_from_source_str( name: @str, source: @str, cfg: ast::CrateConfig, - sess: @mut ParseSess + sess: @ParseSess ) -> ~[ast::token_tree] { let mut p = new_parser_from_source_str( sess, @@ -192,7 +192,7 @@ pub fn parse_from_source_str( ss: codemap::FileSubstr, source: @str, cfg: ast::CrateConfig, - sess: @mut ParseSess) + sess: @ParseSess) -> T { let mut p = new_parser_from_source_substr(sess, cfg, name, ss, source); let r = f(&mut p); @@ -203,7 +203,7 @@ pub fn parse_from_source_str( } // Create a new parser from a source string -pub fn new_parser_from_source_str(sess: @mut ParseSess, +pub fn new_parser_from_source_str(sess: @ParseSess, cfg: ast::CrateConfig, name: @str, source: @str) @@ -213,7 +213,7 @@ pub fn new_parser_from_source_str(sess: @mut ParseSess, // Create a new parser from a source string where the origin // is specified as a substring of another file. -pub fn new_parser_from_source_substr(sess: @mut ParseSess, +pub fn new_parser_from_source_substr(sess: @ParseSess, cfg: ast::CrateConfig, name: @str, ss: codemap::FileSubstr, @@ -225,7 +225,7 @@ pub fn new_parser_from_source_substr(sess: @mut ParseSess, /// Create a new parser, handling errors as appropriate /// if the file doesn't exist pub fn new_parser_from_file( - sess: @mut ParseSess, + sess: @ParseSess, cfg: ast::CrateConfig, path: &Path ) -> Parser { @@ -236,7 +236,7 @@ pub fn new_parser_from_file( /// the file at the given path to the codemap, and return a parser. /// On an error, use the given span as the source of the problem. pub fn new_sub_parser_from_file( - sess: @mut ParseSess, + sess: @ParseSess, cfg: ast::CrateConfig, path: &Path, sp: Span @@ -245,7 +245,7 @@ pub fn new_sub_parser_from_file( } /// Given a filemap and config, return a parser -pub fn filemap_to_parser(sess: @mut ParseSess, +pub fn filemap_to_parser(sess: @ParseSess, filemap: @FileMap, cfg: ast::CrateConfig) -> Parser { tts_to_parser(sess,filemap_to_tts(sess,filemap),cfg) @@ -253,7 +253,7 @@ pub fn filemap_to_parser(sess: @mut ParseSess, // must preserve old name for now, because quote! from the *existing* // compiler expands into it -pub fn new_parser_from_tts(sess: @mut ParseSess, +pub fn new_parser_from_tts(sess: @ParseSess, cfg: ast::CrateConfig, tts: ~[ast::token_tree]) -> Parser { tts_to_parser(sess,tts,cfg) @@ -264,7 +264,7 @@ pub fn new_parser_from_tts(sess: @mut ParseSess, /// Given a session and a path and an optional span (for error reporting), /// add the path to the session's codemap and return the new filemap. -pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option) +pub fn file_to_filemap(sess: @ParseSess, path: &Path, spanopt: Option) -> @FileMap { let err = |msg: &str| { match spanopt { @@ -293,20 +293,20 @@ pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option) // given a session and a string, add the string to // the session's codemap and return the new filemap -pub fn string_to_filemap(sess: @mut ParseSess, source: @str, path: @str) +pub fn string_to_filemap(sess: @ParseSess, source: @str, path: @str) -> @FileMap { sess.cm.new_filemap(path, source) } // given a session and a string and a path and a FileSubStr, add // the string to the CodeMap and return the new FileMap -pub fn substring_to_filemap(sess: @mut ParseSess, source: @str, path: @str, +pub fn substring_to_filemap(sess: @ParseSess, source: @str, path: @str, filesubstr: FileSubstr) -> @FileMap { sess.cm.new_filemap_w_substr(path,filesubstr,source) } // given a filemap, produce a sequence of token-trees -pub fn filemap_to_tts(sess: @mut ParseSess, filemap: @FileMap) +pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap) -> ~[ast::token_tree] { // it appears to me that the cfg doesn't matter here... indeed, // parsing tt's probably shouldn't require a parser at all. @@ -317,7 +317,7 @@ pub fn filemap_to_tts(sess: @mut ParseSess, filemap: @FileMap) } // given tts and cfg, produce a parser -pub fn tts_to_parser(sess: @mut ParseSess, +pub fn tts_to_parser(sess: @ParseSess, tts: ~[ast::token_tree], cfg: ast::CrateConfig) -> Parser { let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ed149c1a73e..0d7e31e1861 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -286,8 +286,8 @@ struct ParsedItemsAndViewItems { /* ident is handled by common.rs */ -pub fn Parser(sess: @mut ParseSess, cfg: ast::CrateConfig, rdr: @mut reader) - -> Parser { +pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: @mut reader) + -> Parser { let tok0 = rdr.next_token(); let interner = get_ident_interner(); let span = tok0.sp; @@ -324,7 +324,7 @@ pub fn Parser(sess: @mut ParseSess, cfg: ast::CrateConfig, rdr: @mut reader) } pub struct Parser { - sess: @mut ParseSess, + sess: @ParseSess, cfg: CrateConfig, // the current token: token: token::Token, diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index 01e050c1ffe..dc546c7610f 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -17,7 +17,7 @@ use parse::token; // map a string to tts, using a made-up filename: return both the token_trees // and the ParseSess -pub fn string_to_tts_and_sess (source_str : @str) -> (~[ast::token_tree],@mut ParseSess) { +pub fn string_to_tts_and_sess (source_str : @str) -> (~[ast::token_tree],@ParseSess) { let ps = new_parse_sess(None); (filemap_to_tts(ps,string_to_filemap(ps,source_str,@"bogofile")),ps) } @@ -28,7 +28,7 @@ pub fn string_to_tts(source_str : @str) -> ~[ast::token_tree] { tts } -pub fn string_to_parser_and_sess(source_str: @str) -> (Parser,@mut ParseSess) { +pub fn string_to_parser_and_sess(source_str: @str) -> (Parser,@ParseSess) { let ps = new_parse_sess(None); (new_parser_from_source_str(ps,~[],@"bogofile",source_str),ps) } @@ -54,7 +54,7 @@ pub fn string_to_crate (source_str : @str) -> ast::Crate { } // parse a string, return a crate and the ParseSess -pub fn string_to_crate_and_sess (source_str : @str) -> (ast::Crate,@mut ParseSess) { +pub fn string_to_crate_and_sess (source_str : @str) -> (ast::Crate,@ParseSess) { let (mut p,ps) = string_to_parser_and_sess(source_str); (p.parse_crate_mod(),ps) } -- cgit 1.4.1-3-g733a5 From 7e1b535eb1aa7614e40538ca5892a71199f804b9 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 27 Dec 2013 13:40:07 -0800 Subject: libsyntax: De-`@mut` `StringReader`, `TtReader`, and `reader` --- src/libsyntax/ext/trace_macros.rs | 2 +- src/libsyntax/ext/tt/macro_parser.rs | 13 +++--- src/libsyntax/ext/tt/macro_rules.rs | 13 ++---- src/libsyntax/ext/tt/transcribe.rs | 19 ++++---- src/libsyntax/parse/comments.rs | 22 ++++----- src/libsyntax/parse/lexer.rs | 87 ++++++++++++++++++------------------ src/libsyntax/parse/mod.rs | 4 +- src/libsyntax/parse/parser.rs | 4 +- 8 files changed, 77 insertions(+), 87 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index 34151377d7b..a7d1d8fb366 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -25,7 +25,7 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt, let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic, None, tt.to_owned()); - let rdr = tt_rdr as @mut reader; + let rdr = tt_rdr as @reader; let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); if rust_parser.is_keyword(keywords::True) { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 004fd3e325b..8b22e32262b 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -221,12 +221,11 @@ pub enum parse_result { error(codemap::Span, ~str) } -pub fn parse_or_else( - sess: @ParseSess, - cfg: ast::CrateConfig, - rdr: @mut reader, - ms: ~[matcher] -) -> HashMap { +pub fn parse_or_else(sess: @ParseSess, + cfg: ast::CrateConfig, + rdr: @reader, + ms: ~[matcher]) + -> HashMap { match parse(sess, cfg, rdr, ms) { success(m) => m, failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), @@ -245,7 +244,7 @@ pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool { pub fn parse(sess: @ParseSess, cfg: ast::CrateConfig, - rdr: @mut reader, + rdr: @reader, ms: &[matcher]) -> parse_result { let mut cur_eis = ~[]; diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index c9827fb54bd..32d9ed1238b 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -130,11 +130,7 @@ fn generic_extension(cx: &ExtCtxt, match *lhs { @matched_nonterminal(nt_matchers(ref mtcs)) => { // `none` is because we're not interpolating - let arg_rdr = new_tt_reader( - s_d, - None, - arg.to_owned() - ) as @mut reader; + let arg_rdr = new_tt_reader(s_d, None, arg.to_owned()) as @reader; match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) { success(named_matches) => { let rhs = match rhses[i] { @@ -154,10 +150,7 @@ fn generic_extension(cx: &ExtCtxt, // rhs has holes ( `$id` and `$(...)` that need filled) let trncbr = new_tt_reader(s_d, Some(named_matches), rhs); - let p = Parser(cx.parse_sess(), - cx.cfg(), - trncbr as @mut reader); - + let p = Parser(cx.parse_sess(), cx.cfg(), trncbr as @reader); // Let the context choose how to interpret the result. // Weird, but useful for X-macros. return MRAny(@ParserAnyMacro { @@ -218,7 +211,7 @@ pub fn add_new_extension(cx: &mut ExtCtxt, arg.clone()); let argument_map = parse_or_else(cx.parse_sess(), cx.cfg(), - arg_reader as @mut reader, + arg_reader as @reader, argument_gram); // Extract the arguments: diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 02094ff3d6a..f4c7132a1f6 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -49,8 +49,8 @@ pub struct TtReader { pub fn new_tt_reader(sp_diag: @mut SpanHandler, interp: Option>, src: ~[ast::token_tree]) - -> @mut TtReader { - let r = @mut TtReader { + -> @TtReader { + let r = @TtReader { sp_diag: sp_diag, stack: RefCell::new(@mut TtFrame { forest: @src, @@ -86,8 +86,8 @@ fn dup_tt_frame(f: @mut TtFrame) -> @mut TtFrame { } } -pub fn dup_tt_reader(r: @mut TtReader) -> @mut TtReader { - @mut TtReader { +pub fn dup_tt_reader(r: @TtReader) -> @TtReader { + @TtReader { sp_diag: r.sp_diag, stack: RefCell::new(dup_tt_frame(r.stack.get())), repeat_idx: r.repeat_idx.clone(), @@ -99,9 +99,8 @@ pub fn dup_tt_reader(r: @mut TtReader) -> @mut TtReader { } -fn lookup_cur_matched_by_matched(r: &mut TtReader, - start: @named_match) - -> @named_match { +fn lookup_cur_matched_by_matched(r: &TtReader, start: @named_match) + -> @named_match { fn red(ad: @named_match, idx: &uint) -> @named_match { match *ad { matched_nonterminal(_) => { @@ -115,7 +114,7 @@ fn lookup_cur_matched_by_matched(r: &mut TtReader, repeat_idx.get().iter().fold(start, red) } -fn lookup_cur_matched(r: &mut TtReader, name: Ident) -> @named_match { +fn lookup_cur_matched(r: &TtReader, name: Ident) -> @named_match { let matched_opt = { let interpolations = r.interpolations.borrow(); interpolations.get().find_copy(&name) @@ -137,7 +136,7 @@ enum lis { lis_contradiction(~str), } -fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis { +fn lockstep_iter_size(t: &token_tree, r: &TtReader) -> lis { fn lis_merge(lhs: lis, rhs: lis) -> lis { match lhs { lis_unconstrained => rhs.clone(), @@ -173,7 +172,7 @@ fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis { // return the next token from the TtReader. // EFFECT: advances the reader's token field -pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { +pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { // XXX(pcwalton): Bad copy? let ret_val = TokenAndSpan { tok: r.cur_tok.get(), diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index b8fd39cb910..248f5fe3ffb 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -135,7 +135,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { fail!("not a doc-comment: {}", comment); } -fn read_to_eol(rdr: @mut StringReader) -> ~str { +fn read_to_eol(rdr: @StringReader) -> ~str { let mut val = ~""; while rdr.curr.get() != '\n' && !is_eof(rdr) { val.push_char(rdr.curr.get()); @@ -145,21 +145,21 @@ fn read_to_eol(rdr: @mut StringReader) -> ~str { return val; } -fn read_one_line_comment(rdr: @mut StringReader) -> ~str { +fn read_one_line_comment(rdr: @StringReader) -> ~str { let val = read_to_eol(rdr); assert!((val[0] == '/' as u8 && val[1] == '/' as u8) || (val[0] == '#' as u8 && val[1] == '!' as u8)); return val; } -fn consume_non_eol_whitespace(rdr: @mut StringReader) { +fn consume_non_eol_whitespace(rdr: @StringReader) { while is_whitespace(rdr.curr.get()) && rdr.curr.get() != '\n' && !is_eof(rdr) { bump(rdr); } } -fn push_blank_line_comment(rdr: @mut StringReader, comments: &mut ~[cmnt]) { +fn push_blank_line_comment(rdr: @StringReader, comments: &mut ~[cmnt]) { debug!(">>> blank-line comment"); let v: ~[~str] = ~[]; comments.push(cmnt { @@ -169,7 +169,7 @@ fn push_blank_line_comment(rdr: @mut StringReader, comments: &mut ~[cmnt]) { }); } -fn consume_whitespace_counting_blank_lines(rdr: @mut StringReader, +fn consume_whitespace_counting_blank_lines(rdr: @StringReader, comments: &mut ~[cmnt]) { while is_whitespace(rdr.curr.get()) && !is_eof(rdr) { if rdr.col.get() == CharPos(0u) && rdr.curr.get() == '\n' { @@ -180,7 +180,7 @@ fn consume_whitespace_counting_blank_lines(rdr: @mut StringReader, } -fn read_shebang_comment(rdr: @mut StringReader, code_to_the_left: bool, +fn read_shebang_comment(rdr: @StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { debug!(">>> shebang comment"); let p = rdr.last_pos.get(); @@ -192,7 +192,7 @@ fn read_shebang_comment(rdr: @mut StringReader, code_to_the_left: bool, }); } -fn read_line_comments(rdr: @mut StringReader, code_to_the_left: bool, +fn read_line_comments(rdr: @StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { debug!(">>> line comments"); let p = rdr.last_pos.get(); @@ -249,7 +249,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str], lines.push(s1); } -fn read_block_comment(rdr: @mut StringReader, +fn read_block_comment(rdr: @StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { debug!(">>> block comment"); @@ -280,7 +280,7 @@ fn read_block_comment(rdr: @mut StringReader, while level > 0 { debug!("=== block comment level {}", level); if is_eof(rdr) { - (rdr as @mut reader).fatal(~"unterminated block comment"); + (rdr as @reader).fatal(~"unterminated block comment"); } if rdr.curr.get() == '\n' { trim_whitespace_prefix_and_push_line(&mut lines, curr_line, @@ -318,13 +318,13 @@ fn read_block_comment(rdr: @mut StringReader, comments.push(cmnt {style: style, lines: lines, pos: p}); } -fn peeking_at_comment(rdr: @mut StringReader) -> bool { +fn peeking_at_comment(rdr: @StringReader) -> bool { return ((rdr.curr.get() == '/' && nextch(rdr) == '/') || (rdr.curr.get() == '/' && nextch(rdr) == '*')) || (rdr.curr.get() == '#' && nextch(rdr) == '!'); } -fn consume_comment(rdr: @mut StringReader, +fn consume_comment(rdr: @StringReader, code_to_the_left: bool, comments: &mut ~[cmnt]) { debug!(">>> consume comment"); diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 3fcc0414e61..e3b2c5406ba 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -26,12 +26,12 @@ use std::util; pub use ext::tt::transcribe::{TtReader, new_tt_reader}; pub trait reader { - fn is_eof(@mut self) -> bool; - fn next_token(@mut self) -> TokenAndSpan; - fn fatal(@mut self, ~str) -> !; - fn span_diag(@mut self) -> @mut SpanHandler; - fn peek(@mut self) -> TokenAndSpan; - fn dup(@mut self) -> @mut reader; + fn is_eof(@self) -> bool; + fn next_token(@self) -> TokenAndSpan; + fn fatal(@self, ~str) -> !; + fn span_diag(@self) -> @mut SpanHandler; + fn peek(@self) -> TokenAndSpan; + fn dup(@self) -> @reader; } #[deriving(Clone, Eq)] @@ -59,7 +59,7 @@ pub struct StringReader { pub fn new_string_reader(span_diagnostic: @mut SpanHandler, filemap: @codemap::FileMap) - -> @mut StringReader { + -> @StringReader { let r = new_low_level_string_reader(span_diagnostic, filemap); string_advance_token(r); /* fill in peek_* */ return r; @@ -68,10 +68,10 @@ pub fn new_string_reader(span_diagnostic: @mut SpanHandler, /* For comments.rs, which hackily pokes into 'pos' and 'curr' */ pub fn new_low_level_string_reader(span_diagnostic: @mut SpanHandler, filemap: @codemap::FileMap) - -> @mut StringReader { + -> @StringReader { // Force the initial reader bump to start on a fresh line let initial_char = '\n'; - let r = @mut StringReader { + let r = @StringReader { span_diagnostic: span_diagnostic, src: filemap.src, pos: Cell::new(filemap.start_pos), @@ -90,8 +90,8 @@ pub fn new_low_level_string_reader(span_diagnostic: @mut SpanHandler, // duplicating the string reader is probably a bad idea, in // that using them will cause interleaved pushes of line // offsets to the underlying filemap... -fn dup_string_reader(r: @mut StringReader) -> @mut StringReader { - @mut StringReader { +fn dup_string_reader(r: @StringReader) -> @StringReader { + @StringReader { span_diagnostic: r.span_diagnostic, src: r.src, pos: Cell::new(r.pos.get()), @@ -105,9 +105,9 @@ fn dup_string_reader(r: @mut StringReader) -> @mut StringReader { } impl reader for StringReader { - fn is_eof(@mut self) -> bool { is_eof(self) } + fn is_eof(@self) -> bool { is_eof(self) } // return the next token. EFFECT: advances the string_reader. - fn next_token(@mut self) -> TokenAndSpan { + fn next_token(@self) -> TokenAndSpan { let ret_val = { let mut peek_tok = self.peek_tok.borrow_mut(); TokenAndSpan { @@ -118,45 +118,45 @@ impl reader for StringReader { string_advance_token(self); ret_val } - fn fatal(@mut self, m: ~str) -> ! { + fn fatal(@self, m: ~str) -> ! { self.span_diagnostic.span_fatal(self.peek_span.get(), m) } - fn span_diag(@mut self) -> @mut SpanHandler { self.span_diagnostic } - fn peek(@mut self) -> TokenAndSpan { + fn span_diag(@self) -> @mut SpanHandler { self.span_diagnostic } + fn peek(@self) -> TokenAndSpan { // XXX(pcwalton): Bad copy! TokenAndSpan { tok: self.peek_tok.get(), sp: self.peek_span.get(), } } - fn dup(@mut self) -> @mut reader { dup_string_reader(self) as @mut reader } + fn dup(@self) -> @reader { dup_string_reader(self) as @reader } } impl reader for TtReader { - fn is_eof(@mut self) -> bool { + fn is_eof(@self) -> bool { let cur_tok = self.cur_tok.borrow(); *cur_tok.get() == token::EOF } - fn next_token(@mut self) -> TokenAndSpan { + fn next_token(@self) -> TokenAndSpan { let r = tt_next_token(self); debug!("TtReader: r={:?}", r); return r; } - fn fatal(@mut self, m: ~str) -> ! { + fn fatal(@self, m: ~str) -> ! { self.sp_diag.span_fatal(self.cur_span.get(), m); } - fn span_diag(@mut self) -> @mut SpanHandler { self.sp_diag } - fn peek(@mut self) -> TokenAndSpan { + fn span_diag(@self) -> @mut SpanHandler { self.sp_diag } + fn peek(@self) -> TokenAndSpan { TokenAndSpan { tok: self.cur_tok.get(), sp: self.cur_span.get(), } } - fn dup(@mut self) -> @mut reader { dup_tt_reader(self) as @mut reader } + fn dup(@self) -> @reader { dup_tt_reader(self) as @reader } } // report a lexical error spanning [`from_pos`, `to_pos`) -fn fatal_span(rdr: @mut StringReader, +fn fatal_span(rdr: @StringReader, from_pos: BytePos, to_pos: BytePos, m: ~str) @@ -167,7 +167,7 @@ fn fatal_span(rdr: @mut StringReader, // report a lexical error spanning [`from_pos`, `to_pos`), appending an // escaped character to the error message -fn fatal_span_char(rdr: @mut StringReader, +fn fatal_span_char(rdr: @StringReader, from_pos: BytePos, to_pos: BytePos, m: ~str, @@ -181,7 +181,7 @@ fn fatal_span_char(rdr: @mut StringReader, // report a lexical error spanning [`from_pos`, `to_pos`), appending the // offending string to the error message -fn fatal_span_verbose(rdr: @mut StringReader, +fn fatal_span_verbose(rdr: @StringReader, from_pos: BytePos, to_pos: BytePos, m: ~str) @@ -197,7 +197,7 @@ fn fatal_span_verbose(rdr: @mut StringReader, // EFFECT: advance peek_tok and peek_span to refer to the next token. // EFFECT: update the interner, maybe. -fn string_advance_token(r: @mut StringReader) { +fn string_advance_token(r: @StringReader) { match (consume_whitespace_and_comments(r)) { Some(comment) => { r.peek_span.set(comment.sp); @@ -224,7 +224,7 @@ fn byte_offset(rdr: &StringReader, pos: BytePos) -> BytePos { /// up to but excluding `rdr.last_pos`, meaning the slice does not include /// the character `rdr.curr`. pub fn with_str_from( - rdr: @mut StringReader, + rdr: @StringReader, start: BytePos, f: |s: &str| -> T) -> T { @@ -234,7 +234,7 @@ pub fn with_str_from( /// Calls `f` with astring slice of the source text spanning from `start` /// up to but excluding `end`. fn with_str_from_to( - rdr: @mut StringReader, + rdr: @StringReader, start: BytePos, end: BytePos, f: |s: &str| -> T) @@ -246,7 +246,7 @@ fn with_str_from_to( // EFFECT: advance the StringReader by one character. If a newline is // discovered, add it to the FileMap's list of line start offsets. -pub fn bump(rdr: &mut StringReader) { +pub fn bump(rdr: &StringReader) { rdr.last_pos.set(rdr.pos.get()); let current_byte_offset = byte_offset(rdr, rdr.pos.get()).to_uint(); if current_byte_offset < (rdr.src).len() { @@ -272,10 +272,10 @@ pub fn bump(rdr: &mut StringReader) { rdr.curr.set(unsafe { transmute(-1u32) }); // FIXME: #8971: unsound } } -pub fn is_eof(rdr: @mut StringReader) -> bool { +pub fn is_eof(rdr: @StringReader) -> bool { rdr.curr.get() == unsafe { transmute(-1u32) } // FIXME: #8971: unsound } -pub fn nextch(rdr: @mut StringReader) -> char { +pub fn nextch(rdr: @StringReader) -> char { let offset = byte_offset(rdr, rdr.pos.get()).to_uint(); if offset < (rdr.src).len() { return rdr.src.char_at(offset); @@ -306,7 +306,7 @@ fn is_hex_digit(c: char) -> bool { // EFFECT: eats whitespace and comments. // returns a Some(sugared-doc-attr) if one exists, None otherwise. -fn consume_whitespace_and_comments(rdr: @mut StringReader) +fn consume_whitespace_and_comments(rdr: @StringReader) -> Option { while is_whitespace(rdr.curr.get()) { bump(rdr); } return consume_any_line_comment(rdr); @@ -319,7 +319,7 @@ pub fn is_line_non_doc_comment(s: &str) -> bool { // PRECONDITION: rdr.curr is not whitespace // EFFECT: eats any kind of comment. // returns a Some(sugared-doc-attr) if one exists, None otherwise -fn consume_any_line_comment(rdr: @mut StringReader) +fn consume_any_line_comment(rdr: @StringReader) -> Option { if rdr.curr.get() == '/' { match nextch(rdr) { @@ -377,8 +377,7 @@ pub fn is_block_non_doc_comment(s: &str) -> bool { } // might return a sugared-doc-attr -fn consume_block_comment(rdr: @mut StringReader) - -> Option { +fn consume_block_comment(rdr: @StringReader) -> Option { // block comments starting with "/**" or "/*!" are doc-comments let is_doc_comment = rdr.curr.get() == '*' || rdr.curr.get() == '!'; let start_bpos = rdr.pos.get() - BytePos(if is_doc_comment {3} else {2}); @@ -425,7 +424,7 @@ fn consume_block_comment(rdr: @mut StringReader) if res.is_some() { res } else { consume_whitespace_and_comments(rdr) } } -fn scan_exponent(rdr: @mut StringReader, start_bpos: BytePos) -> Option<~str> { +fn scan_exponent(rdr: @StringReader, start_bpos: BytePos) -> Option<~str> { let mut c = rdr.curr.get(); let mut rslt = ~""; if c == 'e' || c == 'E' { @@ -446,7 +445,7 @@ fn scan_exponent(rdr: @mut StringReader, start_bpos: BytePos) -> Option<~str> { } else { return None::<~str>; } } -fn scan_digits(rdr: @mut StringReader, radix: uint) -> ~str { +fn scan_digits(rdr: @StringReader, radix: uint) -> ~str { let mut rslt = ~""; loop { let c = rdr.curr.get(); @@ -461,7 +460,7 @@ fn scan_digits(rdr: @mut StringReader, radix: uint) -> ~str { }; } -fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { +fn scan_number(c: char, rdr: @StringReader) -> token::Token { let mut num_str; let mut base = 10u; let mut c = c; @@ -597,7 +596,7 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { } } -fn scan_numeric_escape(rdr: @mut StringReader, n_hex_digits: uint) -> char { +fn scan_numeric_escape(rdr: @StringReader, n_hex_digits: uint) -> char { let mut accum_int = 0; let mut i = n_hex_digits; let start_bpos = rdr.last_pos.get(); @@ -638,7 +637,7 @@ fn ident_continue(c: char) -> bool { // return the next token from the string // EFFECT: advances the input past that token // EFFECT: updates the interner -fn next_token_inner(rdr: @mut StringReader) -> token::Token { +fn next_token_inner(rdr: @StringReader) -> token::Token { let c = rdr.curr.get(); if ident_start(c) && nextch(rdr) != '"' && nextch(rdr) != '#' { // Note: r as in r" or r#" is part of a raw string literal, @@ -663,7 +662,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token { if is_dec_digit(c) { return scan_number(c, rdr); } - fn binop(rdr: @mut StringReader, op: token::binop) -> token::Token { + fn binop(rdr: @StringReader, op: token::binop) -> token::Token { bump(rdr); if rdr.curr.get() == '=' { bump(rdr); @@ -951,7 +950,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token { } } -fn consume_whitespace(rdr: @mut StringReader) { +fn consume_whitespace(rdr: @StringReader) { while is_whitespace(rdr.curr.get()) && !is_eof(rdr) { bump(rdr); } } @@ -966,7 +965,7 @@ mod test { // represents a testing reader (incl. both reader and interner) struct Env { - string_reader: @mut StringReader + string_reader: @StringReader } // open a string reader for the given string diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a20265e6d36..21fdf1d2327 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -312,7 +312,7 @@ pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap) // parsing tt's probably shouldn't require a parser at all. let cfg = ~[]; let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap); - let mut p1 = Parser(sess, cfg, srdr as @mut reader); + let mut p1 = Parser(sess, cfg, srdr as @reader); p1.parse_all_token_trees() } @@ -321,7 +321,7 @@ pub fn tts_to_parser(sess: @ParseSess, tts: ~[ast::token_tree], cfg: ast::CrateConfig) -> Parser { let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts); - Parser(sess, cfg, trdr as @mut reader) + Parser(sess, cfg, trdr as @reader) } // abort if necessary diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 0d7e31e1861..20f202826ec 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -286,7 +286,7 @@ struct ParsedItemsAndViewItems { /* ident is handled by common.rs */ -pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: @mut reader) +pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: @reader) -> Parser { let tok0 = rdr.next_token(); let interner = get_ident_interner(); @@ -340,7 +340,7 @@ pub struct Parser { tokens_consumed: uint, restriction: restriction, quote_depth: uint, // not (yet) related to the quasiquoter - reader: @mut reader, + reader: @reader, interner: @token::ident_interner, /// The set of seen errors about obsolete syntax. Used to suppress /// extra detail when the same error is seen twice -- cgit 1.4.1-3-g733a5 From 4269f85d5bc67390af75c28311b17c0032a55c5e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 27 Dec 2013 16:11:33 -0800 Subject: libsyntax: De-`@mut` `name_idx` --- src/libsyntax/parse/parser.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 20f202826ec..ca856a53116 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -81,6 +81,7 @@ use parse::{new_sub_parser_from_file, ParseSess}; use opt_vec; use opt_vec::OptVec; +use std::cell::Cell; use std::hashmap::HashSet; use std::util; use std::vec; @@ -2185,7 +2186,7 @@ impl Parser { // unification of matchers and token_trees would vastly improve // the interpolation of matchers maybe_whole!(self, nt_matchers); - let name_idx = @mut 0u; + let name_idx = @Cell::new(0u); match self.token { token::LBRACE | token::LPAREN | token::LBRACKET => { let other_delimiter = token::flip_delimiter(&self.token); @@ -2200,7 +2201,7 @@ impl Parser { // Otherwise, `$( ( )` would be a valid matcher, and `$( () )` would be // invalid. It's similar to common::parse_seq. pub fn parse_matcher_subseq_upto(&mut self, - name_idx: @mut uint, + name_idx: @Cell, ket: &token::Token) -> ~[matcher] { let mut ret_val = ~[]; @@ -2217,13 +2218,13 @@ impl Parser { return ret_val; } - pub fn parse_matcher(&mut self, name_idx: @mut uint) -> matcher { + pub fn parse_matcher(&mut self, name_idx: @Cell) -> matcher { let lo = self.span.lo; let m = if self.token == token::DOLLAR { self.bump(); if self.token == token::LPAREN { - let name_idx_lo = *name_idx; + let name_idx_lo = name_idx.get(); self.bump(); let ms = self.parse_matcher_subseq_upto(name_idx, &token::RPAREN); @@ -2231,13 +2232,13 @@ impl Parser { self.fatal("repetition body must be nonempty"); } let (sep, zerok) = self.parse_sep_and_zerok(); - match_seq(ms, sep, zerok, name_idx_lo, *name_idx) + match_seq(ms, sep, zerok, name_idx_lo, name_idx.get()) } else { let bound_to = self.parse_ident(); self.expect(&token::COLON); let nt_name = self.parse_ident(); - let m = match_nonterminal(bound_to, nt_name, *name_idx); - *name_idx += 1u; + let m = match_nonterminal(bound_to, nt_name, name_idx.get()); + name_idx.set(name_idx.get() + 1u); m } } else { -- cgit 1.4.1-3-g733a5 From 82a09b9a04cb72088e2ec0bd66810445efba5c2e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 31 Dec 2013 12:55:39 -0800 Subject: librustc: Remove `@mut` support from the parser --- src/librustc/front/feature_gate.rs | 5 ++--- src/librustc/middle/check_const.rs | 5 ++--- src/librustc/middle/const_eval.rs | 1 - src/librustc/middle/kind.rs | 2 +- src/librustc/middle/lint.rs | 2 +- src/librustc/middle/trans/consts.rs | 4 +--- src/librustc/middle/trans/expr.rs | 8 +++----- src/librustc/middle/ty.rs | 1 - src/librustc/middle/typeck/astconv.rs | 4 ++-- src/librustc/middle/typeck/check/mod.rs | 29 +++++++++++------------------ src/librustdoc/clean.rs | 4 ++-- src/librustdoc/html/format.rs | 8 +------- src/libsyntax/ast.rs | 5 ++--- src/libsyntax/ast_util.rs | 12 ++++++------ src/libsyntax/ext/build.rs | 11 ++++++----- src/libsyntax/ext/deriving/ty.rs | 8 ++++---- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/parser.rs | 12 ++++-------- src/libsyntax/print/pprust.rs | 6 +----- src/libsyntax/visit.rs | 4 ++-- 20 files changed, 52 insertions(+), 81 deletions(-) (limited to 'src/libsyntax/parse/parser.rs') diff --git a/src/librustc/front/feature_gate.rs b/src/librustc/front/feature_gate.rs index 6bbf18de693..fa0be72b830 100644 --- a/src/librustc/front/feature_gate.rs +++ b/src/librustc/front/feature_gate.rs @@ -189,9 +189,8 @@ impl Visitor<()> for Context { fn visit_expr(&mut self, e: @ast::Expr, _: ()) { match e.node { - ast::ExprUnary(_, ast::UnBox(..), _) | - ast::ExprVstore(_, ast::ExprVstoreBox) | - ast::ExprVstore(_, ast::ExprVstoreMutBox) => { + ast::ExprUnary(_, ast::UnBox, _) | + ast::ExprVstore(_, ast::ExprVstoreBox) => { self.gate_box(e.span); } _ => {} diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index a6a51e95083..c56a268c48f 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -116,7 +116,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor, if is_const { match e.node { ExprUnary(_, UnDeref, _) => { } - ExprUnary(_, UnBox(_), _) | ExprUnary(_, UnUniq, _) => { + ExprUnary(_, UnBox, _) | ExprUnary(_, UnUniq, _) => { sess.span_err(e.span, "cannot do allocations in constant expressions"); return; @@ -197,8 +197,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor, immutable values"); }, ExprVstore(_, ExprVstoreUniq) | - ExprVstore(_, ExprVstoreBox) | - ExprVstore(_, ExprVstoreMutBox) => { + ExprVstore(_, ExprVstoreBox) => { sess.span_err(e.span, "cannot allocate vectors in constant expressions") }, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index e7dddd18aee..20db51861d6 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -239,7 +239,6 @@ impl ConstEvalVisitor { ast::ExprVstoreSlice => self.classify(e), ast::ExprVstoreUniq | ast::ExprVstoreBox | - ast::ExprVstoreMutBox | ast::ExprVstoreMutSlice => non_const } } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 70abd94ea31..49e57306c12 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -306,7 +306,7 @@ pub fn check_expr(cx: &mut Context, e: @Expr) { } match e.node { - ExprUnary(_, UnBox(_), interior) => { + ExprUnary(_, UnBox, interior) => { let interior_type = ty::expr_ty(cx.tcx, interior); let _ = check_durable(cx.tcx, interior_type, interior.span); } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 7503419f8b6..07893280624 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -1068,7 +1068,7 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) { } } ast::ExprUnary(_, ast::UnUniq, _) | - ast::ExprUnary(_, ast::UnBox(..), _) => BoxAllocation, + ast::ExprUnary(_, ast::UnBox, _) => BoxAllocation, _ => return }; diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 0dd8b841bcf..9c3a7f4f671 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -377,9 +377,7 @@ fn const_expr_unadjusted(cx: @CrateContext, let ty = ty::expr_ty(cx.tcx, e); let is_float = ty::type_is_fp(ty); return (match u { - ast::UnBox(_) | - ast::UnUniq | - ast::UnDeref => { + ast::UnBox | ast::UnUniq | ast::UnDeref => { let (dv, _dt) = const_deref(cx, te, ty, true); dv } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 6cece563a82..640f9339a7d 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -590,8 +590,7 @@ fn trans_rvalue_datum_unadjusted(bcx: @Block, expr: &ast::Expr) -> DatumBlock { ast::ExprPath(_) | ast::ExprSelf => { return trans_def_datum_unadjusted(bcx, expr, bcx.def(expr.id)); } - ast::ExprVstore(contents, ast::ExprVstoreBox) | - ast::ExprVstore(contents, ast::ExprVstoreMutBox) => { + ast::ExprVstore(contents, ast::ExprVstoreBox) => { return tvec::trans_uniq_or_managed_vstore(bcx, heap_managed, expr, contents); } @@ -1406,9 +1405,8 @@ fn trans_unary_datum(bcx: @Block, }; immediate_rvalue_bcx(bcx, llneg, un_ty) } - ast::UnBox(_) => { - trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, - heap_managed) + ast::UnBox => { + trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap_managed) } ast::UnUniq => { let heap = heap_for_unique(bcx, un_ty); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 79eb26091dc..3ae29eade77 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3257,7 +3257,6 @@ pub fn expr_kind(tcx: ctxt, ast::ExprAddrOf(..) | ast::ExprBinary(..) | ast::ExprVstore(_, ast::ExprVstoreBox) | - ast::ExprVstore(_, ast::ExprVstoreMutBox) | ast::ExprVstore(_, ast::ExprVstoreUniq) => { RvalueDatumExpr } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 24c4b3399bc..746389c6044 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -401,8 +401,8 @@ pub fn ast_ty_to_ty( let typ = match ast_ty.node { ast::ty_nil => ty::mk_nil(), ast::ty_bot => ty::mk_bot(), - ast::ty_box(ref mt) => { - let mt = ast::mt { ty: mt.ty, mutbl: ast::MutImmutable }; + ast::ty_box(ty) => { + let mt = ast::mt { ty: ty, mutbl: ast::MutImmutable }; mk_pointer(this, rscope, &mt, ty::vstore_box, |tmt| ty::mk_box(tcx, tmt.ty)) } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index dde55f320bc..088104e84ef 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2628,15 +2628,12 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, } ast::ExprVec(ref args, mutbl) => { let tt = ast_expr_vstore_to_vstore(fcx, ev, vst); - let mutability; let mut any_error = false; let mut any_bot = false; - match vst { - ast::ExprVstoreMutBox | ast::ExprVstoreMutSlice => { - mutability = ast::MutMutable - } - _ => mutability = mutbl - } + let mutability = match vst { + ast::ExprVstoreMutSlice => ast::MutMutable, + _ => mutbl, + }; let t: ty::t = fcx.infcx().next_ty_var(); for e in args.iter() { check_expr_has_type(fcx, *e, t); @@ -2650,11 +2647,9 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, } if any_error { ty::mk_err() - } - else if any_bot { + } else if any_bot { ty::mk_bot() - } - else { + } else { ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutability}, tt) } } @@ -2663,10 +2658,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, let _ = ty::eval_repeat_count(fcx, count_expr); let tt = ast_expr_vstore_to_vstore(fcx, ev, vst); let mutability = match vst { - ast::ExprVstoreMutBox | ast::ExprVstoreMutSlice => { - ast::MutMutable - } - _ => mutbl + ast::ExprVstoreMutSlice => ast::MutMutable, + _ => mutbl, }; let t: ty::t = fcx.infcx().next_ty_var(); check_expr_has_type(fcx, element, t); @@ -2741,7 +2734,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, ast::ExprUnary(callee_id, unop, oprnd) => { let exp_inner = unpack_expected(fcx, expected, |sty| { match unop { - ast::UnBox(_) | ast::UnUniq => match *sty { + ast::UnBox | ast::UnUniq => match *sty { ty::ty_box(ty) => Some(ty), ty::ty_uniq(ref mt) => Some(mt.ty), _ => None @@ -2755,7 +2748,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, if !ty::type_is_error(oprnd_t) && !ty::type_is_bot(oprnd_t) { match unop { - ast::UnBox(_) => { + ast::UnBox => { oprnd_t = ty::mk_box(tcx, oprnd_t) } ast::UnUniq => { @@ -3920,7 +3913,7 @@ pub fn ast_expr_vstore_to_vstore(fcx: @FnCtxt, -> ty::vstore { match v { ast::ExprVstoreUniq => ty::vstore_uniq, - ast::ExprVstoreBox | ast::ExprVstoreMutBox => ty::vstore_box, + ast::ExprVstoreBox => ty::vstore_box, ast::ExprVstoreSlice | ast::ExprVstoreMutSlice => { let r = fcx.infcx().next_region_var(infer::AddrOfSlice(e.span)); ty::vstore_slice(r) diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 4bcf1985ef2..52dbba13ea8 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -594,7 +594,7 @@ pub enum Type { /// aka ty_bot Bottom, Unique(~Type), - Managed(Mutability, ~Type), + Managed(~Type), RawPointer(Mutability, ~Type), BorrowedRef { lifetime: Option, mutability: Mutability, type_: ~Type}, // region, raw, other boxes, mutable @@ -620,7 +620,7 @@ impl Clean for ast::Ty { ty_rptr(ref l, ref m) => BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(), type_: ~m.ty.clean()}, - ty_box(ref m) => Managed(m.mutbl.clean(), ~m.ty.clean()), + ty_box(ty) => Managed(~ty.clean()), ty_uniq(ty) => Unique(~ty.clean()), ty_vec(ty) => Vector(~ty.clean()), ty_fixed_length_vec(ty, ref e) => FixedVector(~ty.clean(), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 04da17d4ec4..b32ca037261 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -340,13 +340,7 @@ impl fmt::Default for clean::Type { clean::Unit => f.buf.write("()".as_bytes()), clean::Bottom => f.buf.write("!".as_bytes()), clean::Unique(ref t) => write!(f.buf, "~{}", **t), - clean::Managed(m, ref t) => { - write!(f.buf, "@{}{}", - match m { - clean::Mutable => "mut ", - clean::Immutable => "", - }, **t) - } + clean::Managed(ref t) => write!(f.buf, "@{}", **t), clean::RawPointer(m, ref t) => { write!(f.buf, "*{}{}", match m { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 4d744f4df29..3523d63ef60 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -415,7 +415,6 @@ pub enum Vstore { pub enum ExprVstore { ExprVstoreUniq, // ~[1,2,3,4] ExprVstoreBox, // @[1,2,3,4] - ExprVstoreMutBox, // @mut [1,2,3,4] ExprVstoreSlice, // &[1,2,3,4] ExprVstoreMutSlice, // &mut [1,2,3,4] } @@ -444,7 +443,7 @@ pub enum BinOp { #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum UnOp { - UnBox(Mutability), + UnBox, UnUniq, UnDeref, UnNot, @@ -875,7 +874,7 @@ pub struct TyBareFn { pub enum ty_ { ty_nil, ty_bot, /* bottom type */ - ty_box(mt), + ty_box(P), ty_uniq(P), ty_vec(P), ty_fixed_length_vec(P, @Expr), diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 70e4922aabf..f99fed517b1 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -137,13 +137,13 @@ pub fn is_shift_binop(b: BinOp) -> bool { } } -pub fn unop_to_str(op: UnOp) -> ~str { +pub fn unop_to_str(op: UnOp) -> &'static str { match op { - UnBox(mt) => if mt == MutMutable { ~"@mut " } else { ~"@" }, - UnUniq => ~"~", - UnDeref => ~"*", - UnNot => ~"!", - UnNeg => ~"-" + UnBox => "@", + UnUniq => "~", + UnDeref => "*", + UnNot => "!", + UnNeg => "-", } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1a3513ab81c..481472e8f0b 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -54,7 +54,7 @@ pub trait AstBuilder { lifetime: Option, mutbl: ast::Mutability) -> P; fn ty_uniq(&self, span: Span, ty: P) -> P; - fn ty_box(&self, span: Span, ty: P, mutbl: ast::Mutability) -> P; + fn ty_box(&self, span: Span, ty: P) -> P; fn ty_option(&self, ty: P) -> P; fn ty_infer(&self, sp: Span) -> P; @@ -311,12 +311,13 @@ impl AstBuilder for ExtCtxt { self.ty(span, ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl))) } + fn ty_uniq(&self, span: Span, ty: P) -> P { self.ty(span, ast::ty_uniq(ty)) } - fn ty_box(&self, span: Span, - ty: P, mutbl: ast::Mutability) -> P { - self.ty(span, ast::ty_box(self.ty_mt(ty, mutbl))) + + fn ty_box(&self, span: Span, ty: P) -> P { + self.ty(span, ast::ty_box(ty)) } fn ty_option(&self, ty: P) -> P { @@ -494,7 +495,7 @@ impl AstBuilder for ExtCtxt { } fn expr_managed(&self, sp: Span, e: @ast::Expr) -> @ast::Expr { - self.expr_unary(sp, ast::UnBox(ast::MutImmutable), e) + self.expr_unary(sp, ast::UnBox, e) } fn expr_field_access(&self, sp: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr { diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 10e07520a84..89bed626c1e 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -24,7 +24,7 @@ use opt_vec::OptVec; /// The types of pointers pub enum PtrTy<'a> { Send, // ~ - Managed(ast::Mutability), // @[mut] + Managed, // @ Borrowed(Option<&'a str>, ast::Mutability), // &['lifetime] [mut] } @@ -138,8 +138,8 @@ impl<'a> Ty<'a> { Send => { cx.ty_uniq(span, raw_ty) } - Managed(mutbl) => { - cx.ty_box(span, raw_ty, mutbl) + Managed => { + cx.ty_box(span, raw_ty) } Borrowed(ref lt, mutbl) => { let lt = mk_lifetime(cx, span, lt); @@ -251,7 +251,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option) span, match *ptr { Send => ast::sty_uniq(ast::MutImmutable), - Managed(mutbl) => ast::sty_box(mutbl), + Managed => ast::sty_box(ast::MutImmutable), Borrowed(ref lt, mutbl) => { let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s))); ast::sty_region(lt, mutbl) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 4a2adc04fbd..dea30d181da 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -238,7 +238,7 @@ pub trait ast_fold { fn fold_ty(&mut 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_box(ty) => ty_box(self.fold_ty(ty)), 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)), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ca856a53116..40a2ef86e4f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -29,8 +29,7 @@ use ast::{ExprField, ExprFnBlock, ExprIf, ExprIndex}; use ast::{ExprLit, ExprLogLevel, ExprLoop, ExprMac}; use ast::{ExprMethodCall, ExprParen, ExprPath, ExprProc, ExprRepeat}; use ast::{ExprRet, ExprSelf, ExprStruct, ExprTup, ExprUnary}; -use ast::{ExprVec, ExprVstore, ExprVstoreMutBox}; -use ast::{ExprVstoreSlice, ExprVstoreBox}; +use ast::{ExprVec, ExprVstore, ExprVstoreSlice, ExprVstoreBox}; use ast::{ExprVstoreMutSlice, ExprWhile, ExprForLoop, extern_fn, Field, fn_decl}; use ast::{ExprVstoreUniq, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod}; @@ -1300,7 +1299,7 @@ impl Parser { if sigil == OwnedSigil { ty_uniq(self.parse_ty(false)) } else { - ty_box(self.parse_mt()) + ty_box(self.parse_ty(false)) } } @@ -2300,17 +2299,14 @@ impl Parser { } token::AT => { self.bump(); - let m = self.parse_mutability(); let e = self.parse_prefix_expr(); hi = e.span.hi; // HACK: turn @[...] into a @-evec ex = match e.node { - ExprVec(..) | ExprRepeat(..) if m == MutMutable => - ExprVstore(e, ExprVstoreMutBox), ExprVec(..) | ExprLit(@codemap::Spanned { node: lit_str(..), span: _}) | - ExprRepeat(..) if m == MutImmutable => ExprVstore(e, ExprVstoreBox), - _ => self.mk_unary(UnBox(m), e) + ExprRepeat(..) => ExprVstore(e, ExprVstoreBox), + _ => self.mk_unary(UnBox, e) }; } token::TILDE => { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0d68f117460..15dfacc41f1 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -422,7 +422,7 @@ pub fn print_type(s: &mut ps, ty: &ast::Ty) { match ty.node { ast::ty_nil => word(&mut s.s, "()"), ast::ty_bot => word(&mut s.s, "!"), - ast::ty_box(ref mt) => { word(&mut s.s, "@"); print_mt(s, mt); } + ast::ty_box(ty) => { word(&mut s.s, "@"); print_type(s, ty); } ast::ty_uniq(ty) => { word(&mut s.s, "~"); print_type(s, ty); } ast::ty_vec(ty) => { word(&mut s.s, "["); @@ -1083,10 +1083,6 @@ pub fn print_expr_vstore(s: &mut ps, t: ast::ExprVstore) { match t { ast::ExprVstoreUniq => word(&mut s.s, "~"), ast::ExprVstoreBox => word(&mut s.s, "@"), - ast::ExprVstoreMutBox => { - word(&mut s.s, "@"); - word(&mut s.s, "mut"); - } ast::ExprVstoreSlice => word(&mut s.s, "&"), ast::ExprVstoreMutSlice => { word(&mut s.s, "&"); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 2e83a038c58..29567ab9442 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -302,10 +302,10 @@ pub fn skip_ty>(_: &mut V, _: &Ty, _: E) { pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { match typ.node { - ty_uniq(ty) | ty_vec(ty) => { + ty_uniq(ty) | ty_vec(ty) | ty_box(ty) => { visitor.visit_ty(ty, env) } - ty_box(ref mutable_type) | ty_ptr(ref mutable_type) => { + ty_ptr(ref mutable_type) => { visitor.visit_ty(mutable_type.ty, env) } ty_rptr(ref lifetime, ref mutable_type) => { -- cgit 1.4.1-3-g733a5