Inline and remove parse_crate{,_attrs}_from_{file,source_str}
.
All four functions are simple and have a single call site. This requires making `Parser::parse_inner_attributes` public, which is no big deal.
This commit is contained in:
parent
8964106e44
commit
25972aec67
4 changed files with 16 additions and 40 deletions
|
@ -47,35 +47,6 @@ fn unwrap_or_emit_fatal<T>(expr: Result<T, Vec<Diag<'_>>>) -> T {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_crate_from_file<'a>(input: &Path, psess: &'a ParseSess) -> PResult<'a, ast::Crate> {
|
||||
let mut parser = new_parser_from_file(psess, input, None);
|
||||
parser.parse_crate_mod()
|
||||
}
|
||||
|
||||
pub fn parse_crate_attrs_from_file<'a>(
|
||||
input: &Path,
|
||||
psess: &'a ParseSess,
|
||||
) -> PResult<'a, ast::AttrVec> {
|
||||
let mut parser = new_parser_from_file(psess, input, None);
|
||||
parser.parse_inner_attributes()
|
||||
}
|
||||
|
||||
pub fn parse_crate_from_source_str(
|
||||
name: FileName,
|
||||
source: String,
|
||||
psess: &ParseSess,
|
||||
) -> PResult<'_, ast::Crate> {
|
||||
new_parser_from_source_str(psess, name, source).parse_crate_mod()
|
||||
}
|
||||
|
||||
pub fn parse_crate_attrs_from_source_str(
|
||||
name: FileName,
|
||||
source: String,
|
||||
psess: &ParseSess,
|
||||
) -> PResult<'_, ast::AttrVec> {
|
||||
new_parser_from_source_str(psess, name, source).parse_inner_attributes()
|
||||
}
|
||||
|
||||
/// Creates a new parser from a source string.
|
||||
pub fn new_parser_from_source_str(psess: &ParseSess, name: FileName, source: String) -> Parser<'_> {
|
||||
unwrap_or_emit_fatal(maybe_new_parser_from_source_str(psess, name, source))
|
||||
|
|
|
@ -265,7 +265,7 @@ impl<'a> Parser<'a> {
|
|||
/// terminated by a semicolon.
|
||||
///
|
||||
/// Matches `inner_attrs*`.
|
||||
pub(crate) fn parse_inner_attributes(&mut self) -> PResult<'a, ast::AttrVec> {
|
||||
pub fn parse_inner_attributes(&mut self) -> PResult<'a, ast::AttrVec> {
|
||||
let mut attrs = ast::AttrVec::new();
|
||||
loop {
|
||||
let start_pos: u32 = self.num_bump_calls.try_into().unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue