move function closer to its usage

This commit is contained in:
Aleksey Kladov 2019-09-25 10:17:59 +03:00
parent 9a020186f8
commit 538437e829
2 changed files with 14 additions and 13 deletions

View File

@ -413,18 +413,6 @@ fn nameize<I: Iterator<Item = NamedMatch>>(
Success(ret_val)
}
/// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For
/// other tokens, this is "unexpected token...".
crate fn parse_failure_msg(tok: &Token) -> String {
match tok.kind {
token::Eof => "unexpected end of macro invocation".to_string(),
_ => format!(
"no rules expected the token `{}`",
pprust::token_to_string(tok)
),
}
}
/// Performs a token equality check, ignoring syntax context (that is, an unhygienic comparison)
fn token_name_eq(t1: &Token, t2: &Token) -> bool {
if let (Some((ident1, is_raw1)), Some((ident2, is_raw2))) = (t1.ident(), t2.ident()) {

View File

@ -6,7 +6,7 @@ use crate::ext::base::{SyntaxExtension, SyntaxExtensionKind};
use crate::ext::expand::{AstFragment, AstFragmentKind};
use crate::ext::mbe;
use crate::ext::mbe::macro_check;
use crate::ext::mbe::macro_parser::{parse, parse_failure_msg};
use crate::ext::mbe::macro_parser::parse;
use crate::ext::mbe::macro_parser::{Error, Failure, Success};
use crate::ext::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedParseResult};
use crate::ext::mbe::transcribe::transcribe;
@ -15,6 +15,7 @@ use crate::parse::parser::Parser;
use crate::parse::token::TokenKind::*;
use crate::parse::token::{self, NtTT, Token};
use crate::parse::{Directory, ParseSess};
use crate::print::pprust;
use crate::symbol::{kw, sym, Symbol};
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
@ -1176,3 +1177,15 @@ impl TokenTree {
parse(cx.parse_sess(), tts, mtch, Some(directory), true)
}
}
/// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For
/// other tokens, this is "unexpected token...".
fn parse_failure_msg(tok: &Token) -> String {
match tok.kind {
token::Eof => "unexpected end of macro invocation".to_string(),
_ => format!(
"no rules expected the token `{}`",
pprust::token_to_string(tok),
),
}
}