Skip to content

Commit d97c4fb

Browse files
authored
Merge pull request #6431 from ytmimi/subtree-push-nightly-2025-01-02
subtree-push nightly-2025-01-02
2 parents a43eef1 + 7397eee commit d97c4fb

23 files changed

+186
-144
lines changed

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-12-02"
2+
channel = "nightly-2025-01-02"
33
components = ["llvm-tools", "rustc-dev"]

src/bin/main.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ fn make_opts() -> Options {
135135
"Rust edition to use",
136136
"[2015|2018|2021|2024]",
137137
);
138+
opts.optopt(
139+
"",
140+
"style-edition",
141+
"The edition of the Style Guide (unstable).",
142+
"[2015|2018|2021|2024]",
143+
);
138144
opts.optopt(
139145
"",
140146
"color",
@@ -186,12 +192,6 @@ fn make_opts() -> Options {
186192
"skip-children",
187193
"Don't reformat child modules (unstable).",
188194
);
189-
opts.optopt(
190-
"",
191-
"style-edition",
192-
"The edition of the Style Guide (unstable).",
193-
"[2015|2018|2021|2024]",
194-
);
195195
}
196196

197197
opts.optflag("v", "verbose", "Print verbose output");
@@ -568,10 +568,6 @@ impl GetOptsOptions {
568568
if let Some(ref file_lines) = matches.opt_str("file-lines") {
569569
options.file_lines = file_lines.parse()?;
570570
}
571-
if let Some(ref edition_str) = matches.opt_str("style-edition") {
572-
options.style_edition =
573-
Some(style_edition_from_style_edition_str(edition_str)?);
574-
}
575571
} else {
576572
let mut unstable_options = vec![];
577573
if matches.opt_present("skip-children") {
@@ -583,9 +579,6 @@ impl GetOptsOptions {
583579
if matches.opt_present("file-lines") {
584580
unstable_options.push("`--file-lines`");
585581
}
586-
if matches.opt_present("style-edition") {
587-
unstable_options.push("`--style-edition`");
588-
}
589582
if !unstable_options.is_empty() {
590583
let s = if unstable_options.len() == 1 { "" } else { "s" };
591584
return Err(format_err!(
@@ -635,6 +628,10 @@ impl GetOptsOptions {
635628
options.edition = Some(edition_from_edition_str(edition_str)?);
636629
}
637630

631+
if let Some(ref edition_str) = matches.opt_str("style-edition") {
632+
options.style_edition = Some(style_edition_from_style_edition_str(edition_str)?);
633+
}
634+
638635
if matches.opt_present("backup") {
639636
options.backup = true;
640637
}

src/config/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) mod style_edition;
2929
// This macro defines configuration options used in rustfmt. Each option
3030
// is defined as follows:
3131
//
32-
// `name: value type, default value, is stable, description;`
32+
// `name: value type, is stable, description;`
3333
create_config! {
3434
// Fundamental stuff
3535
max_width: MaxWidth, true, "Maximum width of each line";
@@ -149,7 +149,7 @@ create_config! {
149149
blank_lines_lower_bound: BlankLinesLowerBound, false,
150150
"Minimum number of blank lines which must be put between items";
151151
edition: EditionConfig, true, "The edition of the parser (RFC 2052)";
152-
style_edition: StyleEditionConfig, false, "The edition of the Style Guide (RFC 3338)";
152+
style_edition: StyleEditionConfig, true, "The edition of the Style Guide (RFC 3338)";
153153
version: VersionConfig, false, "Version of formatting rules";
154154
inline_attribute_width: InlineAttributeWidth, false,
155155
"Write an item and its attribute on the same line \

src/config/options.rs

-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ pub enum StyleEdition {
511511
Edition2021,
512512
#[value = "2024"]
513513
#[doc_hint = "2024"]
514-
#[unstable_variant]
515514
/// [Edition 2024]().
516515
Edition2024,
517516
#[value = "2027"]

src/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ pub(crate) fn format_expr(
421421
ast::ExprKind::FormatArgs(..)
422422
| ast::ExprKind::Type(..)
423423
| ast::ExprKind::IncludedBytes(..)
424-
| ast::ExprKind::OffsetOf(..) => {
424+
| ast::ExprKind::OffsetOf(..)
425+
| ast::ExprKind::UnsafeBinderCast(..) => {
425426
// These don't normally occur in the AST because macros aren't expanded. However,
426427
// rustfmt tries to parse macro arguments when formatting macros, so it's not totally
427428
// impossible for rustfmt to come across one of these nodes when formatting a file.

src/items.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,11 @@ pub(crate) fn rewrite_struct_field(
19301930
shape: Shape,
19311931
lhs_max_width: usize,
19321932
) -> RewriteResult {
1933+
// FIXME(default_field_values): Implement formatting.
1934+
if field.default.is_some() {
1935+
return Err(RewriteError::Unknown);
1936+
}
1937+
19331938
if contains_skip(&field.attrs) {
19341939
return Ok(context.snippet(field.span()).to_owned());
19351940
}
@@ -3581,7 +3586,7 @@ pub(crate) fn rewrite_extern_crate(
35813586
pub(crate) fn is_mod_decl(item: &ast::Item) -> bool {
35823587
!matches!(
35833588
item.kind,
3584-
ast::ItemKind::Mod(_, ast::ModKind::Loaded(_, ast::Inline::Yes, _))
3589+
ast::ItemKind::Mod(_, ast::ModKind::Loaded(_, ast::Inline::Yes, _, _))
35853590
)
35863591
}
35873592

src/macros.rs

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

1515
use rustc_ast::token::{BinOpToken, Delimiter, Token, TokenKind};
16-
use rustc_ast::tokenstream::{RefTokenTreeCursor, TokenStream, TokenTree};
16+
use rustc_ast::tokenstream::{TokenStream, TokenStreamIter, TokenTree};
1717
use rustc_ast::{ast, ptr};
1818
use rustc_ast_pretty::pprust;
1919
use rustc_span::{
@@ -441,7 +441,7 @@ pub(crate) fn rewrite_macro_def(
441441
}
442442

443443
let ts = def.body.tokens.clone();
444-
let mut parser = MacroParser::new(ts.trees());
444+
let mut parser = MacroParser::new(ts.iter());
445445
let parsed_def = match parser.parse() {
446446
Some(def) => def,
447447
None => return snippet,
@@ -792,7 +792,7 @@ impl MacroArgParser {
792792
self.buf.clear();
793793
}
794794

795-
fn add_meta_variable(&mut self, iter: &mut RefTokenTreeCursor<'_>) -> Option<()> {
795+
fn add_meta_variable(&mut self, iter: &mut TokenStreamIter<'_>) -> Option<()> {
796796
match iter.next() {
797797
Some(&TokenTree::Token(
798798
Token {
@@ -824,7 +824,7 @@ impl MacroArgParser {
824824
&mut self,
825825
inner: Vec<ParsedMacroArg>,
826826
delim: Delimiter,
827-
iter: &mut RefTokenTreeCursor<'_>,
827+
iter: &mut TokenStreamIter<'_>,
828828
) -> Option<()> {
829829
let mut buffer = String::new();
830830
let mut first = true;
@@ -924,7 +924,7 @@ impl MacroArgParser {
924924

925925
/// Returns a collection of parsed macro def's arguments.
926926
fn parse(mut self, tokens: TokenStream) -> Option<Vec<ParsedMacroArg>> {
927-
let mut iter = tokens.trees();
927+
let mut iter = tokens.iter();
928928

929929
while let Some(tok) = iter.next() {
930930
match tok {
@@ -1061,7 +1061,7 @@ fn format_macro_args(
10611061
}
10621062

10631063
fn span_for_token_stream(token_stream: &TokenStream) -> Option<Span> {
1064-
token_stream.trees().next().map(|tt| tt.span())
1064+
token_stream.iter().next().map(|tt| tt.span())
10651065
}
10661066

10671067
// We should insert a space if the next token is a:
@@ -1177,18 +1177,18 @@ pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> D
11771177
// A very simple parser that just parses a macros 2.0 definition into its branches.
11781178
// Currently we do not attempt to parse any further than that.
11791179
struct MacroParser<'a> {
1180-
toks: RefTokenTreeCursor<'a>,
1180+
iter: TokenStreamIter<'a>,
11811181
}
11821182

11831183
impl<'a> MacroParser<'a> {
1184-
const fn new(toks: RefTokenTreeCursor<'a>) -> Self {
1185-
Self { toks }
1184+
const fn new(iter: TokenStreamIter<'a>) -> Self {
1185+
Self { iter }
11861186
}
11871187

11881188
// (`(` ... `)` `=>` `{` ... `}`)*
11891189
fn parse(&mut self) -> Option<Macro> {
11901190
let mut branches = vec![];
1191-
while self.toks.look_ahead(1).is_some() {
1191+
while self.iter.peek().is_some() {
11921192
branches.push(self.parse_branch()?);
11931193
}
11941194

@@ -1197,13 +1197,13 @@ impl<'a> MacroParser<'a> {
11971197

11981198
// `(` ... `)` `=>` `{` ... `}`
11991199
fn parse_branch(&mut self) -> Option<MacroBranch> {
1200-
let tok = self.toks.next()?;
1200+
let tok = self.iter.next()?;
12011201
let (lo, args_paren_kind) = match tok {
12021202
TokenTree::Token(..) => return None,
12031203
&TokenTree::Delimited(delimited_span, _, d, _) => (delimited_span.open.lo(), d),
12041204
};
12051205
let args = TokenStream::new(vec![tok.clone()]);
1206-
match self.toks.next()? {
1206+
match self.iter.next()? {
12071207
TokenTree::Token(
12081208
Token {
12091209
kind: TokenKind::FatArrow,
@@ -1213,7 +1213,7 @@ impl<'a> MacroParser<'a> {
12131213
) => {}
12141214
_ => return None,
12151215
}
1216-
let (mut hi, body, whole_body) = match self.toks.next()? {
1216+
let (mut hi, body, whole_body) = match self.iter.next()? {
12171217
TokenTree::Token(..) => return None,
12181218
TokenTree::Delimited(delimited_span, ..) => {
12191219
let data = delimited_span.entire().data();
@@ -1235,10 +1235,10 @@ impl<'a> MacroParser<'a> {
12351235
span,
12361236
},
12371237
_,
1238-
)) = self.toks.look_ahead(0)
1238+
)) = self.iter.peek()
12391239
{
12401240
hi = span.hi();
1241-
self.toks.next();
1241+
self.iter.next();
12421242
}
12431243
Some(MacroBranch {
12441244
span: mk_sp(lo, hi),

src/modules.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,11 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> {
316316
self.directory = directory;
317317
}
318318
match (sub_mod.ast_mod_kind, sub_mod.items) {
319-
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
319+
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _, _))), _) => {
320320
self.visit_mod_from_ast(items)
321321
}
322-
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _))), _) | (_, Cow::Owned(items)) => {
323-
self.visit_mod_outside_ast(items)
324-
}
322+
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _, _))), _)
323+
| (_, Cow::Owned(items)) => self.visit_mod_outside_ast(items),
325324
(_, _) => Ok(()),
326325
}
327326
}

src/parse/macros/cfg_if.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind};
22

33
use rustc_ast::ast;
44
use rustc_ast::token::{Delimiter, TokenKind};
5+
use rustc_parse::exp;
56
use rustc_parse::parser::ForceCollect;
67
use rustc_span::symbol::kw;
78

@@ -31,7 +32,7 @@ fn parse_cfg_if_inner<'a>(
3132

3233
while parser.token.kind != TokenKind::Eof {
3334
if process_if_cfg {
34-
if !parser.eat_keyword(kw::If) {
35+
if !parser.eat_keyword(exp!(If)) {
3536
return Err("Expected `if`");
3637
}
3738

@@ -55,7 +56,7 @@ fn parse_cfg_if_inner<'a>(
5556
})?;
5657
}
5758

58-
if !parser.eat(&TokenKind::OpenDelim(Delimiter::Brace)) {
59+
if !parser.eat(exp!(OpenBrace)) {
5960
return Err("Expected an opening brace");
6061
}
6162

@@ -78,15 +79,15 @@ fn parse_cfg_if_inner<'a>(
7879
}
7980
}
8081

81-
if !parser.eat(&TokenKind::CloseDelim(Delimiter::Brace)) {
82+
if !parser.eat(exp!(CloseBrace)) {
8283
return Err("Expected a closing brace");
8384
}
8485

85-
if parser.eat(&TokenKind::Eof) {
86+
if parser.eat(exp!(Eof)) {
8687
break;
8788
}
8889

89-
if !parser.eat_keyword(kw::Else) {
90+
if !parser.eat_keyword(exp!(Else)) {
9091
return Err("Expected `else`");
9192
}
9293

src/parse/macros/lazy_static.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustc_ast::ast;
22
use rustc_ast::ptr::P;
3-
use rustc_ast::token::TokenKind;
3+
use rustc_ast::token;
44
use rustc_ast::tokenstream::TokenStream;
5-
use rustc_span::symbol::{self, kw};
5+
use rustc_parse::exp;
6+
use rustc_span::symbol;
67

78
use crate::rewrite::RewriteContext;
89

@@ -31,19 +32,19 @@ pub(crate) fn parse_lazy_static(
3132
}
3233
}
3334
}
34-
while parser.token.kind != TokenKind::Eof {
35+
while parser.token.kind != token::Eof {
3536
// Parse a `lazy_static!` item.
3637
// FIXME: These `eat_*` calls should be converted to `parse_or` to avoid
3738
// silently formatting malformed lazy-statics.
3839
let vis = parse_or!(parse_visibility, rustc_parse::parser::FollowedByType::No);
39-
let _ = parser.eat_keyword(kw::Static);
40-
let _ = parser.eat_keyword(kw::Ref);
40+
let _ = parser.eat_keyword(exp!(Static));
41+
let _ = parser.eat_keyword(exp!(Ref));
4142
let id = parse_or!(parse_ident);
42-
let _ = parser.eat(&TokenKind::Colon);
43+
let _ = parser.eat(exp!(Colon));
4344
let ty = parse_or!(parse_ty);
44-
let _ = parser.eat(&TokenKind::Eq);
45+
let _ = parser.eat(exp!(Eq));
4546
let expr = parse_or!(parse_expr);
46-
let _ = parser.eat(&TokenKind::Semi);
47+
let _ = parser.eat(exp!(Semi));
4748
result.push((vis, id, ty, expr));
4849
}
4950

0 commit comments

Comments
 (0)