-use ast::NodeId;
-use early_buffered_lints::BufferedEarlyLintId;
-use ext::tt::macro_parser;
-use feature_gate::Features;
-use parse::{token, ParseSess};
-use print::pprust;
-use symbol::keywords;
+use crate::ast::NodeId;
+use crate::early_buffered_lints::BufferedEarlyLintId;
+use crate::ext::tt::macro_parser;
+use crate::feature_gate::Features;
+use crate::parse::{token, ParseSess};
+use crate::print::pprust;
+use crate::tokenstream::{self, DelimSpan};
+use crate::ast;
+use crate::symbol::keywords;
+
use syntax_pos::{edition::Edition, BytePos, Span};
-use tokenstream::{self, DelimSpan};
-use ast;
use rustc_data_structures::sync::Lrc;
use std::iter::Peekable;
}
impl Delimited {
- /// Return the opening delimiter (possibly `NoDelim`).
+ /// Returns the opening delimiter (possibly `NoDelim`).
pub fn open_token(&self) -> token::Token {
token::OpenDelim(self.delim)
}
- /// Return the closing delimiter (possibly `NoDelim`).
+ /// Returns the closing delimiter (possibly `NoDelim`).
pub fn close_token(&self) -> token::Token {
token::CloseDelim(self.delim)
}
- /// Return a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
+ /// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
pub fn open_tt(&self, span: Span) -> TokenTree {
let open_span = if span.is_dummy() {
span
TokenTree::Token(open_span, self.open_token())
}
- /// Return a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
+ /// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
pub fn close_tt(&self, span: Span) -> TokenTree {
let close_span = if span.is_dummy() {
span
}
}
- /// Returns true if the given token tree contains no other tokens. This is vacuously true for
+ /// Returns `true` if the given token tree contains no other tokens. This is vacuously true for
/// single tokens or metavar/decls, but may be false for delimited trees or sequences.
pub fn is_empty(&self) -> bool {
match *self {
}
}
- /// Get the `index`-th sub-token-tree. This only makes sense for delimited trees and sequences.
+ /// Gets the `index`-th sub-token-tree. This only makes sense for delimited trees and sequences.
pub fn get_tt(&self, index: usize) -> TokenTree {
match (self, index) {
(&TokenTree::Delimited(_, ref delimed), _) if delimed.delim == token::NoDelim => {
}
}
- /// Retrieve the `TokenTree`'s span.
+ /// Retrieves the `TokenTree`'s span.
pub fn span(&self) -> Span {
match *self {
TokenTree::Token(sp, _)
/// operator and separator, then a tuple with `(separator, KleeneOp)` is returned. Otherwise, an
/// error with the appropriate span is emitted to `sess` and a dummy value is returned.
///
-/// NOTE: In 2015 edition, * and + are the only Kleene operators and `?` is a separator. In 2018,
-/// `?` is a Kleene op and not a separator.
+/// N.B., in the 2015 edition, `*` and `+` are the only Kleene operators, and `?` is a separator.
+/// In the 2018 edition however, `?` is a Kleene operator, and not a separator.
fn parse_sep_and_kleene_op<I>(
input: &mut Peekable<I>,
span: Span,
// #1 is a separator and #2 should be a KleepeOp.
// (N.B. We need to advance the input iterator.)
match parse_kleene_op(input, span) {
- // #2 is `?`, which is not allowed as a Kleene op in 2015 edition.
+ // #2 is `?`, which is not allowed as a Kleene op in 2015 edition,
+ // but is allowed in the 2018 edition.
Ok(Ok((op, op2_span))) if op == KleeneOp::ZeroOrOne => {
sess.span_diagnostic
.struct_span_err(op2_span, "expected `*` or `+`")
- .note("`?` is not a macro repetition operator")
+ .note("`?` is not a macro repetition operator in the 2015 edition, \
+ but is accepted in the 2018 edition")
.emit();
// Return a dummy
Err(_) => op1_span,
}
} else {
- // `?` is not allowed as a Kleene op in 2015
+ // `?` is not allowed as a Kleene op in 2015,
+ // but is allowed in the 2018 edition
sess.span_diagnostic
.struct_span_err(op1_span, "expected `*` or `+`")
- .note("`?` is not a macro repetition operator")
+ .note("`?` is not a macro repetition operator in the 2015 edition, \
+ but is accepted in the 2018 edition")
.emit();
// Return a dummy
// #1 is a separator followed by #2, a KleeneOp
Ok(Err((tok, span))) => match parse_kleene_op(input, span) {
- // #2 is a `?`, which is not allowed as a Kleene op in 2015 edition.
+ // #2 is a `?`, which is not allowed as a Kleene op in 2015 edition,
+ // but is allowed in the 2018 edition
Ok(Ok((op, op2_span))) if op == KleeneOp::ZeroOrOne => {
sess.span_diagnostic
.struct_span_err(op2_span, "expected `*` or `+`")
- .note("`?` is not a macro repetition operator")
+ .note("`?` is not a macro repetition operator in the 2015 edition, \
+ but is accepted in the 2018 edition")
.emit();
// Return a dummy