mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
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
@ -32,6 +32,7 @@ use rustc_interface::{interface, Queries};
|
||||
use rustc_lint::unerased_lint_store;
|
||||
use rustc_metadata::creader::MetadataLoader;
|
||||
use rustc_metadata::locator;
|
||||
use rustc_parse::{new_parser_from_file, new_parser_from_source_str};
|
||||
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
|
||||
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType};
|
||||
use rustc_session::getopts::{self, Matches};
|
||||
@ -1264,12 +1265,13 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
|
||||
}
|
||||
|
||||
fn parse_crate_attrs<'a>(sess: &'a Session) -> PResult<'a, ast::AttrVec> {
|
||||
match &sess.io.input {
|
||||
Input::File(ifile) => rustc_parse::parse_crate_attrs_from_file(ifile, &sess.psess),
|
||||
let mut parser = match &sess.io.input {
|
||||
Input::File(file) => new_parser_from_file(&sess.psess, file, None),
|
||||
Input::Str { name, input } => {
|
||||
rustc_parse::parse_crate_attrs_from_source_str(name.clone(), input.clone(), &sess.psess)
|
||||
new_parser_from_source_str(&sess.psess, name.clone(), input.clone())
|
||||
}
|
||||
}
|
||||
};
|
||||
parser.parse_inner_attributes()
|
||||
}
|
||||
|
||||
/// Runs a closure and catches unwinds triggered by fatal errors.
|
||||
|
@ -19,7 +19,7 @@ use rustc_middle::arena::Arena;
|
||||
use rustc_middle::dep_graph::DepGraph;
|
||||
use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, TyCtxt};
|
||||
use rustc_middle::util::Providers;
|
||||
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_attr};
|
||||
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, validate_attr};
|
||||
use rustc_passes::{abi_test, hir_stats, layout_test};
|
||||
use rustc_resolve::Resolver;
|
||||
use rustc_session::code_stats::VTableSizeInfo;
|
||||
@ -42,11 +42,14 @@ use std::{env, fs, iter};
|
||||
use tracing::{info, instrument};
|
||||
|
||||
pub fn parse<'a>(sess: &'a Session) -> PResult<'a, ast::Crate> {
|
||||
let krate = sess.time("parse_crate", || match &sess.io.input {
|
||||
Input::File(file) => parse_crate_from_file(file, &sess.psess),
|
||||
Input::Str { input, name } => {
|
||||
parse_crate_from_source_str(name.clone(), input.clone(), &sess.psess)
|
||||
}
|
||||
let krate = sess.time("parse_crate", || {
|
||||
let mut parser = match &sess.io.input {
|
||||
Input::File(file) => new_parser_from_file(&sess.psess, file, None),
|
||||
Input::Str { input, name } => {
|
||||
new_parser_from_source_str(&sess.psess, name.clone(), input.clone())
|
||||
}
|
||||
};
|
||||
parser.parse_crate_mod()
|
||||
})?;
|
||||
|
||||
if sess.opts.unstable_opts.input_stats {
|
||||
|
@ -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…
Reference in New Issue
Block a user