Skip to content

Commit ba12369

Browse files
authored
Rollup merge of rust-lang#61616 - petrochenkov:parsderef, r=oli-obk
parser: Remove `Deref` impl from `Parser` Follow up to rust-lang#61541 You have to write `self.token.span` instead of `self.span` in the parser now, which is not nice, but not too bad either, I guess. Not sure. Probably still better than people using both and being confused about the definition point of `span`. r? @oli-obk @estebank
2 parents c4285b7 + 3dbee57 commit ba12369

13 files changed

+256
-266
lines changed

src/libsyntax/attr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,9 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -
735735
raw_attr.clone(),
736736
);
737737

738-
let start_span = parser.span;
738+
let start_span = parser.token.span;
739739
let (path, tokens) = panictry!(parser.parse_meta_item_unrestricted());
740-
let end_span = parser.span;
740+
let end_span = parser.token.span;
741741
if parser.token != token::Eof {
742742
parse_sess.span_diagnostic
743743
.span_err(start_span.to(end_span), "invalid crate attribute");

src/libsyntax/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a> StripUnconfigured<'a> {
121121
let mut expanded_attrs = Vec::with_capacity(1);
122122

123123
while !parser.check(&token::CloseDelim(token::Paren)) {
124-
let lo = parser.span.lo();
124+
let lo = parser.token.span.lo();
125125
let (path, tokens) = parser.parse_meta_item_unrestricted()?;
126126
expanded_attrs.push((path, tokens, parser.prev_span.with_lo(lo)));
127127
parser.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Paren)])?;

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ impl<'a> Parser<'a> {
10411041
let msg = format!("macro expansion ignores token `{}` and any following",
10421042
self.this_token_to_string());
10431043
// Avoid emitting backtrace info twice.
1044-
let def_site_span = self.span.with_ctxt(SyntaxContext::empty());
1044+
let def_site_span = self.token.span.with_ctxt(SyntaxContext::empty());
10451045
let mut err = self.diagnostic().struct_span_err(def_site_span, &msg);
10461046
err.span_label(span, "caused by the macro expansion here");
10471047
let msg = format!(

src/libsyntax/ext/source_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: &[tokenstrea
105105
while self.p.token != token::Eof {
106106
match panictry!(self.p.parse_item()) {
107107
Some(item) => ret.push(item),
108-
None => self.p.diagnostic().span_fatal(self.p.span,
108+
None => self.p.diagnostic().span_fatal(self.p.token.span,
109109
&format!("expected item, found `{}`",
110110
self.p.this_token_to_string()))
111111
.raise()

src/libsyntax/ext/tt/macro_parser.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ pub fn parse(
675675
//
676676
// This MatcherPos instance is allocated on the stack. All others -- and
677677
// there are frequently *no* others! -- are allocated on the heap.
678-
let mut initial = initial_matcher_pos(ms, parser.span);
678+
let mut initial = initial_matcher_pos(ms, parser.token.span);
679679
let mut cur_items = smallvec![MatcherPosHandle::Ref(&mut initial)];
680680
let mut next_items = Vec::new();
681681

@@ -721,15 +721,15 @@ pub fn parse(
721721
return nameize(sess, ms, matches);
722722
} else if eof_items.len() > 1 {
723723
return Error(
724-
parser.span,
724+
parser.token.span,
725725
"ambiguity: multiple successful parses".to_string(),
726726
);
727727
} else {
728728
return Failure(
729-
Token::new(token::Eof, if parser.span.is_dummy() {
730-
parser.span
729+
Token::new(token::Eof, if parser.token.span.is_dummy() {
730+
parser.token.span
731731
} else {
732-
sess.source_map().next_point(parser.span)
732+
sess.source_map().next_point(parser.token.span)
733733
}),
734734
"missing tokens in macro arguments",
735735
);
@@ -753,7 +753,7 @@ pub fn parse(
753753
.join(" or ");
754754

755755
return Error(
756-
parser.span,
756+
parser.token.span,
757757
format!(
758758
"local ambiguity: multiple parsing options: {}",
759759
match next_items.len() {
@@ -927,7 +927,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> Nonterminal {
927927
sym::ty => token::NtTy(panictry!(p.parse_ty())),
928928
// this could be handled like a token, since it is one
929929
sym::ident => if let Some((name, is_raw)) = get_macro_name(&p.token) {
930-
let span = p.span;
930+
let span = p.token.span;
931931
p.bump();
932932
token::NtIdent(Ident::new(name, span), is_raw)
933933
} else {

src/libsyntax/ext/tt/macro_rules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a> ParserAnyMacro<'a> {
4747
let fragment = panictry!(parser.parse_ast_fragment(kind, true).map_err(|mut e| {
4848
if parser.token == token::Eof && e.message().ends_with(", found `<eof>`") {
4949
if !e.span.is_dummy() { // early end of macro arm (#52866)
50-
e.replace_span_with(parser.sess.source_map().next_point(parser.span));
50+
e.replace_span_with(parser.sess.source_map().next_point(parser.token.span));
5151
}
5252
let msg = &e.message[0];
5353
e.message[0] = (
@@ -63,7 +63,7 @@ impl<'a> ParserAnyMacro<'a> {
6363
if parser.sess.source_map().span_to_filename(arm_span).is_real() {
6464
e.span_label(arm_span, "in this macro arm");
6565
}
66-
} else if !parser.sess.source_map().span_to_filename(parser.span).is_real() {
66+
} else if !parser.sess.source_map().span_to_filename(parser.token.span).is_real() {
6767
e.span_label(site_span, "in this macro invocation");
6868
}
6969
e

src/libsyntax/parse/attr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a> Parser<'a> {
3939
just_parsed_doc_comment = false;
4040
}
4141
token::DocComment(s) => {
42-
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
42+
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.token.span);
4343
if attr.style != ast::AttrStyle::Outer {
4444
let mut err = self.fatal("expected outer doc comment");
4545
err.note("inner doc comments like this (starting with \
@@ -83,7 +83,7 @@ impl<'a> Parser<'a> {
8383
self.token);
8484
let (span, path, tokens, style) = match self.token.kind {
8585
token::Pound => {
86-
let lo = self.span;
86+
let lo = self.token.span;
8787
self.bump();
8888

8989
if let InnerAttributeParsePolicy::Permitted = inner_parse_policy {
@@ -93,7 +93,7 @@ impl<'a> Parser<'a> {
9393
self.bump();
9494
if let InnerAttributeParsePolicy::NotPermitted { reason } = inner_parse_policy
9595
{
96-
let span = self.span;
96+
let span = self.token.span;
9797
self.diagnostic()
9898
.struct_span_err(span, reason)
9999
.note("inner attributes, like `#![no_std]`, annotate the item \
@@ -201,7 +201,7 @@ impl<'a> Parser<'a> {
201201
}
202202
token::DocComment(s) => {
203203
// we need to get the position of this token before we bump.
204-
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.span);
204+
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, self.token.span);
205205
if attr.style == ast::AttrStyle::Inner {
206206
attrs.push(attr);
207207
self.bump();
@@ -249,7 +249,7 @@ impl<'a> Parser<'a> {
249249
return Ok(meta);
250250
}
251251

252-
let lo = self.span;
252+
let lo = self.token.span;
253253
let path = self.parse_path(PathStyle::Mod)?;
254254
let node = self.parse_meta_item_kind()?;
255255
let span = lo.to(self.prev_span);
@@ -284,7 +284,7 @@ impl<'a> Parser<'a> {
284284

285285
let found = self.this_token_to_string();
286286
let msg = format!("expected unsuffixed literal or identifier, found `{}`", found);
287-
Err(self.diagnostic().struct_span_err(self.span, &msg))
287+
Err(self.diagnostic().struct_span_err(self.token.span, &msg))
288288
}
289289

290290
/// matches meta_seq = ( COMMASEP(meta_item_inner) )

0 commit comments

Comments
 (0)