Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop using BytePos for computing spans in librustc_parse/parser/mod.rs #68845

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, FatalError
use rustc_session::parse::ParseSess;
use rustc_span::source_map::respan;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
use rustc_span::{FileName, Span, DUMMY_SP};
use syntax::ast::{self, AttrStyle, AttrVec, CrateSugar, Extern, Ident, Unsafety, DUMMY_NODE_ID};
use syntax::ast::{IsAsync, MacArgs, MacDelimiter, Mutability, StrLit, Visibility, VisibilityKind};
use syntax::ptr::P;
Expand Down Expand Up @@ -615,8 +615,8 @@ impl<'a> Parser<'a> {
true
}
token::BinOpEq(token::Plus) => {
let span = self.token.span.with_lo(self.token.span.lo() + BytePos(1));
self.bump_with(token::Eq, span);
let start_point = self.sess.source_map().start_point(self.token.span);
self.bump_with(token::Eq, self.token.span.with_lo(start_point.hi()));
true
}
_ => false,
Expand All @@ -633,8 +633,9 @@ impl<'a> Parser<'a> {
Ok(())
}
token::AndAnd => {
let span = self.token.span.with_lo(self.token.span.lo() + BytePos(1));
Ok(self.bump_with(token::BinOp(token::And), span))
let start_point = self.sess.source_map().start_point(self.token.span);
Ok(self
.bump_with(token::BinOp(token::And), self.token.span.with_lo(start_point.hi())))
}
_ => self.unexpected(),
}
Expand All @@ -650,8 +651,9 @@ impl<'a> Parser<'a> {
Ok(())
}
token::OrOr => {
let span = self.token.span.with_lo(self.token.span.lo() + BytePos(1));
Ok(self.bump_with(token::BinOp(token::Or), span))
let start_point = self.sess.source_map().start_point(self.token.span);
Ok(self
.bump_with(token::BinOp(token::Or), self.token.span.with_lo(start_point.hi())))
}
_ => self.unexpected(),
}
Expand All @@ -671,13 +673,16 @@ impl<'a> Parser<'a> {
true
}
token::BinOp(token::Shl) => {
let span = self.sess.source_map().next_point(self.token.span);
self.bump_with(token::Lt, span);
let start_point = self.sess.source_map().start_point(self.token.span);
self.bump_with(token::Lt, self.token.span.with_lo(start_point.hi()));
true
}
token::LArrow => {
let span = self.sess.source_map().next_point(self.token.span);
self.bump_with(token::BinOp(token::Minus), span);
let start_point = self.sess.source_map().start_point(self.token.span);
self.bump_with(
token::BinOp(token::Minus),
self.token.span.with_lo(start_point.hi()),
);
true
}
_ => false,
Expand Down Expand Up @@ -707,16 +712,16 @@ impl<'a> Parser<'a> {
Some(())
}
token::BinOp(token::Shr) => {
let span = self.token.span.with_lo(self.token.span.lo() + BytePos(1));
Some(self.bump_with(token::Gt, span))
let start_point = self.sess.source_map().start_point(self.token.span);
Some(self.bump_with(token::Gt, self.token.span.with_lo(start_point.hi())))
}
token::BinOpEq(token::Shr) => {
let span = self.token.span.with_lo(self.token.span.lo() + BytePos(1));
Some(self.bump_with(token::Ge, span))
let start_point = self.sess.source_map().start_point(self.token.span);
Some(self.bump_with(token::Ge, self.token.span.with_lo(start_point.hi())))
}
token::Ge => {
let span = self.token.span.with_lo(self.token.span.lo() + BytePos(1));
Some(self.bump_with(token::Eq, span))
let start_point = self.sess.source_map().start_point(self.token.span);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is such a common thing then we might want to have a new method in SourceMap for it.

Some(self.bump_with(token::Eq, self.token.span.with_lo(start_point.hi())))
}
_ => None,
};
Expand Down
Binary file modified src/test/ui/parser/issue-68730.stderr
Binary file not shown.