Skip to content

Commit 8f4f53a

Browse files
authored
Rollup merge of rust-lang#70248 - Centril:unroot, r=petrochenkov
parser: simplify & remove unused field r? @petrochenkov
2 parents e31d810 + eaa0ae5 commit 8f4f53a

File tree

6 files changed

+11
-32
lines changed

6 files changed

+11
-32
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, None, 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/mbe/macro_rules.rs

-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ fn generic_extension<'cx>(
259259
}
260260

261261
let mut p = Parser::new(sess, tts, false, None);
262-
p.root_module_name =
263-
cx.current_expansion.module.mod_path.last().map(|id| id.to_string());
264262
p.last_type_ascription = cx.current_expansion.prior_type_ascription;
265263

266264
// Let the context choose how to interpret the result.

src/librustc_expand/module.rs

+3-4
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;
@@ -59,9 +59,8 @@ crate fn parse_external_mod(
5959
*pop_mod_stack = true; // We have pushed, so notify caller.
6060
drop(included_mod_stack);
6161

62-
// Actually parse the external file as amodule.
63-
let mut p0 = new_sub_parser_from_file(sess, &mp.path, Some(id.to_string()), span);
64-
let mut module = p0.parse_mod(&token::Eof)?;
62+
// Actually parse the external file as a module.
63+
let mut module = new_parser_from_file(sess, &mp.path, Some(span)).parse_mod(&token::Eof)?;
6564
module.0.inline = false;
6665
module
6766
};

src/librustc_parse/lib.rs

+5-18
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,20 +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 crate config, a path, and a span, add
124-
/// 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>(
127-
sess: &'a ParseSess,
128-
path: &Path,
129-
module_name: Option<String>,
130-
sp: Span,
131-
) -> Parser<'a> {
132-
let mut p = source_file_to_parser(sess, file_to_source_file(sess, path, Some(sp)));
133-
p.root_module_name = module_name;
134-
p
135-
}
136-
137124
/// Given a `source_file` and config, returns a parser.
138125
fn source_file_to_parser(sess: &ParseSess, source_file: Lrc<SourceFile>) -> Parser<'_> {
139126
panictry_buffer!(&sess.span_diagnostic, maybe_source_file_to_parser(sess, source_file))

src/librustc_parse/parser/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ pub struct Parser<'a> {
8888
/// The previous token.
8989
pub prev_token: Token,
9090
restrictions: Restrictions,
91-
/// Name of the root module this parser originated from. If `None`, then the
92-
/// name is not known. This does not change while the parser is descending
93-
/// into modules, and sub-parsers have new values for this name.
94-
pub root_module_name: Option<String>,
9591
expected_tokens: Vec<TokenType>,
9692
token_cursor: TokenCursor,
9793
desugar_doc_comments: bool,
@@ -350,7 +346,6 @@ impl<'a> Parser<'a> {
350346
token: Token::dummy(),
351347
prev_token: Token::dummy(),
352348
restrictions: Restrictions::empty(),
353-
root_module_name: None,
354349
expected_tokens: Vec::new(),
355350
token_cursor: TokenCursor {
356351
frame: TokenCursorFrame::new(DelimSpan::dummy(), token::NoDelim, &tokens),

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)