Skip to content

Commit 75786fb

Browse files
Merge pull request #5374 from calebcartwright/subtree-sync-2022-06-07
Subtree sync
2 parents 64f1f57 + aedb396 commit 75786fb

21 files changed

+122
-126
lines changed

Diff for: rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-03-27"
2+
channel = "nightly-2022-06-06"
33
components = ["rustc-dev"]

Diff for: src/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Format attributes and meta items.
22
33
use rustc_ast::ast;
4-
use rustc_ast::AstLike;
4+
use rustc_ast::HasAttrs;
55
use rustc_span::{symbol::sym, Span, Symbol};
66

77
use self::doc_comment::DocCommentFormatter;

Diff for: src/bin/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
693693
"2015" => Ok(Edition::Edition2015),
694694
"2018" => Ok(Edition::Edition2018),
695695
"2021" => Ok(Edition::Edition2021),
696+
"2024" => Ok(Edition::Edition2024),
696697
_ => Err(format_err!("Invalid value for `--edition`")),
697698
}
698699
}

Diff for: src/config/options.rs

+5
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ pub enum Edition {
423423
#[doc_hint = "2021"]
424424
/// Edition 2021.
425425
Edition2021,
426+
#[value = "2024"]
427+
#[doc_hint = "2024"]
428+
/// Edition 2024.
429+
Edition2024,
426430
}
427431

428432
impl Default for Edition {
@@ -437,6 +441,7 @@ impl From<Edition> for rustc_span::edition::Edition {
437441
Edition::Edition2015 => Self::Edition2015,
438442
Edition::Edition2018 => Self::Edition2018,
439443
Edition::Edition2021 => Self::Edition2021,
444+
Edition::Edition2024 => Self::Edition2024,
440445
}
441446
}
442447
}

Diff for: src/expr.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp::min;
33
use std::collections::HashMap;
44

55
use itertools::Itertools;
6-
use rustc_ast::token::{DelimToken, LitKind};
6+
use rustc_ast::token::{Delimiter, LitKind};
77
use rustc_ast::{ast, ptr};
88
use rustc_span::{BytePos, Span};
99

@@ -274,6 +274,10 @@ fn format_expr_inner(
274274
ast::ExprKind::Ret(Some(ref expr)) => {
275275
rewrite_unary_prefix(context, "return ", &**expr, shape)
276276
}
277+
ast::ExprKind::Yeet(None) => Some("do yeet".to_owned()),
278+
ast::ExprKind::Yeet(Some(ref expr)) => {
279+
rewrite_unary_prefix(context, "do yeet ", &**expr, shape)
280+
}
277281
ast::ExprKind::Box(ref expr) => rewrite_unary_prefix(context, "box ", &**expr, shape),
278282
ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => {
279283
rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape)
@@ -461,7 +465,7 @@ pub(crate) fn rewrite_array<'a, T: 'a + IntoOverflowableItem<'a>>(
461465
context: &'a RewriteContext<'_>,
462466
shape: Shape,
463467
force_separator_tactic: Option<SeparatorTactic>,
464-
delim_token: Option<DelimToken>,
468+
delim_token: Option<Delimiter>,
465469
) -> Option<String> {
466470
overflow::rewrite_with_square_brackets(
467471
context,
@@ -1374,7 +1378,7 @@ pub(crate) fn can_be_overflowed_expr(
13741378
}
13751379
ast::ExprKind::MacCall(ref mac) => {
13761380
match (
1377-
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim()),
1381+
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim().unwrap()),
13781382
context.config.overflow_delimited_expr(),
13791383
) {
13801384
(Some(ast::MacDelimiter::Bracket), true)

Diff for: src/formatting.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::rc::Rc;
66
use std::time::{Duration, Instant};
77

88
use rustc_ast::ast;
9-
use rustc_ast::AstLike;
109
use rustc_span::Span;
1110

1211
use self::newline_style::apply_newline_style;

Diff for: src/items.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,11 @@ impl<'a> FnSig<'a> {
204204

205205
pub(crate) fn from_fn_kind(
206206
fn_kind: &'a visit::FnKind<'_>,
207-
generics: &'a ast::Generics,
208207
decl: &'a ast::FnDecl,
209208
defaultness: ast::Defaultness,
210209
) -> FnSig<'a> {
211210
match *fn_kind {
212-
visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, _) => match fn_ctxt {
211+
visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, generics, _) => match fn_ctxt {
213212
visit::FnCtxt::Assoc(..) => {
214213
let mut fn_sig = FnSig::from_method_sig(fn_sig, generics, vis);
215214
fn_sig.defaultness = defaultness;
@@ -1362,7 +1361,7 @@ pub(crate) fn format_struct_struct(
13621361

13631362
fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
13641363
match vis.kind {
1365-
ast::VisibilityKind::Crate(..) | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
1364+
ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
13661365
_ => default_span.lo(),
13671366
}
13681367
}
@@ -3180,8 +3179,14 @@ impl Rewrite for ast::ForeignItem {
31803179
let inner_attrs = inner_attributes(&self.attrs);
31813180
let fn_ctxt = visit::FnCtxt::Foreign;
31823181
visitor.visit_fn(
3183-
visit::FnKind::Fn(fn_ctxt, self.ident, sig, &self.vis, Some(body)),
3184-
generics,
3182+
visit::FnKind::Fn(
3183+
fn_ctxt,
3184+
self.ident,
3185+
sig,
3186+
&self.vis,
3187+
generics,
3188+
Some(body),
3189+
),
31853190
&sig.decl,
31863191
self.span,
31873192
defaultness,

Diff for: src/macros.rs

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

15-
use rustc_ast::token::{BinOpToken, DelimToken, Token, TokenKind};
15+
use rustc_ast::token::{BinOpToken, Delimiter, Token, TokenKind};
1616
use rustc_ast::tokenstream::{Cursor, Spacing, TokenStream, TokenTree};
1717
use rustc_ast::{ast, ptr};
1818
use rustc_ast_pretty::pprust;
@@ -203,7 +203,7 @@ fn rewrite_macro_inner(
203203
let is_forced_bracket = FORCED_BRACKET_MACROS.contains(&&macro_name[..]);
204204

205205
let style = if is_forced_bracket && !is_nested_macro {
206-
DelimToken::Bracket
206+
Delimiter::Bracket
207207
} else {
208208
original_style
209209
};
@@ -212,21 +212,21 @@ fn rewrite_macro_inner(
212212
let has_comment = contains_comment(context.snippet(mac.span()));
213213
if ts.is_empty() && !has_comment {
214214
return match style {
215-
DelimToken::Paren if position == MacroPosition::Item => {
215+
Delimiter::Parenthesis if position == MacroPosition::Item => {
216216
Some(format!("{}();", macro_name))
217217
}
218-
DelimToken::Bracket if position == MacroPosition::Item => {
218+
Delimiter::Bracket if position == MacroPosition::Item => {
219219
Some(format!("{}[];", macro_name))
220220
}
221-
DelimToken::Paren => Some(format!("{}()", macro_name)),
222-
DelimToken::Bracket => Some(format!("{}[]", macro_name)),
223-
DelimToken::Brace => Some(format!("{} {{}}", macro_name)),
221+
Delimiter::Parenthesis => Some(format!("{}()", macro_name)),
222+
Delimiter::Bracket => Some(format!("{}[]", macro_name)),
223+
Delimiter::Brace => Some(format!("{} {{}}", macro_name)),
224224
_ => unreachable!(),
225225
};
226226
}
227227
// Format well-known macros which cannot be parsed as a valid AST.
228228
if macro_name == "lazy_static!" && !has_comment {
229-
if let success @ Some(..) = format_lazy_static(context, shape, ts.trees().collect()) {
229+
if let success @ Some(..) = format_lazy_static(context, shape, ts.clone()) {
230230
return success;
231231
}
232232
}
@@ -260,7 +260,7 @@ fn rewrite_macro_inner(
260260
}
261261

262262
match style {
263-
DelimToken::Paren => {
263+
Delimiter::Parenthesis => {
264264
// Handle special case: `vec!(expr; expr)`
265265
if vec_with_semi {
266266
handle_vec_semi(context, shape, arg_vec, macro_name, style)
@@ -286,7 +286,7 @@ fn rewrite_macro_inner(
286286
})
287287
}
288288
}
289-
DelimToken::Bracket => {
289+
Delimiter::Bracket => {
290290
// Handle special case: `vec![expr; expr]`
291291
if vec_with_semi {
292292
handle_vec_semi(context, shape, arg_vec, macro_name, style)
@@ -323,7 +323,7 @@ fn rewrite_macro_inner(
323323
Some(format!("{}{}", rewrite, comma))
324324
}
325325
}
326-
DelimToken::Brace => {
326+
Delimiter::Brace => {
327327
// For macro invocations with braces, always put a space between
328328
// the `macro_name!` and `{ /* macro_body */ }` but skip modifying
329329
// anything in between the braces (for now).
@@ -342,11 +342,11 @@ fn handle_vec_semi(
342342
shape: Shape,
343343
arg_vec: Vec<MacroArg>,
344344
macro_name: String,
345-
delim_token: DelimToken,
345+
delim_token: Delimiter,
346346
) -> Option<String> {
347347
let (left, right) = match delim_token {
348-
DelimToken::Paren => ("(", ")"),
349-
DelimToken::Bracket => ("[", "]"),
348+
Delimiter::Parenthesis => ("(", ")"),
349+
Delimiter::Bracket => ("[", "]"),
350350
_ => unreachable!(),
351351
};
352352

@@ -528,7 +528,7 @@ enum MacroArgKind {
528528
/// e.g., `$($foo: expr),*`
529529
Repeat(
530530
/// `()`, `[]` or `{}`.
531-
DelimToken,
531+
Delimiter,
532532
/// Inner arguments inside delimiters.
533533
Vec<ParsedMacroArg>,
534534
/// Something after the closing delimiter and the repeat token, if available.
@@ -537,7 +537,7 @@ enum MacroArgKind {
537537
Token,
538538
),
539539
/// e.g., `[derive(Debug)]`
540-
Delimited(DelimToken, Vec<ParsedMacroArg>),
540+
Delimited(Delimiter, Vec<ParsedMacroArg>),
541541
/// A possible separator. e.g., `,` or `;`.
542542
Separator(String, String),
543543
/// Other random stuff that does not fit to other kinds.
@@ -547,22 +547,22 @@ enum MacroArgKind {
547547

548548
fn delim_token_to_str(
549549
context: &RewriteContext<'_>,
550-
delim_token: DelimToken,
550+
delim_token: Delimiter,
551551
shape: Shape,
552552
use_multiple_lines: bool,
553553
inner_is_empty: bool,
554554
) -> (String, String) {
555555
let (lhs, rhs) = match delim_token {
556-
DelimToken::Paren => ("(", ")"),
557-
DelimToken::Bracket => ("[", "]"),
558-
DelimToken::Brace => {
556+
Delimiter::Parenthesis => ("(", ")"),
557+
Delimiter::Bracket => ("[", "]"),
558+
Delimiter::Brace => {
559559
if inner_is_empty || use_multiple_lines {
560560
("{", "}")
561561
} else {
562562
("{ ", " }")
563563
}
564564
}
565-
DelimToken::NoDelim => ("", ""),
565+
Delimiter::Invisible => unreachable!(),
566566
};
567567
if use_multiple_lines {
568568
let indent_str = shape.indent.to_string_with_newline(context.config);
@@ -583,8 +583,8 @@ impl MacroArgKind {
583583
fn starts_with_brace(&self) -> bool {
584584
matches!(
585585
*self,
586-
MacroArgKind::Repeat(DelimToken::Brace, _, _, _)
587-
| MacroArgKind::Delimited(DelimToken::Brace, _)
586+
MacroArgKind::Repeat(Delimiter::Brace, _, _, _)
587+
| MacroArgKind::Delimited(Delimiter::Brace, _)
588588
)
589589
}
590590

@@ -753,7 +753,7 @@ impl MacroArgParser {
753753
}
754754
}
755755

756-
fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: DelimToken) {
756+
fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: Delimiter) {
757757
self.result.push(ParsedMacroArg {
758758
kind: MacroArgKind::Delimited(delim, inner),
759759
});
@@ -763,7 +763,7 @@ impl MacroArgParser {
763763
fn add_repeat(
764764
&mut self,
765765
inner: Vec<ParsedMacroArg>,
766-
delim: DelimToken,
766+
delim: Delimiter,
767767
iter: &mut Cursor,
768768
) -> Option<()> {
769769
let mut buffer = String::new();
@@ -855,7 +855,7 @@ impl MacroArgParser {
855855

856856
/// Returns a collection of parsed macro def's arguments.
857857
fn parse(mut self, tokens: TokenStream) -> Option<Vec<ParsedMacroArg>> {
858-
let mut iter = tokens.trees();
858+
let mut iter = tokens.into_trees();
859859

860860
while let Some(tok) = iter.next() {
861861
match tok {
@@ -1083,18 +1083,18 @@ pub(crate) fn convert_try_mac(
10831083
}
10841084
}
10851085

1086-
pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> DelimToken {
1086+
pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> Delimiter {
10871087
let snippet = context.snippet(mac.span());
10881088
let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::max_value());
10891089
let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::max_value());
10901090
let brace_pos = snippet.find_uncommented("{").unwrap_or(usize::max_value());
10911091

10921092
if paren_pos < bracket_pos && paren_pos < brace_pos {
1093-
DelimToken::Paren
1093+
Delimiter::Parenthesis
10941094
} else if bracket_pos < brace_pos {
1095-
DelimToken::Bracket
1095+
Delimiter::Bracket
10961096
} else {
1097-
DelimToken::Brace
1097+
Delimiter::Brace
10981098
}
10991099
}
11001100

@@ -1174,7 +1174,7 @@ struct Macro {
11741174
// rather than clone them, if we can make the borrowing work out.
11751175
struct MacroBranch {
11761176
span: Span,
1177-
args_paren_kind: DelimToken,
1177+
args_paren_kind: Delimiter,
11781178
args: TokenStream,
11791179
body: Span,
11801180
whole_body: Span,
@@ -1188,7 +1188,7 @@ impl MacroBranch {
11881188
multi_branch_style: bool,
11891189
) -> Option<String> {
11901190
// Only attempt to format function-like macros.
1191-
if self.args_paren_kind != DelimToken::Paren {
1191+
if self.args_paren_kind != Delimiter::Parenthesis {
11921192
// FIXME(#1539): implement for non-sugared macros.
11931193
return None;
11941194
}
@@ -1350,18 +1350,18 @@ fn rewrite_macro_with_items(
13501350
items: &[MacroArg],
13511351
macro_name: &str,
13521352
shape: Shape,
1353-
style: DelimToken,
1353+
style: Delimiter,
13541354
position: MacroPosition,
13551355
span: Span,
13561356
) -> Option<String> {
13571357
let (opener, closer) = match style {
1358-
DelimToken::Paren => ("(", ")"),
1359-
DelimToken::Bracket => ("[", "]"),
1360-
DelimToken::Brace => (" {", "}"),
1358+
Delimiter::Parenthesis => ("(", ")"),
1359+
Delimiter::Bracket => ("[", "]"),
1360+
Delimiter::Brace => (" {", "}"),
13611361
_ => return None,
13621362
};
13631363
let trailing_semicolon = match style {
1364-
DelimToken::Paren | DelimToken::Bracket if position == MacroPosition::Item => ";",
1364+
Delimiter::Parenthesis | Delimiter::Bracket if position == MacroPosition::Item => ";",
13651365
_ => "",
13661366
};
13671367

Diff for: src/modules.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::path::{Path, PathBuf};
44

55
use rustc_ast::ast;
66
use rustc_ast::visit::Visitor;
7-
use rustc_ast::AstLike;
87
use rustc_span::symbol::{self, sym, Symbol};
98
use rustc_span::Span;
109
use thiserror::Error;
@@ -50,19 +49,10 @@ impl<'a> Module<'a> {
5049
ast_mod_kind,
5150
}
5251
}
53-
}
5452

55-
impl<'a> AstLike for Module<'a> {
56-
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = true;
57-
fn attrs(&self) -> &[ast::Attribute] {
53+
pub(crate) fn attrs(&self) -> &[ast::Attribute] {
5854
&self.inner_attr
5955
}
60-
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<ast::Attribute>)) {
61-
f(&mut self.inner_attr)
62-
}
63-
fn tokens_mut(&mut self) -> Option<&mut Option<rustc_ast::tokenstream::LazyTokenStream>> {
64-
unimplemented!()
65-
}
6656
}
6757

6858
/// Maps each module to the corresponding file.

0 commit comments

Comments
 (0)