syntax: reduce visibilities
This commit is contained in:
parent
98017ca53a
commit
c189565edc
14 changed files with 101 additions and 101 deletions
|
@ -280,7 +280,7 @@ impl Attribute {
|
|||
self.item.meta(self.span)
|
||||
}
|
||||
|
||||
pub fn parse<'a, T, F>(&self, sess: &'a ParseSess, mut f: F) -> PResult<'a, T>
|
||||
crate fn parse<'a, T, F>(&self, sess: &'a ParseSess, mut f: F) -> PResult<'a, T>
|
||||
where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
|
||||
{
|
||||
let mut parser = Parser::new(
|
||||
|
@ -298,14 +298,14 @@ impl Attribute {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn parse_derive_paths<'a>(&self, sess: &'a ParseSess) -> PResult<'a, Vec<Path>> {
|
||||
crate fn parse_derive_paths<'a>(&self, sess: &'a ParseSess) -> PResult<'a, Vec<Path>> {
|
||||
if self.tokens.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
self.parse(sess, |p| p.parse_derive_paths())
|
||||
}
|
||||
|
||||
pub fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> {
|
||||
crate fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> {
|
||||
Ok(MetaItem {
|
||||
path: self.path.clone(),
|
||||
kind: self.parse(sess, |parser| parser.parse_meta_item_kind())?,
|
||||
|
|
|
@ -838,7 +838,7 @@ impl<'a> Parser<'a> {
|
|||
self.this_token_to_string());
|
||||
// Avoid emitting backtrace info twice.
|
||||
let def_site_span = self.token.span.with_ctxt(SyntaxContext::root());
|
||||
let mut err = self.diagnostic().struct_span_err(def_site_span, &msg);
|
||||
let mut err = self.struct_span_err(def_site_span, &msg);
|
||||
err.span_label(span, "caused by the macro expansion here");
|
||||
let msg = format!(
|
||||
"the usage of `{}!` is likely invalid in {} context",
|
||||
|
|
|
@ -212,7 +212,7 @@ impl Lit {
|
|||
/// Attempts to recover an AST literal from semantic literal.
|
||||
/// This function is used when the original token doesn't exist (e.g. the literal is created
|
||||
/// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
|
||||
pub fn from_lit_kind(kind: LitKind, span: Span) -> Lit {
|
||||
crate fn from_lit_kind(kind: LitKind, span: Span) -> Lit {
|
||||
Lit { token: kind.to_lit_token(), kind, span }
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,10 @@ mod attr;
|
|||
mod expr;
|
||||
mod pat;
|
||||
mod item;
|
||||
pub use item::AliasKind;
|
||||
mod module;
|
||||
pub use module::{ModulePath, ModulePathSuccess};
|
||||
mod ty;
|
||||
mod path;
|
||||
pub use path::PathStyle;
|
||||
crate use path::PathStyle;
|
||||
mod stmt;
|
||||
mod generics;
|
||||
mod diagnostics;
|
||||
|
@ -46,14 +44,14 @@ bitflags::bitflags! {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
crate enum SemiColonMode {
|
||||
enum SemiColonMode {
|
||||
Break,
|
||||
Ignore,
|
||||
Comma,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
crate enum BlockMode {
|
||||
enum BlockMode {
|
||||
Break,
|
||||
Ignore,
|
||||
}
|
||||
|
@ -126,33 +124,33 @@ pub struct Parser<'a> {
|
|||
prev_token_kind: PrevTokenKind,
|
||||
restrictions: Restrictions,
|
||||
/// Used to determine the path to externally loaded source files.
|
||||
crate directory: Directory<'a>,
|
||||
pub(super) directory: Directory<'a>,
|
||||
/// `true` to parse sub-modules in other files.
|
||||
pub recurse_into_file_modules: bool,
|
||||
pub(super) recurse_into_file_modules: bool,
|
||||
/// Name of the root module this parser originated from. If `None`, then the
|
||||
/// name is not known. This does not change while the parser is descending
|
||||
/// into modules, and sub-parsers have new values for this name.
|
||||
pub root_module_name: Option<String>,
|
||||
crate expected_tokens: Vec<TokenType>,
|
||||
crate root_module_name: Option<String>,
|
||||
expected_tokens: Vec<TokenType>,
|
||||
token_cursor: TokenCursor,
|
||||
desugar_doc_comments: bool,
|
||||
/// `true` we should configure out of line modules as we parse.
|
||||
pub cfg_mods: bool,
|
||||
cfg_mods: bool,
|
||||
/// This field is used to keep track of how many left angle brackets we have seen. This is
|
||||
/// required in order to detect extra leading left angle brackets (`<` characters) and error
|
||||
/// appropriately.
|
||||
///
|
||||
/// See the comments in the `parse_path_segment` function for more details.
|
||||
crate unmatched_angle_bracket_count: u32,
|
||||
crate max_angle_bracket_count: u32,
|
||||
unmatched_angle_bracket_count: u32,
|
||||
max_angle_bracket_count: u32,
|
||||
/// A list of all unclosed delimiters found by the lexer. If an entry is used for error recovery
|
||||
/// it gets removed from here. Every entry left at the end gets emitted as an independent
|
||||
/// error.
|
||||
crate unclosed_delims: Vec<UnmatchedBrace>,
|
||||
crate last_unexpected_token_span: Option<Span>,
|
||||
pub(super) unclosed_delims: Vec<UnmatchedBrace>,
|
||||
last_unexpected_token_span: Option<Span>,
|
||||
crate last_type_ascription: Option<(Span, bool /* likely path typo */)>,
|
||||
/// If present, this `Parser` is not parsing Rust code but rather a macro call.
|
||||
crate subparser_name: Option<&'static str>,
|
||||
subparser_name: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl<'a> Drop for Parser<'a> {
|
||||
|
@ -196,7 +194,7 @@ struct TokenCursorFrame {
|
|||
/// You can find some more example usage of this in the `collect_tokens` method
|
||||
/// on the parser.
|
||||
#[derive(Clone)]
|
||||
crate enum LastToken {
|
||||
enum LastToken {
|
||||
Collecting(Vec<TreeAndJoint>),
|
||||
Was(Option<TreeAndJoint>),
|
||||
}
|
||||
|
@ -299,7 +297,7 @@ impl TokenCursor {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
crate enum TokenType {
|
||||
enum TokenType {
|
||||
Token(TokenKind),
|
||||
Keyword(Symbol),
|
||||
Operator,
|
||||
|
@ -311,7 +309,7 @@ crate enum TokenType {
|
|||
}
|
||||
|
||||
impl TokenType {
|
||||
crate fn to_string(&self) -> String {
|
||||
fn to_string(&self) -> String {
|
||||
match *self {
|
||||
TokenType::Token(ref t) => format!("`{}`", pprust::token_kind_to_string(t)),
|
||||
TokenType::Keyword(kw) => format!("`{}`", kw),
|
||||
|
@ -326,13 +324,13 @@ impl TokenType {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
crate enum TokenExpectType {
|
||||
enum TokenExpectType {
|
||||
Expect,
|
||||
NoExpect,
|
||||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn new(
|
||||
crate fn new(
|
||||
sess: &'a ParseSess,
|
||||
tokens: TokenStream,
|
||||
directory: Option<Directory<'a>>,
|
||||
|
@ -407,7 +405,7 @@ impl<'a> Parser<'a> {
|
|||
pprust::token_to_string(&self.token)
|
||||
}
|
||||
|
||||
crate fn token_descr(&self) -> Option<&'static str> {
|
||||
fn token_descr(&self) -> Option<&'static str> {
|
||||
Some(match &self.token.kind {
|
||||
_ if self.token.is_special_ident() => "reserved identifier",
|
||||
_ if self.token.is_used_keyword() => "keyword",
|
||||
|
@ -417,7 +415,7 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
crate fn this_token_descr(&self) -> String {
|
||||
pub(super) fn this_token_descr(&self) -> String {
|
||||
if let Some(prefix) = self.token_descr() {
|
||||
format!("{} `{}`", prefix, self.this_token_to_string())
|
||||
} else {
|
||||
|
@ -467,7 +465,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
|
||||
fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
|
||||
self.parse_ident_common(true)
|
||||
}
|
||||
|
||||
|
@ -500,7 +498,7 @@ impl<'a> Parser<'a> {
|
|||
///
|
||||
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
|
||||
/// encountered.
|
||||
crate fn check(&mut self, tok: &TokenKind) -> bool {
|
||||
fn check(&mut self, tok: &TokenKind) -> bool {
|
||||
let is_present = self.token == *tok;
|
||||
if !is_present { self.expected_tokens.push(TokenType::Token(tok.clone())); }
|
||||
is_present
|
||||
|
@ -522,7 +520,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// If the next token is the given keyword, eats it and returns `true`.
|
||||
/// Otherwise, returns `false`. An expectation is also added for diagnostics purposes.
|
||||
pub fn eat_keyword(&mut self, kw: Symbol) -> bool {
|
||||
fn eat_keyword(&mut self, kw: Symbol) -> bool {
|
||||
if self.check_keyword(kw) {
|
||||
self.bump();
|
||||
true
|
||||
|
@ -560,7 +558,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn check_ident(&mut self) -> bool {
|
||||
fn check_ident(&mut self) -> bool {
|
||||
self.check_or_expected(self.token.is_ident(), TokenType::Ident)
|
||||
}
|
||||
|
||||
|
@ -725,7 +723,7 @@ impl<'a> Parser<'a> {
|
|||
/// Parses a sequence, including the closing delimiter. The function
|
||||
/// `f` must consume tokens until reaching the next separator or
|
||||
/// closing bracket.
|
||||
pub fn parse_seq_to_end<T>(
|
||||
fn parse_seq_to_end<T>(
|
||||
&mut self,
|
||||
ket: &TokenKind,
|
||||
sep: SeqSep,
|
||||
|
@ -741,7 +739,7 @@ impl<'a> Parser<'a> {
|
|||
/// Parses a sequence, not including the closing delimiter. The function
|
||||
/// `f` must consume tokens until reaching the next separator or
|
||||
/// closing bracket.
|
||||
pub fn parse_seq_to_before_end<T>(
|
||||
fn parse_seq_to_before_end<T>(
|
||||
&mut self,
|
||||
ket: &TokenKind,
|
||||
sep: SeqSep,
|
||||
|
@ -759,7 +757,7 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
crate fn parse_seq_to_before_tokens<T>(
|
||||
fn parse_seq_to_before_tokens<T>(
|
||||
&mut self,
|
||||
kets: &[&TokenKind],
|
||||
sep: SeqSep,
|
||||
|
@ -1101,7 +1099,7 @@ impl<'a> Parser<'a> {
|
|||
/// If the following element can't be a tuple (i.e., it's a function definition), then
|
||||
/// it's not a tuple struct field), and the contents within the parentheses isn't valid,
|
||||
/// so emit a proper diagnostic.
|
||||
pub fn parse_visibility(&mut self, can_take_tuple: bool) -> PResult<'a, Visibility> {
|
||||
crate fn parse_visibility(&mut self, can_take_tuple: bool) -> PResult<'a, Visibility> {
|
||||
maybe_whole!(self, NtVis, |x| x);
|
||||
|
||||
self.expected_tokens.push(TokenType::Keyword(kw::Crate));
|
||||
|
@ -1325,7 +1323,7 @@ impl<'a> Parser<'a> {
|
|||
*t == token::BinOp(token::Star))
|
||||
}
|
||||
|
||||
pub fn parse_optional_str(&mut self) -> Option<(Symbol, ast::StrStyle, Option<ast::Name>)> {
|
||||
fn parse_optional_str(&mut self) -> Option<(Symbol, ast::StrStyle, Option<ast::Name>)> {
|
||||
let ret = match self.token.kind {
|
||||
token::Literal(token::Lit { kind: token::Str, symbol, suffix }) =>
|
||||
(symbol, ast::StrStyle::Cooked, suffix),
|
||||
|
|
|
@ -20,7 +20,7 @@ const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &str = "an inner attribute is not \
|
|||
|
||||
impl<'a> Parser<'a> {
|
||||
/// Parses attributes that appear before an item.
|
||||
crate fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
|
||||
pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
|
||||
let mut attrs: Vec<ast::Attribute> = Vec::new();
|
||||
let mut just_parsed_doc_comment = false;
|
||||
loop {
|
||||
|
@ -66,7 +66,7 @@ impl<'a> Parser<'a> {
|
|||
///
|
||||
/// If `permit_inner` is `true`, then a leading `!` indicates an inner
|
||||
/// attribute.
|
||||
pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, ast::Attribute> {
|
||||
fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, ast::Attribute> {
|
||||
debug!("parse_attribute: permit_inner={:?} self.token={:?}",
|
||||
permit_inner,
|
||||
self.token);
|
||||
|
@ -84,9 +84,10 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// The same as `parse_attribute`, except it takes in an `InnerAttributeParsePolicy`
|
||||
/// that prescribes how to handle inner attributes.
|
||||
fn parse_attribute_with_inner_parse_policy(&mut self,
|
||||
inner_parse_policy: InnerAttributeParsePolicy<'_>)
|
||||
-> PResult<'a, ast::Attribute> {
|
||||
fn parse_attribute_with_inner_parse_policy(
|
||||
&mut self,
|
||||
inner_parse_policy: InnerAttributeParsePolicy<'_>
|
||||
) -> PResult<'a, ast::Attribute> {
|
||||
debug!("parse_attribute_with_inner_parse_policy: inner_parse_policy={:?} self.token={:?}",
|
||||
inner_parse_policy,
|
||||
self.token);
|
||||
|
|
|
@ -17,8 +17,9 @@ use log::{debug, trace};
|
|||
use std::mem;
|
||||
|
||||
const TURBOFISH: &'static str = "use `::<...>` instead of `<...>` to specify type arguments";
|
||||
|
||||
/// Creates a placeholder argument.
|
||||
crate fn dummy_arg(ident: Ident) -> Param {
|
||||
pub(super) fn dummy_arg(ident: Ident) -> Param {
|
||||
let pat = P(Pat {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), ident, None),
|
||||
|
@ -121,7 +122,7 @@ impl Error {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait RecoverQPath: Sized + 'static {
|
||||
pub(super) trait RecoverQPath: Sized + 'static {
|
||||
const PATH_STYLE: PathStyle = PathStyle::Expr;
|
||||
fn to_ty(&self) -> Option<P<Ty>>;
|
||||
fn recovered(qself: Option<QSelf>, path: ast::Path) -> Self;
|
||||
|
@ -169,23 +170,23 @@ impl RecoverQPath for Expr {
|
|||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn fatal(&self, m: &str) -> DiagnosticBuilder<'a> {
|
||||
crate fn fatal(&self, m: &str) -> DiagnosticBuilder<'a> {
|
||||
self.span_fatal(self.token.span, m)
|
||||
}
|
||||
|
||||
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
|
||||
crate fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
|
||||
self.sess.span_diagnostic.struct_span_fatal(sp, m)
|
||||
}
|
||||
|
||||
pub fn span_fatal_err<S: Into<MultiSpan>>(&self, sp: S, err: Error) -> DiagnosticBuilder<'a> {
|
||||
pub(super) fn span_fatal_err<S: Into<MultiSpan>>(&self, sp: S, err: Error) -> DiagnosticBuilder<'a> {
|
||||
err.span_err(sp, self.diagnostic())
|
||||
}
|
||||
|
||||
pub fn bug(&self, m: &str) -> ! {
|
||||
pub(super) fn bug(&self, m: &str) -> ! {
|
||||
self.sess.span_diagnostic.span_bug(self.token.span, m)
|
||||
}
|
||||
|
||||
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) {
|
||||
pub(super) fn span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) {
|
||||
self.sess.span_diagnostic.span_err(sp, m)
|
||||
}
|
||||
|
||||
|
@ -197,15 +198,15 @@ impl<'a> Parser<'a> {
|
|||
self.sess.span_diagnostic.span_bug(sp, m)
|
||||
}
|
||||
|
||||
crate fn diagnostic(&self) -> &'a errors::Handler {
|
||||
pub(super) fn diagnostic(&self) -> &'a errors::Handler {
|
||||
&self.sess.span_diagnostic
|
||||
}
|
||||
|
||||
crate fn span_to_snippet(&self, span: Span) -> Result<String, SpanSnippetError> {
|
||||
pub(super) fn span_to_snippet(&self, span: Span) -> Result<String, SpanSnippetError> {
|
||||
self.sess.source_map().span_to_snippet(span)
|
||||
}
|
||||
|
||||
crate fn expected_ident_found(&self) -> DiagnosticBuilder<'a> {
|
||||
pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a> {
|
||||
let mut err = self.struct_span_err(
|
||||
self.token.span,
|
||||
&format!("expected identifier, found {}", self.this_token_descr()),
|
||||
|
@ -236,7 +237,7 @@ impl<'a> Parser<'a> {
|
|||
err
|
||||
}
|
||||
|
||||
pub fn expected_one_of_not_found(
|
||||
pub(super) fn expected_one_of_not_found(
|
||||
&mut self,
|
||||
edible: &[TokenKind],
|
||||
inedible: &[TokenKind],
|
||||
|
@ -423,7 +424,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Eats and discards tokens until one of `kets` is encountered. Respects token trees,
|
||||
/// passes through any errors encountered. Used for error recovery.
|
||||
crate fn eat_to_tokens(&mut self, kets: &[&TokenKind]) {
|
||||
pub(super) fn eat_to_tokens(&mut self, kets: &[&TokenKind]) {
|
||||
if let Err(ref mut err) = self.parse_seq_to_before_tokens(
|
||||
kets,
|
||||
SeqSep::none(),
|
||||
|
@ -441,7 +442,7 @@ impl<'a> Parser<'a> {
|
|||
/// let _ = vec![1, 2, 3].into_iter().collect::<Vec<usize>>>>();
|
||||
/// ^^ help: remove extra angle brackets
|
||||
/// ```
|
||||
crate fn check_trailing_angle_brackets(&mut self, segment: &PathSegment, end: TokenKind) {
|
||||
pub(super) fn check_trailing_angle_brackets(&mut self, segment: &PathSegment, end: TokenKind) {
|
||||
// This function is intended to be invoked after parsing a path segment where there are two
|
||||
// cases:
|
||||
//
|
||||
|
@ -560,7 +561,7 @@ impl<'a> Parser<'a> {
|
|||
/// inner_op r2
|
||||
/// / \
|
||||
/// l1 r1
|
||||
crate fn check_no_chained_comparison(
|
||||
pub(super) fn check_no_chained_comparison(
|
||||
&mut self,
|
||||
lhs: &Expr,
|
||||
outer_op: &AssocOp,
|
||||
|
@ -695,7 +696,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn maybe_report_ambiguous_plus(
|
||||
pub(super) fn maybe_report_ambiguous_plus(
|
||||
&mut self,
|
||||
allow_plus: bool,
|
||||
impl_dyn_multi: bool,
|
||||
|
@ -768,7 +769,7 @@ impl<'a> Parser<'a> {
|
|||
/// Tries to recover from associated item paths like `[T]::AssocItem` / `(T, U)::AssocItem`.
|
||||
/// Attempts to convert the base expression/pattern/type into a type, parses the `::AssocItem`
|
||||
/// tail, and combines them into a `<Ty>::AssocItem` expression/pattern/type.
|
||||
crate fn maybe_recover_from_bad_qpath<T: RecoverQPath>(
|
||||
pub(super) fn maybe_recover_from_bad_qpath<T: RecoverQPath>(
|
||||
&mut self,
|
||||
base: P<T>,
|
||||
allow_recovery: bool,
|
||||
|
@ -784,7 +785,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Given an already parsed `Ty`, parses the `::AssocItem` tail and
|
||||
/// combines them into a `<Ty>::AssocItem` expression/pattern/type.
|
||||
crate fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>(
|
||||
pub(super) fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>(
|
||||
&mut self,
|
||||
ty_span: Span,
|
||||
ty: P<Ty>,
|
||||
|
@ -823,7 +824,7 @@ impl<'a> Parser<'a> {
|
|||
)))
|
||||
}
|
||||
|
||||
crate fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
|
||||
pub(super) fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
|
||||
if self.eat(&token::Semi) {
|
||||
let mut err = self.struct_span_err(self.prev_span, "expected item, found `;`");
|
||||
err.span_suggestion_short(
|
||||
|
@ -859,7 +860,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Creates a `DiagnosticBuilder` for an unexpected token `t` and tries to recover if it is a
|
||||
/// closing delimiter.
|
||||
pub fn unexpected_try_recover(
|
||||
pub(super) fn unexpected_try_recover(
|
||||
&mut self,
|
||||
t: &TokenKind,
|
||||
) -> PResult<'a, bool /* recovered */> {
|
||||
|
@ -909,7 +910,7 @@ impl<'a> Parser<'a> {
|
|||
Err(err)
|
||||
}
|
||||
|
||||
crate fn parse_semi_or_incorrect_foreign_fn_body(
|
||||
pub(super) fn parse_semi_or_incorrect_foreign_fn_body(
|
||||
&mut self,
|
||||
ident: &Ident,
|
||||
extern_sp: Span,
|
||||
|
@ -947,7 +948,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Consumes alternative await syntaxes like `await!(<expr>)`, `await <expr>`,
|
||||
/// `await? <expr>`, `await(<expr>)`, and `await { <expr> }`.
|
||||
crate fn parse_incorrect_await_syntax(
|
||||
pub(super) fn parse_incorrect_await_syntax(
|
||||
&mut self,
|
||||
lo: Span,
|
||||
await_sp: Span,
|
||||
|
@ -999,7 +1000,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// If encountering `future.await()`, consumes and emits an error.
|
||||
crate fn recover_from_await_method_call(&mut self) {
|
||||
pub(super) fn recover_from_await_method_call(&mut self) {
|
||||
if self.token == token::OpenDelim(token::Paren) &&
|
||||
self.look_ahead(1, |t| t == &token::CloseDelim(token::Paren))
|
||||
{
|
||||
|
@ -1022,7 +1023,7 @@ impl<'a> Parser<'a> {
|
|||
/// and suggest writing `for $pat in $expr` instead.
|
||||
///
|
||||
/// This should be called before parsing the `$block`.
|
||||
crate fn recover_parens_around_for_head(
|
||||
pub(super) fn recover_parens_around_for_head(
|
||||
&mut self,
|
||||
pat: P<Pat>,
|
||||
expr: &Expr,
|
||||
|
@ -1060,7 +1061,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool {
|
||||
pub(super) fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool {
|
||||
self.token.is_ident() &&
|
||||
if let ast::ExprKind::Path(..) = node { true } else { false } &&
|
||||
!self.token.is_reserved_ident() && // v `foo:bar(baz)`
|
||||
|
@ -1074,7 +1075,7 @@ impl<'a> Parser<'a> {
|
|||
self.look_ahead(2, |t| t == &token::Lt)) // `foo:bar::<baz>`
|
||||
}
|
||||
|
||||
crate fn recover_seq_parse_error(
|
||||
pub(super) fn recover_seq_parse_error(
|
||||
&mut self,
|
||||
delim: token::DelimToken,
|
||||
lo: Span,
|
||||
|
@ -1091,7 +1092,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn recover_closing_delimiter(
|
||||
pub(super) fn recover_closing_delimiter(
|
||||
&mut self,
|
||||
tokens: &[TokenKind],
|
||||
mut err: DiagnosticBuilder<'a>,
|
||||
|
@ -1142,7 +1143,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Recovers from `pub` keyword in places where it seems _reasonable_ but isn't valid.
|
||||
crate fn eat_bad_pub(&mut self) {
|
||||
pub(super) fn eat_bad_pub(&mut self) {
|
||||
if self.token.is_keyword(kw::Pub) {
|
||||
match self.parse_visibility(false) {
|
||||
Ok(vis) => {
|
||||
|
@ -1160,7 +1161,7 @@ impl<'a> Parser<'a> {
|
|||
/// statement. This is something of a best-effort heuristic.
|
||||
///
|
||||
/// We terminate when we find an unmatched `}` (without consuming it).
|
||||
crate fn recover_stmt(&mut self) {
|
||||
pub(super) fn recover_stmt(&mut self) {
|
||||
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore)
|
||||
}
|
||||
|
||||
|
@ -1171,7 +1172,7 @@ impl<'a> Parser<'a> {
|
|||
///
|
||||
/// If `break_on_block` is `Break`, then we will stop consuming tokens
|
||||
/// after finding (and consuming) a brace-delimited block.
|
||||
crate fn recover_stmt_(&mut self, break_on_semi: SemiColonMode, break_on_block: BlockMode) {
|
||||
pub(super) fn recover_stmt_(&mut self, break_on_semi: SemiColonMode, break_on_block: BlockMode) {
|
||||
let mut brace_depth = 0;
|
||||
let mut bracket_depth = 0;
|
||||
let mut in_block = false;
|
||||
|
@ -1239,7 +1240,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn check_for_for_in_in_typo(&mut self, in_span: Span) {
|
||||
pub(super) fn check_for_for_in_in_typo(&mut self, in_span: Span) {
|
||||
if self.eat_keyword(kw::In) {
|
||||
// a common typo: `for _ in in bar {}`
|
||||
self.struct_span_err(self.prev_span, "expected iterable, found keyword `in`")
|
||||
|
@ -1253,14 +1254,14 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn expected_semi_or_open_brace<T>(&mut self) -> PResult<'a, T> {
|
||||
pub(super) fn expected_semi_or_open_brace<T>(&mut self) -> PResult<'a, T> {
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!("expected `;` or `{{`, found {}", token_str));
|
||||
err.span_label(self.token.span, "expected `;` or `{`");
|
||||
Err(err)
|
||||
}
|
||||
|
||||
crate fn eat_incorrect_doc_comment_for_param_type(&mut self) {
|
||||
pub(super) fn eat_incorrect_doc_comment_for_param_type(&mut self) {
|
||||
if let token::DocComment(_) = self.token.kind {
|
||||
self.struct_span_err(
|
||||
self.token.span,
|
||||
|
@ -1288,7 +1289,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn parameter_without_type(
|
||||
pub(super) fn parameter_without_type(
|
||||
&mut self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
pat: P<ast::Pat>,
|
||||
|
@ -1351,7 +1352,7 @@ impl<'a> Parser<'a> {
|
|||
None
|
||||
}
|
||||
|
||||
crate fn recover_arg_parse(&mut self) -> PResult<'a, (P<ast::Pat>, P<ast::Ty>)> {
|
||||
pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (P<ast::Pat>, P<ast::Ty>)> {
|
||||
let pat = self.parse_pat(Some("argument name"))?;
|
||||
self.expect(&token::Colon)?;
|
||||
let ty = self.parse_ty()?;
|
||||
|
@ -1379,7 +1380,7 @@ impl<'a> Parser<'a> {
|
|||
Ok((pat, ty))
|
||||
}
|
||||
|
||||
crate fn recover_bad_self_param(
|
||||
pub(super) fn recover_bad_self_param(
|
||||
&mut self,
|
||||
mut param: ast::Param,
|
||||
is_trait_item: bool,
|
||||
|
@ -1397,7 +1398,7 @@ impl<'a> Parser<'a> {
|
|||
Ok(param)
|
||||
}
|
||||
|
||||
crate fn consume_block(&mut self, delim: token::DelimToken) {
|
||||
pub(super) fn consume_block(&mut self, delim: token::DelimToken) {
|
||||
let mut brace_depth = 0;
|
||||
loop {
|
||||
if self.eat(&token::OpenDelim(delim)) {
|
||||
|
@ -1417,7 +1418,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn expected_expression_found(&self) -> DiagnosticBuilder<'a> {
|
||||
pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a> {
|
||||
let (span, msg) = match (&self.token.kind, self.subparser_name) {
|
||||
(&token::Eof, Some(origin)) => {
|
||||
let sp = self.sess.source_map().next_point(self.token.span);
|
||||
|
@ -1462,7 +1463,7 @@ impl<'a> Parser<'a> {
|
|||
/// the parameters are *names* (so we don't emit errors about not being able to find `b` in
|
||||
/// the local scope), but if we find the same name multiple times, like in `fn foo(i8, i8)`,
|
||||
/// we deduplicate them to not complain about duplicated parameter names.
|
||||
crate fn deduplicate_recovered_params_names(&self, fn_inputs: &mut Vec<Param>) {
|
||||
pub(super) fn deduplicate_recovered_params_names(&self, fn_inputs: &mut Vec<Param>) {
|
||||
let mut seen_inputs = FxHashSet::default();
|
||||
for input in fn_inputs.iter_mut() {
|
||||
let opt_ident = if let (PatKind::Ident(_, ident, _), TyKind::Err) = (
|
||||
|
|
|
@ -1074,7 +1074,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Matches `lit = true | false | token_lit`.
|
||||
crate fn parse_lit(&mut self) -> PResult<'a, Lit> {
|
||||
pub(super) fn parse_lit(&mut self) -> PResult<'a, Lit> {
|
||||
let mut recovered = None;
|
||||
if self.token == token::Dot {
|
||||
// Attempt to recover `.4` as `0.4`.
|
||||
|
@ -1253,7 +1253,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses a block or unsafe block.
|
||||
crate fn parse_block_expr(
|
||||
pub(super) fn parse_block_expr(
|
||||
&mut self,
|
||||
opt_label: Option<Label>,
|
||||
lo: Span,
|
||||
|
@ -1558,7 +1558,7 @@ impl<'a> Parser<'a> {
|
|||
return Ok(self.mk_expr(lo.to(hi), ExprKind::Match(discriminant, arms), attrs));
|
||||
}
|
||||
|
||||
crate fn parse_arm(&mut self) -> PResult<'a, Arm> {
|
||||
pub(super) fn parse_arm(&mut self) -> PResult<'a, Arm> {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
let lo = self.token.span;
|
||||
let pat = self.parse_top_pat(GateOr::No)?;
|
||||
|
@ -1666,7 +1666,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses an `async move? {...}` expression.
|
||||
pub fn parse_async_block(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
|
||||
fn parse_async_block(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
|
||||
let span_lo = self.token.span;
|
||||
self.expect_keyword(kw::Async)?;
|
||||
let capture_clause = self.parse_capture_clause();
|
||||
|
|
|
@ -74,7 +74,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Parses a (possibly empty) list of lifetime and type parameters, possibly including
|
||||
/// a trailing comma and erroneous trailing attributes.
|
||||
crate fn parse_generic_params(&mut self) -> PResult<'a, Vec<ast::GenericParam>> {
|
||||
pub(super) fn parse_generic_params(&mut self) -> PResult<'a, Vec<ast::GenericParam>> {
|
||||
let mut params = Vec::new();
|
||||
loop {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
|
|
|
@ -24,7 +24,7 @@ use errors::{Applicability, DiagnosticBuilder, DiagnosticId, StashKey};
|
|||
|
||||
/// Whether the type alias or associated type is a concrete type or an opaque type.
|
||||
#[derive(Debug)]
|
||||
pub enum AliasKind {
|
||||
pub(super) enum AliasKind {
|
||||
/// Just a new name for the same type.
|
||||
Weak(P<Ty>),
|
||||
/// Only trait impls of the type will be usable, not the actual type itself.
|
||||
|
@ -675,7 +675,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses an impl item.
|
||||
pub fn parse_impl_item(&mut self, at_end: &mut bool) -> PResult<'a, ImplItem> {
|
||||
crate fn parse_impl_item(&mut self, at_end: &mut bool) -> PResult<'a, ImplItem> {
|
||||
maybe_whole!(self, NtImplItem, |x| x);
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
let mut unclosed_delims = vec![];
|
||||
|
@ -851,7 +851,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses the items in a trait declaration.
|
||||
pub fn parse_trait_item(&mut self, at_end: &mut bool) -> PResult<'a, TraitItem> {
|
||||
crate fn parse_trait_item(&mut self, at_end: &mut bool) -> PResult<'a, TraitItem> {
|
||||
maybe_whole!(self, NtTraitItem, |x| x);
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
let mut unclosed_delims = vec![];
|
||||
|
|
|
@ -12,13 +12,13 @@ use crate::symbol::sym;
|
|||
use std::path::{self, Path, PathBuf};
|
||||
|
||||
/// Information about the path to a module.
|
||||
pub struct ModulePath {
|
||||
pub(super) struct ModulePath {
|
||||
name: String,
|
||||
path_exists: bool,
|
||||
pub result: Result<ModulePathSuccess, Error>,
|
||||
}
|
||||
|
||||
pub struct ModulePathSuccess {
|
||||
pub(super) struct ModulePathSuccess {
|
||||
pub path: PathBuf,
|
||||
pub directory_ownership: DirectoryOwnership,
|
||||
warn: bool,
|
||||
|
@ -26,7 +26,7 @@ pub struct ModulePathSuccess {
|
|||
|
||||
impl<'a> Parser<'a> {
|
||||
/// Parses a source module as a crate. This is the main entry point for the parser.
|
||||
pub fn parse_crate_mod(&mut self) -> PResult<'a, Crate> {
|
||||
crate fn parse_crate_mod(&mut self) -> PResult<'a, Crate> {
|
||||
let lo = self.token.span;
|
||||
let krate = Ok(ast::Crate {
|
||||
attrs: self.parse_inner_attributes()?,
|
||||
|
@ -198,7 +198,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn submod_path_from_attr(attrs: &[Attribute], dir_path: &Path) -> Option<PathBuf> {
|
||||
pub(super) fn submod_path_from_attr(attrs: &[Attribute], dir_path: &Path) -> Option<PathBuf> {
|
||||
if let Some(s) = attr::first_attr_value_str_by_name(attrs, sym::path) {
|
||||
let s = s.as_str();
|
||||
|
||||
|
@ -215,7 +215,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Returns a path to a module.
|
||||
pub fn default_submod_path(
|
||||
pub(super) fn default_submod_path(
|
||||
id: ast::Ident,
|
||||
relative: Option<ast::Ident>,
|
||||
dir_path: &Path,
|
||||
|
|
|
@ -22,7 +22,7 @@ const WHILE_PARSING_OR_MSG: &str = "while parsing this or-pattern starting here"
|
|||
|
||||
/// Whether or not an or-pattern should be gated when occurring in the current context.
|
||||
#[derive(PartialEq)]
|
||||
pub enum GateOr { Yes, No }
|
||||
pub(super) enum GateOr { Yes, No }
|
||||
|
||||
/// Whether or not to recover a `,` when parsing or-patterns.
|
||||
#[derive(PartialEq, Copy, Clone)]
|
||||
|
@ -34,7 +34,7 @@ impl<'a> Parser<'a> {
|
|||
/// Corresponds to `pat<no_top_alt>` in RFC 2535 and does not admit or-patterns
|
||||
/// at the top level. Used when parsing the parameters of lambda expressions,
|
||||
/// functions, function pointers, and `pat` macro fragments.
|
||||
pub fn parse_pat(&mut self, expected: Expected) -> PResult<'a, P<Pat>> {
|
||||
crate fn parse_pat(&mut self, expected: Expected) -> PResult<'a, P<Pat>> {
|
||||
self.parse_pat_with_range_pat(true, expected)
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use errors::{Applicability, pluralise};
|
|||
|
||||
/// Specifies how to parse a path.
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum PathStyle {
|
||||
crate enum PathStyle {
|
||||
/// In some contexts, notably in expressions, paths with generic arguments are ambiguous
|
||||
/// with something else. For example, in expressions `segment < ....` can be interpreted
|
||||
/// as a comparison and `segment ( ....` can be interpreted as a function call.
|
||||
|
@ -88,7 +88,7 @@ impl<'a> Parser<'a> {
|
|||
/// `a::b::C::<D>` (with disambiguator)
|
||||
/// `Fn(Args)` (without disambiguator)
|
||||
/// `Fn::(Args)` (with disambiguator)
|
||||
pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Path> {
|
||||
crate fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Path> {
|
||||
maybe_whole!(self, NtPath, |path| {
|
||||
if style == PathStyle::Mod &&
|
||||
path.segments.iter().any(|segment| segment.args.is_some()) {
|
||||
|
@ -144,7 +144,7 @@ impl<'a> Parser<'a> {
|
|||
Ok(list)
|
||||
}
|
||||
|
||||
crate fn parse_path_segments(
|
||||
pub(super) fn parse_path_segments(
|
||||
&mut self,
|
||||
segments: &mut Vec<PathSegment>,
|
||||
style: PathStyle,
|
||||
|
|
|
@ -20,7 +20,7 @@ use errors::Applicability;
|
|||
impl<'a> Parser<'a> {
|
||||
/// Parses a statement. This stops just before trailing semicolons on everything but items.
|
||||
/// e.g., a `StmtKind::Semi` parses to a `StmtKind::Expr`, leaving the trailing `;` unconsumed.
|
||||
pub fn parse_stmt(&mut self) -> PResult<'a, Option<Stmt>> {
|
||||
crate fn parse_stmt(&mut self) -> PResult<'a, Option<Stmt>> {
|
||||
Ok(self.parse_stmt_(true))
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses a block. No inner attributes are allowed.
|
||||
pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
|
||||
crate fn parse_block(&mut self) -> PResult<'a, P<Block>> {
|
||||
maybe_whole!(self, NtBlock, |x| x);
|
||||
|
||||
let lo = self.token.span;
|
||||
|
@ -373,7 +373,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses a block. Inner attributes are allowed.
|
||||
crate fn parse_inner_attrs_and_block(&mut self) -> PResult<'a, (Vec<Attribute>, P<Block>)> {
|
||||
pub(super) fn parse_inner_attrs_and_block(&mut self) -> PResult<'a, (Vec<Attribute>, P<Block>)> {
|
||||
maybe_whole!(self, NtBlock, |x| (Vec::new(), x));
|
||||
|
||||
let lo = self.token.span;
|
||||
|
|
|
@ -296,7 +296,7 @@ impl<'a> Parser<'a> {
|
|||
})))
|
||||
}
|
||||
|
||||
crate fn parse_generic_bounds(&mut self,
|
||||
pub(super) fn parse_generic_bounds(&mut self,
|
||||
colon_span: Option<Span>) -> PResult<'a, GenericBounds> {
|
||||
self.parse_generic_bounds_common(true, colon_span)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue