diff options
| author | bors <bors@rust-lang.org> | 2014-10-22 07:07:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-22 07:07:09 +0000 |
| commit | 7088c45ef4078e0be54d4353b2c11146e25b2906 (patch) | |
| tree | 48268c53733ca2bfa58336f9a5cd2a4dfd0b5f47 /src/libsyntax/parse/mod.rs | |
| parent | c29a7520e7fb4a5b4d4eccfc594e05793ef6688d (diff) | |
| parent | 9c7865fa6fad826d7bf542a2cb36f63d0ae2410b (diff) | |
| download | rust-7088c45ef4078e0be54d4353b2c11146e25b2906.tar.gz rust-7088c45ef4078e0be54d4353b2c11146e25b2906.zip | |
auto merge of #18141 : phildawes/rust/master, r=brson
Hello! I noticed spans are wrong for the PatIdents of self args. (I use spans a lot in racer)
Diffstat (limited to 'src/libsyntax/parse/mod.rs')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index f1baccfcd80..2d7d32cd9ea 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -721,7 +721,7 @@ pub fn integer_lit(s: &str, sd: &SpanHandler, sp: Span) -> ast::Lit_ { mod test { use super::*; use serialize::json; - use codemap::{Span, BytePos, Spanned, NO_EXPANSION}; + use codemap::{Span, BytePos, Pos, Spanned, NO_EXPANSION}; use owned_slice::OwnedSlice; use ast; use abi; @@ -1121,6 +1121,46 @@ mod test { span: sp(0,21)}))); } + fn get_spans_of_pat_idents(src: &str) -> Vec<Span> { + let item = string_to_item(src.to_string()).unwrap(); + + struct PatIdentVisitor { + spans: Vec<Span> + } + impl<'v> ::visit::Visitor<'v> for PatIdentVisitor { + fn visit_pat(&mut self, p: &'v ast::Pat) { + match p.node { + ast::PatIdent(_ , ref spannedident, _) => { + self.spans.push(spannedident.span.clone()); + } + _ => { + ::visit::walk_pat(self, p); + } + } + } + } + let mut v = PatIdentVisitor { spans: Vec::new() }; + ::visit::walk_item(&mut v, &*item); + return v.spans; + } + + #[test] fn span_of_self_arg_pat_idents_are_correct() { + + let srcs = ["impl z { fn a (&self, &myarg: int) {} }", + "impl z { fn a (&mut self, &myarg: int) {} }", + "impl z { fn a (&'a self, &myarg: int) {} }", + "impl z { fn a (self, &myarg: int) {} }", + "impl z { fn a (self: Foo, &myarg: int) {} }", + ]; + + for &src in srcs.iter() { + let spans = get_spans_of_pat_idents(src); + let Span{lo:lo,hi:hi,..} = spans[0]; + assert!("self" == src.slice(lo.to_uint(), hi.to_uint()), + "\"{}\" != \"self\". src=\"{}\"", + src.slice(lo.to_uint(), hi.to_uint()), src) + } + } #[test] fn parse_exprs () { // just make sure that they parse.... |
