Skip to content

Commit eaa0ae5

Browse files
committed
parse: nix new_sub_parser_from_file
1 parent d18ed20 commit eaa0ae5

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

src/librustc_builtin_macros/source_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast_pretty::pprust;
66
use rustc_expand::base::{self, *};
77
use rustc_expand::module::DirectoryOwnership;
88
use rustc_expand::panictry;
9-
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser};
9+
use rustc_parse::{self, new_parser_from_file, parser::Parser};
1010
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
1111
use rustc_span::symbol::Symbol;
1212
use rustc_span::{self, Pos, Span};
@@ -110,7 +110,7 @@ pub fn expand_include<'cx>(
110110
return DummyResult::any(sp);
111111
}
112112
};
113-
let p = new_sub_parser_from_file(cx.parse_sess(), &file, sp);
113+
let p = new_parser_from_file(cx.parse_sess(), &file, Some(sp));
114114

115115
// If in the included file we have e.g., `mod bar;`,
116116
// then the path of `bar.rs` should be relative to the directory of `file`.

src/librustc_expand/module.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::ast::{self, Attribute, Ident, Mod};
22
use rustc_ast::{attr, token};
33
use rustc_errors::{struct_span_err, PResult};
4-
use rustc_parse::new_sub_parser_from_file;
4+
use rustc_parse::new_parser_from_file;
55
use rustc_session::parse::ParseSess;
66
use rustc_span::source_map::{FileName, Span};
77
use rustc_span::symbol::sym;
@@ -60,7 +60,7 @@ crate fn parse_external_mod(
6060
drop(included_mod_stack);
6161

6262
// Actually parse the external file as a module.
63-
let mut module = new_sub_parser_from_file(sess, &mp.path, span).parse_mod(&token::Eof)?;
63+
let mut module = new_parser_from_file(sess, &mp.path, Some(span)).parse_mod(&token::Eof)?;
6464
module.0.inline = false;
6565
module
6666
};

src/librustc_parse/lib.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ macro_rules! panictry_buffer {
5050
}
5151

5252
pub fn parse_crate_from_file<'a>(input: &Path, sess: &'a ParseSess) -> PResult<'a, ast::Crate> {
53-
let mut parser = new_parser_from_file(sess, input);
53+
let mut parser = new_parser_from_file(sess, input, None);
5454
parser.parse_crate_mod()
5555
}
5656

5757
pub fn parse_crate_attrs_from_file<'a>(
5858
input: &Path,
5959
sess: &'a ParseSess,
6060
) -> PResult<'a, Vec<ast::Attribute>> {
61-
let mut parser = new_parser_from_file(sess, input);
61+
let mut parser = new_parser_from_file(sess, input, None);
6262
parser.parse_inner_attributes()
6363
}
6464

@@ -106,8 +106,9 @@ pub fn maybe_new_parser_from_source_str(
106106
}
107107

108108
/// Creates a new parser, handling errors as appropriate if the file doesn't exist.
109-
pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path) -> Parser<'a> {
110-
source_file_to_parser(sess, file_to_source_file(sess, path, None))
109+
/// If a span is given, that is used on an error as the as the source of the problem.
110+
pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Option<Span>) -> Parser<'a> {
111+
source_file_to_parser(sess, file_to_source_file(sess, path, sp))
111112
}
112113

113114
/// Creates a new parser, returning buffered diagnostics if the file doesn't exist,
@@ -120,13 +121,6 @@ pub fn maybe_new_parser_from_file<'a>(
120121
maybe_source_file_to_parser(sess, file)
121122
}
122123

123-
/// Given a session, a path, and a span,
124-
/// add the file at the given path to the `source_map`, and returns a parser.
125-
/// On an error, uses the given span as the source of the problem.
126-
pub fn new_sub_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Span) -> Parser<'a> {
127-
source_file_to_parser(sess, file_to_source_file(sess, path, Some(sp)))
128-
}
129-
130124
/// Given a `source_file` and config, returns a parser.
131125
fn source_file_to_parser(sess: &ParseSess, source_file: Lrc<SourceFile>) -> Parser<'_> {
132126
panictry_buffer!(&sess.span_diagnostic, maybe_source_file_to_parser(sess, source_file))

src/test/ui-fulldeps/mod_dir_path_canonicalized.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ fn parse() {
2828

2929
let path = Path::new(file!());
3030
let path = path.canonicalize().unwrap();
31-
let mut parser = new_parser_from_file(&parse_session, &path);
31+
let mut parser = new_parser_from_file(&parse_session, &path, None);
3232
let _ = parser.parse_crate_mod();
3333
}

0 commit comments

Comments
 (0)