Skip to content

Commit 1800d06

Browse files
refactor: switch to new rustc_parse crate
several mods from libsyntax have been split out into separate crates, including the `parse` mod rust-lang/rust#65324
1 parent dc44c57 commit 1800d06

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

rustfmt-core/rustfmt-lib/src/macros.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
use std::collections::HashMap;
1313
use std::panic::{catch_unwind, AssertUnwindSafe};
1414

15+
use rustc_parse::{new_parser_from_tts, parser::Parser};
1516
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, symbol::kw};
16-
use syntax::parse::new_parser_from_tts;
17-
use syntax::parse::parser::Parser;
1817
use syntax::parse::token::{BinOpToken, DelimToken, Token, TokenKind};
1918
use syntax::print::pprust;
2019
use syntax::tokenstream::{Cursor, TokenStream, TokenTree};
2120
use syntax::ThinVec;
22-
use syntax::{ast, parse, ptr};
21+
use syntax::{ast, ptr};
2322

2423
use crate::comment::{
2524
contains_comment, CharClasses, FindUncommented, FullCodeCharKind, LineClasses,
@@ -112,23 +111,23 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
112111

113112
parse_macro_arg!(
114113
Expr,
115-
|parser: &mut parse::parser::Parser<'b>| parser.parse_expr(),
114+
|parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_expr(),
116115
|x: ptr::P<ast::Expr>| Some(x)
117116
);
118117
parse_macro_arg!(
119118
Ty,
120-
|parser: &mut parse::parser::Parser<'b>| parser.parse_ty(),
119+
|parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_ty(),
121120
|x: ptr::P<ast::Ty>| Some(x)
122121
);
123122
parse_macro_arg!(
124123
Pat,
125-
|parser: &mut parse::parser::Parser<'b>| parser.parse_pat(None),
124+
|parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_pat(None),
126125
|x: ptr::P<ast::Pat>| Some(x)
127126
);
128127
// `parse_item` returns `Option<ptr::P<ast::Item>>`.
129128
parse_macro_arg!(
130129
Item,
131-
|parser: &mut parse::parser::Parser<'b>| parser.parse_item(),
130+
|parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_item(),
132131
|x: Option<ptr::P<ast::Item>>| x
133132
);
134133

rustfmt-core/rustfmt-lib/src/syntux/parser.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ use std::borrow::Cow;
22
use std::panic::{catch_unwind, AssertUnwindSafe};
33
use std::path::{Path, PathBuf};
44

5+
use rustc_parse::{new_sub_parser_from_file, parser::Parser as RawParser};
56
use rustc_span::{DUMMY_SP, Span, symbol::kw};
67
use syntax::ast;
78
use syntax::errors::Diagnostic;
8-
use syntax::parse::parser::Parser as RawParser;
99
use syntax::parse::token::{DelimToken, TokenKind};
10-
use syntax::parse::{new_sub_parser_from_file, PResult};
10+
use syntax::parse::PResult;
1111

1212
use crate::syntux::session::ParseSess;
1313
use crate::{Config, Input};
1414

15-
pub(crate) type DirectoryOwnership = syntax::parse::DirectoryOwnership;
16-
pub(crate) type ModulePathSuccess = syntax::parse::parser::ModulePathSuccess;
15+
pub(crate) type DirectoryOwnership = rustc_parse::DirectoryOwnership;
16+
pub(crate) type ModulePathSuccess = rustc_parse::parser::ModulePathSuccess;
1717

1818
#[derive(Clone)]
1919
pub(crate) struct Directory {
@@ -22,8 +22,8 @@ pub(crate) struct Directory {
2222
}
2323

2424
impl<'a> Directory {
25-
fn to_syntax_directory(&'a self) -> syntax::parse::Directory<'a> {
26-
syntax::parse::Directory {
25+
fn to_syntax_directory(&'a self) -> rustc_parse::Directory<'a> {
26+
rustc_parse::Directory {
2727
path: Cow::Borrowed(&self.path),
2828
ownership: self.ownership,
2929
}
@@ -89,23 +89,23 @@ impl<'a> ParserBuilder<'a> {
8989
}
9090

9191
fn parser(
92-
sess: &'a syntax::parse::ParseSess,
92+
sess: &'a syntax::sess::ParseSess,
9393
input: Input,
9494
directory_ownership: Option<DirectoryOwnership>,
95-
) -> Result<syntax::parse::parser::Parser<'a>, Vec<Diagnostic>> {
95+
) -> Result<rustc_parse::parser::Parser<'a>, Vec<Diagnostic>> {
9696
match input {
9797
Input::File(ref file) => Ok(if let Some(directory_ownership) = directory_ownership {
98-
syntax::parse::new_sub_parser_from_file(
98+
rustc_parse::new_sub_parser_from_file(
9999
sess,
100100
file,
101101
directory_ownership,
102102
None,
103103
DUMMY_SP,
104104
)
105105
} else {
106-
syntax::parse::new_parser_from_file(sess, file)
106+
rustc_parse::new_parser_from_file(sess, file)
107107
}),
108-
Input::Text(text) => syntax::parse::maybe_new_parser_from_source_str(
108+
Input::Text(text) => rustc_parse::maybe_new_parser_from_source_str(
109109
sess,
110110
rustc_span::FileName::Custom("stdin".to_owned()),
111111
text,
@@ -130,7 +130,7 @@ pub(crate) enum ParserError {
130130

131131
impl<'a> Parser<'a> {
132132
pub(crate) fn submod_path_from_attr(attrs: &[ast::Attribute], path: &Path) -> Option<PathBuf> {
133-
syntax::parse::parser::Parser::submod_path_from_attr(attrs, path)
133+
rustc_parse::parser::Parser::submod_path_from_attr(attrs, path)
134134
}
135135

136136
// FIXME(topecongiro) Use the method from libsyntax[1] once it become public.
@@ -280,7 +280,7 @@ impl<'a> Parser<'a> {
280280
mac: &'a ast::Mac,
281281
base_dir: &Directory,
282282
) -> Result<Vec<ast::Item>, &'static str> {
283-
let mut parser = syntax::parse::stream_to_parser_with_base_dir(
283+
let mut parser = rustc_parse::stream_to_parser_with_base_dir(
284284
sess.inner(),
285285
mac.tts.clone(),
286286
base_dir.to_syntax_directory(),

rustfmt-core/rustfmt-lib/src/syntux/session.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::{BytePos, source_map::{FilePathMapping, SourceMap}, Span};
77
use syntax::ast;
88
use syntax::errors::emitter::{ColorConfig, Emitter, EmitterWriter};
99
use syntax::errors::{Diagnostic, Handler, Level as DiagnosticLevel};
10-
use syntax::parse::ParseSess as RawParseSess;
10+
use syntax::sess::ParseSess as RawParseSess;
1111

1212
use crate::config::file_lines::LineRange;
1313
use crate::ignore_path::IgnorePathSet;
@@ -141,8 +141,8 @@ impl ParseSess {
141141
id: ast::Ident,
142142
relative: Option<ast::Ident>,
143143
dir_path: &Path,
144-
) -> syntax::parse::parser::ModulePath {
145-
syntax::parse::parser::Parser::default_submod_path(
144+
) -> rustc_parse::parser::ModulePath {
145+
rustc_parse::parser::Parser::default_submod_path(
146146
id,
147147
relative,
148148
dir_path,

0 commit comments

Comments
 (0)