From c9b9462e8f7f0181fcc7f5883c4502e81d260b12 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 2 Jul 2013 15:46:27 +0900 Subject: [PATCH 1/5] Remove visit_struct_method --- src/librustc/middle/lint.rs | 12 ------------ src/libsyntax/visit.rs | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index ce9ab790b11b8..c39b676b97f01 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -966,10 +966,6 @@ fn lint_unused_mut() -> visit::vt<@mut Context> { visit_fn_decl(cx, &tm.decl); visit::visit_ty_method(tm, (cx, vt)); }, - visit_struct_method: |sm, (cx, vt)| { - visit_fn_decl(cx, &sm.decl); - visit::visit_struct_method(sm, (cx, vt)); - }, visit_trait_method: |tm, (cx, vt)| { match *tm { ast::required(ref tm) => visit_fn_decl(cx, &tm.decl), @@ -1049,14 +1045,6 @@ fn lint_missing_doc() -> visit::vt<@mut Context> { } visit::mk_vt(@visit::Visitor { - visit_struct_method: |m, (cx, vt)| { - if m.vis == ast::public { - check_attrs(cx, m.attrs, m.span, - "missing documentation for a method"); - } - visit::visit_struct_method(m, (cx, vt)); - }, - visit_ty_method: |m, (cx, vt)| { // All ty_method objects are linted about because they're part of a // trait (no visibility) diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 9fcffc110130e..5bde51ad70fa2 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -90,7 +90,6 @@ pub struct Visitor { visit_trait_method: @fn(&trait_method, (E, vt)), visit_struct_def: @fn(@struct_def, ident, &Generics, node_id, (E, vt)), visit_struct_field: @fn(@struct_field, (E, vt)), - visit_struct_method: @fn(@method, (E, vt)) } pub type visitor = @Visitor; @@ -116,7 +115,6 @@ pub fn default_visitor() -> visitor { visit_trait_method: |a,b|visit_trait_method::(a, b), visit_struct_def: |a,b,c,d,e|visit_struct_def::(a, b, c, d, e), visit_struct_field: |a,b|visit_struct_field::(a, b), - visit_struct_method: |a,b|visit_struct_method::(a, b) }; } @@ -414,10 +412,6 @@ pub fn visit_struct_field(sf: &struct_field, (e, v): (E, vt)) { (v.visit_ty)(sf.node.ty, (e, v)); } -pub fn visit_struct_method(m: &method, (e, v): (E, vt)) { - visit_method_helper(m, (e, v)); -} - pub fn visit_block(b: &blk, (e, v): (E, vt)) { for b.node.view_items.iter().advance |vi| { (v.visit_view_item)(*vi, (copy e, v)); @@ -729,10 +723,6 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { f(sf); visit_struct_field(sf, (e, v)); } - fn v_struct_method(f: @fn(@method), m: @method, (e, v): ((), vt<()>)) { - f(m); - visit_struct_method(m, (e, v)); - } return mk_vt(@Visitor { visit_mod: |a,b,c,d|v_mod(v.visit_mod, a, b, c, d), visit_view_item: |a,b| v_view_item(v.visit_view_item, a, b), @@ -760,7 +750,5 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { v_struct_def(v.visit_struct_def, a, b, c, d, e), visit_struct_field: |a,b| v_struct_field(v.visit_struct_field, a, b), - visit_struct_method: |a,b| - v_struct_method(v.visit_struct_method, a, b) }); } From 2e65782c1780cb9327281c7f78c8b40a5b4f5f57 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 2 Jul 2013 18:31:00 +0900 Subject: [PATCH 2/5] Do not rely on newtype enum dereference --- src/librustc/front/test.rs | 6 +++--- src/libsyntax/codemap.rs | 9 ++------- src/libsyntax/ext/base.rs | 17 +++++++---------- src/libsyntax/ext/expand.rs | 22 +++++++++++----------- src/libsyntax/ext/source_util.rs | 10 +++++----- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 91000d68aad09..bbac4a2907c0f 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -17,7 +17,7 @@ use front::config; use std::vec; use syntax::ast_util::*; use syntax::attr; -use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan}; +use syntax::codemap::{dummy_sp, span, ExpnInfo, NameAndSpan}; use syntax::codemap; use syntax::ext::base::ExtCtxt; use syntax::fold; @@ -72,13 +72,13 @@ fn generate_test_harness(sess: session::Session, }; let ext_cx = cx.ext_cx; - ext_cx.bt_push(ExpandedFrom(CallInfo { + ext_cx.bt_push(ExpnInfo { call_site: dummy_sp(), callee: NameAndSpan { name: @"test", span: None } - })); + }); let precursor = @fold::AstFoldFns { fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ), diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index bcf617c56ae1e..7e89d04078160 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -174,18 +174,13 @@ pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos} #[deriving(IterBytes)] pub struct NameAndSpan {name: @str, span: Option} +/// Extra information for tracking macro expansion of spans #[deriving(IterBytes)] -pub struct CallInfo { +pub struct ExpnInfo { call_site: span, callee: NameAndSpan } -/// Extra information for tracking macro expansion of spans -#[deriving(IterBytes)] -pub enum ExpnInfo { - ExpandedFrom(CallInfo) -} - pub type FileName = @str; pub struct FileLines diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 78fdb99753d40..ad14b567b9602 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -11,8 +11,7 @@ use ast; use ast::Name; use codemap; -use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom}; -use codemap::CallInfo; +use codemap::{CodeMap, span, ExpnInfo}; use diagnostic::span_handler; use ext; use parse; @@ -243,7 +242,7 @@ impl ExtCtxt { pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg } pub fn call_site(&self) -> span { match *self.backtrace { - Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, + Some(@ExpnInfo {call_site: cs, _}) => cs, None => self.bug("missing top span") } } @@ -254,21 +253,19 @@ impl ExtCtxt { pub fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path } pub fn bt_push(&self, ei: codemap::ExpnInfo) { match ei { - ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { + ExpnInfo {call_site: cs, callee: ref callee} => { *self.backtrace = - Some(@ExpandedFrom(CallInfo { + Some(@ExpnInfo { call_site: span {lo: cs.lo, hi: cs.hi, expn_info: *self.backtrace}, - callee: copy *callee})); + callee: copy *callee}); } } } pub fn bt_pop(&self) { match *self.backtrace { - Some(@ExpandedFrom( - CallInfo { - call_site: span {expn_info: prev, _}, _ - })) => { + Some(@ExpnInfo { + call_site: span {expn_info: prev, _}, _}) => { *self.backtrace = prev } _ => self.bug("tried to pop without a push") diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a78a18810a8d5..2b18ede88791b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -16,7 +16,7 @@ use ast; use ast_util::{new_rename, new_mark, resolve}; use attr; use codemap; -use codemap::{span, CallInfo, ExpandedFrom, NameAndSpan, spanned}; +use codemap::{span, ExpnInfo, NameAndSpan, spanned}; use ext::base::*; use fold::*; use parse; @@ -60,13 +60,13 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, expander: exp, span: exp_sp }))) => { - cx.bt_push(ExpandedFrom(CallInfo { + cx.bt_push(ExpnInfo { call_site: s, callee: NameAndSpan { name: extnamestr, span: exp_sp, }, - })); + }); let expanded = match exp(cx, mac.span, *tts) { MRExpr(e) => e, @@ -131,13 +131,13 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv, match (*extsbox).find(&intern(mname)) { Some(@SE(ItemDecorator(dec_fn))) => { - cx.bt_push(ExpandedFrom(CallInfo { + cx.bt_push(ExpnInfo { call_site: attr.span, callee: NameAndSpan { name: mname, span: None } - })); + }); let r = dec_fn(cx, attr.span, attr.node.value, items); cx.bt_pop(); r @@ -227,13 +227,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, given '%s'", extnamestr, ident_to_str(&it.ident))); } - cx.bt_push(ExpandedFrom(CallInfo { + cx.bt_push(ExpnInfo { call_site: it.span, callee: NameAndSpan { name: extnamestr, span: expand.span } - })); + }); ((*expand).expander)(cx, it.span, tts) } Some(@SE(IdentTT(ref expand))) => { @@ -242,13 +242,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, fmt!("macro %s! expects an ident argument", extnamestr)); } - cx.bt_push(ExpandedFrom(CallInfo { + cx.bt_push(ExpnInfo { call_site: it.span, callee: NameAndSpan { name: extnamestr, span: expand.span } - })); + }); ((*expand).expander)(cx, it.span, it.ident, tts) } _ => cx.span_fatal( @@ -319,10 +319,10 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, Some(@SE(NormalTT( SyntaxExpanderTT{expander: exp, span: exp_sp}))) => { - cx.bt_push(ExpandedFrom(CallInfo { + cx.bt_push(ExpnInfo { call_site: sp, callee: NameAndSpan { name: extnamestr, span: exp_sp } - })); + }); let expanded = match exp(cx, mac.span, tts) { MRExpr(e) => @codemap::spanned { node: stmt_expr(e, cx.next_id()), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index f6325c2eb2c12..b43536389e2cd 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -10,8 +10,8 @@ use ast; use codemap; -use codemap::{Pos, ExpandedFrom, span}; -use codemap::{CallInfo, NameAndSpan}; +use codemap::{Pos, span}; +use codemap::{ExpnInfo, NameAndSpan}; use ext::base::*; use ext::base; use ext::build::AstBuilder; @@ -117,14 +117,14 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) // recur along an ExpnInfo chain to find the original expression fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { match *expn_info { - ExpandedFrom(CallInfo { call_site: ref call_site, _ }) => { + ExpnInfo { call_site: ref call_site, _ } => { match call_site.expn_info { Some(next_expn_info) => { match *next_expn_info { - ExpandedFrom(CallInfo { + ExpnInfo { callee: NameAndSpan { name: ref name, _ }, _ - }) => { + } => { // Don't recurse into file using "include!" if "include" == *name { expn_info From 20458899d53074c2b503ec08a5c1ec4decb2b28f Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Thu, 4 Jul 2013 17:21:02 +0900 Subject: [PATCH 3/5] vim: Highlight 0i as number --- src/etc/vim/syntax/rust.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 25e44c62a8a75..f40bed8640dce 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -95,7 +95,7 @@ syn region rustDeriving start="deriving(" end=")" contains=rustTrait " Number literals syn match rustNumber display "\<[0-9][0-9_]*\>" syn match rustNumber display "\<[0-9][0-9_]*\(u\|u8\|u16\|u32\|u64\)\>" -syn match rustNumber display "\<[0-9][0-9_]*\(i8\|i16\|i32\|i64\)\>" +syn match rustNumber display "\<[0-9][0-9_]*\(i\|i8\|i16\|i32\|i64\)\>" syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\>" syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(u\|u8\|u16\|u32\|u64\)\>" From 30fca57f17dea0b32500937bf80ab1039c50f9f1 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Thu, 4 Jul 2013 20:48:45 +0900 Subject: [PATCH 4/5] Change spans for sugary call expressions --- src/libsyntax/parse/parser.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index cc0baa28e20d7..ae87fd8774a9a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1549,10 +1549,10 @@ impl Parser { } else if self.eat_keyword(keywords::If) { return self.parse_if_expr(); } else if self.eat_keyword(keywords::For) { - return self.parse_sugary_call_expr(~"for", ForSugar, + return self.parse_sugary_call_expr(lo, ~"for", ForSugar, expr_loop_body); } else if self.eat_keyword(keywords::Do) { - return self.parse_sugary_call_expr(~"do", DoSugar, + return self.parse_sugary_call_expr(lo, ~"do", DoSugar, expr_do_body); } else if self.eat_keyword(keywords::While) { return self.parse_while_expr(); @@ -2264,12 +2264,11 @@ impl Parser { // parse a 'for' or 'do'. // the 'for' and 'do' expressions parse as calls, but look like // function calls followed by a closure expression. - pub fn parse_sugary_call_expr(&self, + pub fn parse_sugary_call_expr(&self, lo: BytePos, keyword: ~str, sugar: CallSugar, ctor: &fn(v: @expr) -> expr_) -> @expr { - let lo = self.last_span; // Parse the callee `foo` in // for foo || { // for foo.bar || { @@ -2286,21 +2285,21 @@ impl Parser { let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); let args = vec::append(copy *args, [last_arg]); - self.mk_expr(lo.lo, block.span.hi, expr_call(f, args, sugar)) + self.mk_expr(lo, block.span.hi, expr_call(f, args, sugar)) } expr_method_call(_, f, i, ref tps, ref args, NoSugar) => { let block = self.parse_lambda_block_expr(); let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); let args = vec::append(copy *args, [last_arg]); - self.mk_expr(lo.lo, block.span.hi, + self.mk_expr(lo, block.span.hi, self.mk_method_call(f, i, copy *tps, args, sugar)) } expr_field(f, i, ref tps) => { let block = self.parse_lambda_block_expr(); let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); - self.mk_expr(lo.lo, block.span.hi, + self.mk_expr(lo, block.span.hi, self.mk_method_call(f, i, copy *tps, ~[last_arg], sugar)) } expr_path(*) | expr_call(*) | expr_method_call(*) | @@ -2309,7 +2308,7 @@ impl Parser { let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); self.mk_expr( - lo.lo, + lo, last_arg.span.hi, self.mk_call(e, ~[last_arg], sugar)) } @@ -2319,7 +2318,7 @@ impl Parser { // but they aren't represented by tests debug!("sugary call on %?", e.node); self.span_fatal( - *lo, + e.span, fmt!("`%s` must be followed by a block call", keyword)); } } From 376d5d6aae9a448a0f58a9a98e8dcec9eeeaece7 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 5 Jul 2013 14:56:54 +0900 Subject: [PATCH 5/5] Fix fallout from span change --- src/test/compile-fail/issue-3044.rs | 2 +- src/test/pretty/block-comment-wchar.pp | 1 - src/test/pretty/block-comment-wchar.rs | 2 +- src/test/pretty/for-comment.rs | 18 ++++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/test/pretty/for-comment.rs diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index f4ae436c624d9..310de3657b385 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -12,7 +12,7 @@ fn main() { let needlesArr: ~[char] = ~['a', 'f']; do needlesArr.iter().fold() |x, y| { } - //~^ ERROR 1 parameter was supplied (including the closure passed by the `do` keyword) + //~^^ ERROR 1 parameter was supplied (including the closure passed by the `do` keyword) // // the first error is, um, non-ideal. } diff --git a/src/test/pretty/block-comment-wchar.pp b/src/test/pretty/block-comment-wchar.pp index dbf28caecf290..c666950034a01 100644 --- a/src/test/pretty/block-comment-wchar.pp +++ b/src/test/pretty/block-comment-wchar.pp @@ -108,7 +108,6 @@ '\xA0', '\u1680', '\u180E', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', '\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F', '\u205F', '\u3000']; - // <= bugs in pretty-printer? for chars.iter().advance |c| { let ws = c.is_whitespace(); println(fmt!("%? %?" , c , ws)); diff --git a/src/test/pretty/block-comment-wchar.rs b/src/test/pretty/block-comment-wchar.rs index 148b50d9c9129..f0d46f39cdf9c 100644 --- a/src/test/pretty/block-comment-wchar.rs +++ b/src/test/pretty/block-comment-wchar.rs @@ -104,6 +104,6 @@ fn main() { '\u2028', '\u2029', '\u202F', '\u205F', '\u3000']; for chars.iter().advance |c| { let ws = c.is_whitespace(); - println(fmt!("%? %?", c , ws)); // <= bugs in pretty-printer? + println(fmt!("%? %?", c , ws)); } } diff --git a/src/test/pretty/for-comment.rs b/src/test/pretty/for-comment.rs new file mode 100644 index 0000000000000..15631337d2a44 --- /dev/null +++ b/src/test/pretty/for-comment.rs @@ -0,0 +1,18 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// pp-exact + +fn f(v: &[int]) { + let mut n = 0; + for v.iter().advance |e| { + n = *e; // This comment once triggered pretty printer bug + } +}