Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9b0ed57

Browse files
refactor: parse & mod resolver for rustc-ap v650
1 parent bd5dff4 commit 9b0ed57

19 files changed

+309
-243
lines changed

Cargo.lock

Lines changed: 141 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,36 @@ rustc-workspace-hack = "1.0.0"
6565

6666
[dependencies.rustc_ast_pretty]
6767
package = "rustc-ap-rustc_ast_pretty"
68-
version = "647.0.0"
68+
version = "650.0.0"
6969

7070
[dependencies.rustc_data_structures]
7171
package = "rustc-ap-rustc_data_structures"
72-
version = "647.0.0"
72+
version = "650.0.0"
7373

7474
[dependencies.rustc_errors]
7575
package = "rustc-ap-rustc_errors"
76-
version = "647.0.0"
76+
version = "650.0.0"
77+
78+
[dependencies.rustc_expand]
79+
package = "rustc-ap-rustc_expand"
80+
version = "650.0.0"
7781

7882
[dependencies.rustc_parse]
7983
package = "rustc-ap-rustc_parse"
80-
version = "647.0.0"
84+
version = "650.0.0"
8185

8286
[dependencies.rustc_session]
8387
package = "rustc-ap-rustc_session"
84-
version = "647.0.0"
88+
version = "650.0.0"
8589

8690
[dependencies.rustc_span]
8791
package = "rustc-ap-rustc_span"
88-
version = "647.0.0"
92+
version = "650.0.0"
8993

9094
[dependencies.rustc_target]
9195
package = "rustc-ap-rustc_target"
92-
version = "647.0.0"
96+
version = "650.0.0"
9397

9498
[dependencies.syntax]
9599
package = "rustc-ap-rustc_ast"
96-
version = "647.0.0"
100+
version = "650.0.0"

src/attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> Option<&[ast::Attribute]>
2323
ast::StmtKind::Local(ref local) => Some(&local.attrs),
2424
ast::StmtKind::Item(ref item) => Some(&item.attrs),
2525
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => Some(&expr.attrs),
26-
ast::StmtKind::Mac(ref mac) => Some(&mac.2),
26+
ast::StmtKind::MacCall(ref mac) => Some(&mac.2),
2727
ast::StmtKind::Empty => None,
2828
}
2929
}
@@ -33,7 +33,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
3333
ast::StmtKind::Local(ref local) => local.span,
3434
ast::StmtKind::Item(ref item) => item.span,
3535
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span,
36-
ast::StmtKind::Mac(ref mac) => {
36+
ast::StmtKind::MacCall(ref mac) => {
3737
let (ref mac, _, _) = **mac;
3838
mac.span()
3939
}

src/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl Chain {
403403

404404
fn convert_try(expr: &ast::Expr, context: &RewriteContext<'_>) -> ast::Expr {
405405
match expr.kind {
406-
ast::ExprKind::Mac(ref mac) if context.config.use_try_shorthand() => {
406+
ast::ExprKind::MacCall(ref mac) if context.config.use_try_shorthand() => {
407407
if let Some(subexpr) = convert_try_mac(mac, context) {
408408
subexpr
409409
} else {

src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub(crate) fn format_expr(
199199
ast::ExprKind::Try(..) | ast::ExprKind::Field(..) | ast::ExprKind::MethodCall(..) => {
200200
rewrite_chain(expr, context, shape)
201201
}
202-
ast::ExprKind::Mac(ref mac) => {
202+
ast::ExprKind::MacCall(ref mac) => {
203203
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
204204
wrap_str(
205205
context.snippet(expr.span).to_owned(),
@@ -1312,7 +1312,7 @@ pub(crate) fn can_be_overflowed_expr(
13121312
context.config.overflow_delimited_expr()
13131313
|| (context.use_block_indent() && args_len == 1)
13141314
}
1315-
ast::ExprKind::Mac(ref mac) => {
1315+
ast::ExprKind::MacCall(ref mac) => {
13161316
match (
13171317
syntax::ast::MacDelimiter::from_token(mac.args.delim()),
13181318
context.config.overflow_delimited_expr(),
@@ -1340,7 +1340,7 @@ pub(crate) fn can_be_overflowed_expr(
13401340

13411341
pub(crate) fn is_nested_call(expr: &ast::Expr) -> bool {
13421342
match expr.kind {
1343-
ast::ExprKind::Call(..) | ast::ExprKind::Mac(..) => true,
1343+
ast::ExprKind::Call(..) | ast::ExprKind::MacCall(..) => true,
13441344
ast::ExprKind::AddrOf(_, _, ref expr)
13451345
| ast::ExprKind::Box(ref expr)
13461346
| ast::ExprKind::Try(ref expr)

src/formatting.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ fn format_project<T: FormatHandler>(
9191
let files = modules::ModResolver::new(
9292
&context.parse_session,
9393
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod),
94-
!(input_is_stdin || config.skip_children()),
94+
!input_is_stdin && !config.skip_children(),
9595
)
9696
.visit_crate(&krate)
9797
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
98+
9899
for (path, module) in files {
99100
let should_ignore = !input_is_stdin && context.ignore_file(&path);
100101
if (config.skip_children() && path != main_file) || should_ignore {

src/items.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl<'a> FmtVisitor<'a> {
645645
{
646646
a.ident.as_str().cmp(&b.ident.as_str())
647647
}
648-
(Const(..), Const(..)) | (Macro(..), Macro(..)) => {
648+
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
649649
a.ident.as_str().cmp(&b.ident.as_str())
650650
}
651651
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
@@ -655,8 +655,8 @@ impl<'a> FmtVisitor<'a> {
655655
(_, TyAlias(..)) => Ordering::Greater,
656656
(Const(..), _) => Ordering::Less,
657657
(_, Const(..)) => Ordering::Greater,
658-
(Macro(..), _) => Ordering::Less,
659-
(_, Macro(..)) => Ordering::Greater,
658+
(MacCall(..), _) => Ordering::Less,
659+
(_, MacCall(..)) => Ordering::Greater,
660660
});
661661
let mut prev_kind = None;
662662
for (buf, item) in buffer {
@@ -868,10 +868,9 @@ fn format_impl_ref_and_type(
868868
let generics_str = rewrite_generics(context, "impl", generics, shape)?;
869869
result.push_str(&generics_str);
870870

871-
let polarity_str = if polarity == ast::ImplPolarity::Negative {
872-
"!"
873-
} else {
874-
""
871+
let polarity_str = match polarity {
872+
ast::ImplPolarity::Negative(_) => "!",
873+
ast::ImplPolarity::Positive => "",
875874
};
876875

877876
if let Some(ref trait_ref) = *trait_ref {
@@ -1730,7 +1729,7 @@ impl<'a> StaticParts<'a> {
17301729
ty,
17311730
mutability,
17321731
expr_opt: expr.as_ref(),
1733-
defaultness: defaultness,
1732+
defaultness,
17341733
span: item.span,
17351734
}
17361735
}
@@ -3120,7 +3119,7 @@ impl Rewrite for ast::ForeignItem {
31203119
rewrite_ident(context, self.ident)
31213120
))
31223121
}
3123-
ast::ForeignItemKind::Macro(ref mac) => {
3122+
ast::ForeignItemKind::MacCall(ref mac) => {
31243123
rewrite_macro(mac, None, context, shape, MacroPosition::Item)
31253124
}
31263125
}?;

src/macros.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn return_macro_parse_failure_fallback(
187187
}
188188

189189
pub(crate) fn rewrite_macro(
190-
mac: &ast::Mac,
190+
mac: &ast::MacCall,
191191
extra_ident: Option<ast::Ident>,
192192
context: &RewriteContext<'_>,
193193
shape: Shape,
@@ -239,7 +239,7 @@ fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
239239
}
240240

241241
fn rewrite_macro_inner(
242-
mac: &ast::Mac,
242+
mac: &ast::MacCall,
243243
extra_ident: Option<ast::Ident>,
244244
context: &RewriteContext<'_>,
245245
shape: Shape,
@@ -495,7 +495,7 @@ pub(crate) fn rewrite_macro_def(
495495
None => return snippet,
496496
};
497497

498-
let mut result = if def.legacy {
498+
let mut result = if def.macro_rules {
499499
String::from("macro_rules!")
500500
} else {
501501
format!("{}macro", format_visibility(context, vis))
@@ -504,7 +504,7 @@ pub(crate) fn rewrite_macro_def(
504504
result += " ";
505505
result += rewrite_ident(context, ident);
506506

507-
let multi_branch_style = def.legacy || parsed_def.branches.len() != 1;
507+
let multi_branch_style = def.macro_rules || parsed_def.branches.len() != 1;
508508

509509
let arm_shape = if multi_branch_style {
510510
shape
@@ -537,7 +537,7 @@ pub(crate) fn rewrite_macro_def(
537537
.collect::<Vec<_>>();
538538

539539
let fmt = ListFormatting::new(arm_shape, context.config)
540-
.separator(if def.legacy { ";" } else { "" })
540+
.separator(if def.macro_rules { ";" } else { "" })
541541
.trailing_separator(SeparatorTactic::Always)
542542
.preserve_newline(true);
543543

@@ -1186,7 +1186,7 @@ fn next_space(tok: &TokenKind) -> SpaceState {
11861186
/// Tries to convert a macro use into a short hand try expression. Returns `None`
11871187
/// when the macro is not an instance of `try!` (or parsing the inner expression
11881188
/// failed).
1189-
pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> Option<ast::Expr> {
1189+
pub(crate) fn convert_try_mac(mac: &ast::MacCall, context: &RewriteContext<'_>) -> Option<ast::Expr> {
11901190
let path = &pprust::path_to_string(&mac.path);
11911191
if path == "try" || path == "r#try" {
11921192
let ts = mac.args.inner_tokens();
@@ -1203,7 +1203,7 @@ pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> O
12031203
}
12041204
}
12051205

1206-
pub(crate) fn macro_style(mac: &ast::Mac, context: &RewriteContext<'_>) -> DelimToken {
1206+
pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> DelimToken {
12071207
let snippet = context.snippet(mac.span());
12081208
let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::max_value());
12091209
let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::max_value());

src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
559559
| ast::ExprKind::Array(..)
560560
| ast::ExprKind::Call(..)
561561
| ast::ExprKind::MethodCall(..)
562-
| ast::ExprKind::Mac(..)
562+
| ast::ExprKind::MacCall(..)
563563
| ast::ExprKind::Struct(..)
564564
| ast::ExprKind::Tup(..) => true,
565565
ast::ExprKind::AddrOf(_, _, ref expr)

0 commit comments

Comments
 (0)