diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/tokentrees.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/unicode_chars.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 39 |
6 files changed, 35 insertions, 49 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index f65fffebe33..fb558d1a58f 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -386,7 +386,7 @@ pub fn gather_comments_and_literals(sess: &ParseSess, path: String, srdr: &mut R debug!("tok lit: {}", s); literals.push(Literal { lit: s.to_string(), - pos: sp.lo, + pos: sp.lo(), }); }) } else { diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 527d2e41396..f26a0460905 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -71,7 +71,7 @@ pub struct StringReader<'a> { impl<'a> StringReader<'a> { fn mk_sp(&self, lo: BytePos, hi: BytePos) -> Span { - unwrap_or!(self.override_span, Span { lo: lo, hi: hi, ctxt: NO_EXPANSION}) + unwrap_or!(self.override_span, Span::new(lo, hi, NO_EXPANSION)) } fn next_token(&mut self) -> TokenAndSpan where Self: Sized { @@ -190,20 +190,20 @@ impl<'a> StringReader<'a> { } pub fn retokenize(sess: &'a ParseSess, mut span: Span) -> Self { - let begin = sess.codemap().lookup_byte_offset(span.lo); - let end = sess.codemap().lookup_byte_offset(span.hi); + let begin = sess.codemap().lookup_byte_offset(span.lo()); + let end = sess.codemap().lookup_byte_offset(span.hi()); // Make the range zero-length if the span is invalid. - if span.lo > span.hi || begin.fm.start_pos != end.fm.start_pos { - span.hi = span.lo; + if span.lo() > span.hi() || begin.fm.start_pos != end.fm.start_pos { + span = span.with_hi(span.lo()); } let mut sr = StringReader::new_raw_internal(sess, begin.fm); // Seek the lexer to the right byte range. sr.save_new_lines_and_multibyte = false; - sr.next_pos = span.lo; - sr.terminator = Some(span.hi); + sr.next_pos = span.lo(); + sr.terminator = Some(span.hi()); sr.bump(); @@ -1745,11 +1745,7 @@ mod tests { let tok1 = string_reader.next_token(); let tok2 = TokenAndSpan { tok: token::Ident(id), - sp: Span { - lo: BytePos(21), - hi: BytePos(23), - ctxt: NO_EXPANSION, - }, + sp: Span::new(BytePos(21), BytePos(23), NO_EXPANSION), }; assert_eq!(tok1, tok2); assert_eq!(string_reader.next_token().tok, token::Whitespace); @@ -1759,11 +1755,7 @@ mod tests { let tok3 = string_reader.next_token(); let tok4 = TokenAndSpan { tok: token::Ident(Ident::from_str("main")), - sp: Span { - lo: BytePos(24), - hi: BytePos(28), - ctxt: NO_EXPANSION, - }, + sp: Span::new(BytePos(24), BytePos(28), NO_EXPANSION), }; assert_eq!(tok3, tok4); // the lparen is already read: @@ -1921,7 +1913,7 @@ mod tests { let mut lexer = setup(&cm, &sh, "// test\r\n/// test\r\n".to_string()); let comment = lexer.next_token(); assert_eq!(comment.tok, token::Comment); - assert_eq!((comment.sp.lo, comment.sp.hi), (BytePos(0), BytePos(7))); + assert_eq!((comment.sp.lo(), comment.sp.hi()), (BytePos(0), BytePos(7))); assert_eq!(lexer.next_token().tok, token::Whitespace); assert_eq!(lexer.next_token().tok, token::DocComment(Symbol::intern("/// test"))); diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index ad389ab510a..a2c81e24754 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -11,7 +11,6 @@ use print::pprust::token_to_string; use parse::lexer::StringReader; use parse::{token, PResult}; -use syntax_pos::Span; use tokenstream::{Delimited, TokenStream, TokenTree}; impl<'a> StringReader<'a> { @@ -20,7 +19,7 @@ impl<'a> StringReader<'a> { let mut tts = Vec::new(); while self.token != token::Eof { let tree = self.parse_token_tree()?; - let is_joint = tree.span().hi == self.span.lo && token::is_op(&self.token); + let is_joint = tree.span().hi() == self.span.lo() && token::is_op(&self.token); tts.push(if is_joint { tree.joint() } else { tree.into() }); } Ok(TokenStream::concat(tts)) @@ -40,7 +39,7 @@ impl<'a> StringReader<'a> { return TokenStream::concat(tts); } }; - let is_joint = tree.span().hi == self.span.lo && token::is_op(&self.token); + let is_joint = tree.span().hi() == self.span.lo() && token::is_op(&self.token); tts.push(if is_joint { tree.joint() } else { tree.into() }); } } @@ -69,7 +68,7 @@ impl<'a> StringReader<'a> { let tts = self.parse_token_trees_until_close_delim(); // Expand to cover the entire delimited token tree - let span = Span { hi: self.span.hi, ..pre_span }; + let span = pre_span.with_hi(self.span.hi()); match self.token { // Correct delimiter. diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs index c36fdef2d4c..39b5482a066 100644 --- a/src/libsyntax/parse/lexer/unicode_chars.rs +++ b/src/libsyntax/parse/lexer/unicode_chars.rs @@ -340,7 +340,7 @@ pub fn check_for_substitution<'a>(reader: &StringReader<'a>, .iter() .find(|&&(c, _, _)| c == ch) .map(|&(_, u_name, ascii_char)| { - let span = Span { lo: reader.pos, hi: reader.next_pos, ctxt: NO_EXPANSION }; + let span = Span::new(reader.pos, reader.next_pos, NO_EXPANSION); match ASCII_ARRAY.iter().find(|&&(c, _)| c == ascii_char) { Some(&(ascii_char, ascii_name)) => { let msg = diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 67b4954a8f1..76a7e2923fc 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -181,7 +181,7 @@ pub fn filemap_to_parser(sess: & ParseSess, filemap: Rc<FileMap>, ) -> Parser { let mut parser = stream_to_parser(sess, filemap_to_stream(sess, filemap, None)); if parser.token == token::Eof && parser.span == syntax_pos::DUMMY_SP { - parser.span = Span { lo: end_pos, hi: end_pos, ctxt: NO_EXPANSION }; + parser.span = Span::new(end_pos, end_pos, NO_EXPANSION); } parser @@ -661,7 +661,7 @@ mod tests { // produce a syntax_pos::span fn sp(a: u32, b: u32) -> Span { - Span {lo: BytePos(a), hi: BytePos(b), ctxt: NO_EXPANSION} + Span::new(BytePos(a), BytePos(b), NO_EXPANSION) } fn str2seg(s: &str, lo: u32, hi: u32) -> ast::PathSegment { @@ -976,7 +976,7 @@ mod tests { for &src in &srcs { let spans = get_spans_of_pat_idents(src); - let Span{ lo, hi, .. } = spans[0]; + let (lo, hi) = (spans[0].lo(), spans[0].hi()); assert!("self" == &src[lo.to_usize()..hi.to_usize()], "\"{}\" != \"self\". src=\"{}\"", &src[lo.to_usize()..hi.to_usize()], src) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d2bf943ec17..5e05f36345f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -790,9 +790,8 @@ impl<'a> Parser<'a> { Ok(()) } token::AndAnd => { - let span = self.span; - let lo = span.lo + BytePos(1); - Ok(self.bump_with(token::BinOp(token::And), Span { lo: lo, ..span })) + let span = self.span.with_lo(self.span.lo() + BytePos(1)); + Ok(self.bump_with(token::BinOp(token::And), span)) } _ => self.unexpected() } @@ -824,9 +823,8 @@ impl<'a> Parser<'a> { true } token::BinOp(token::Shl) => { - let span = self.span; - let lo = span.lo + BytePos(1); - self.bump_with(token::Lt, Span { lo: lo, ..span }); + let span = self.span.with_lo(self.span.lo() + BytePos(1)); + self.bump_with(token::Lt, span); true } _ => false, @@ -852,19 +850,16 @@ impl<'a> Parser<'a> { Ok(()) } token::BinOp(token::Shr) => { - let span = self.span; - let lo = span.lo + BytePos(1); - Ok(self.bump_with(token::Gt, Span { lo: lo, ..span })) + let span = self.span.with_lo(self.span.lo() + BytePos(1)); + Ok(self.bump_with(token::Gt, span)) } token::BinOpEq(token::Shr) => { - let span = self.span; - let lo = span.lo + BytePos(1); - Ok(self.bump_with(token::Ge, Span { lo: lo, ..span })) + let span = self.span.with_lo(self.span.lo() + BytePos(1)); + Ok(self.bump_with(token::Ge, span)) } token::Ge => { - let span = self.span; - let lo = span.lo + BytePos(1); - Ok(self.bump_with(token::Eq, Span { lo: lo, ..span })) + let span = self.span.with_lo(self.span.lo() + BytePos(1)); + Ok(self.bump_with(token::Eq, span)) } _ => self.unexpected() } @@ -1094,7 +1089,7 @@ impl<'a> Parser<'a> { /// Advance the parser using provided token as a next one. Use this when /// consuming a part of a token. For example a single `<` from `<<`. pub fn bump_with(&mut self, next: token::Token, span: Span) { - self.prev_span = Span { hi: span.lo, ..self.span }; + self.prev_span = self.span.with_hi(span.lo()); // It would be incorrect to record the kind of the current token, but // fortunately for tokens currently using `bump_with`, the // prev_token_kind will be of no use anyway. @@ -1356,7 +1351,7 @@ impl<'a> Parser<'a> { if self.eat(&token::RArrow) { Ok(FunctionRetTy::Ty(self.parse_ty_no_plus()?)) } else { - Ok(FunctionRetTy::Default(Span { hi: self.span.lo, ..self.span })) + Ok(FunctionRetTy::Default(self.span.with_hi(self.span.lo()))) } } @@ -2532,7 +2527,7 @@ impl<'a> Parser<'a> { pub fn process_potential_macro_variable(&mut self) { let ident = match self.token { - token::Dollar if self.span.ctxt != syntax_pos::hygiene::SyntaxContext::empty() && + token::Dollar if self.span.ctxt() != syntax_pos::hygiene::SyntaxContext::empty() && self.look_ahead(1, |t| t.is_ident()) => { self.bump(); let name = match self.token { token::Ident(ident) => ident, _ => unreachable!() }; @@ -2734,8 +2729,8 @@ impl<'a> Parser<'a> { err.span_label(self.span, "expecting a type here because of type ascription"); let cm = self.sess.codemap(); - let cur_pos = cm.lookup_char_pos(self.span.lo); - let op_pos = cm.lookup_char_pos(cur_op_span.hi); + let cur_pos = cm.lookup_char_pos(self.span.lo()); + let op_pos = cm.lookup_char_pos(cur_op_span.hi()); if cur_pos.line != op_pos.line { err.span_suggestion_short(cur_op_span, "did you mean to use `;` here?", @@ -4056,7 +4051,7 @@ impl<'a> Parser<'a> { let mut stmt_span = stmt.span; // expand the span to include the semicolon, if it exists if self.eat(&token::Semi) { - stmt_span.hi = self.prev_span.hi; + stmt_span = stmt_span.with_hi(self.prev_span.hi()); } let sugg = pprust::to_string(|s| { use print::pprust::{PrintState, INDENT_UNIT}; @@ -4148,7 +4143,7 @@ impl<'a> Parser<'a> { stmt = stmt.add_trailing_semicolon(); } - stmt.span.hi = self.prev_span.hi; + stmt.span = stmt.span.with_hi(self.prev_span.hi()); Ok(Some(stmt)) } |
