Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtree-push nightly-2025-01-02 #15

Open
wants to merge 21 commits into
base: subtree_push_automation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d3cf411
cover guard patterns in rustfmt
max-niederman Oct 7, 2024
74dceee
Fix rustfmt according to review
Nadrieril Nov 24, 2024
7be9019
Store a single copy of the error registry in DiagCtxt
bjorn3 Nov 9, 2024
8073aab
Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-dead
matthiaskrgr Dec 8, 2024
4e46d2f
Auto merge of #134052 - matthiaskrgr:rollup-puxwqrk, r=matthiaskrgr
bors Dec 9, 2024
6b12b6b
Keep track of parse errors in `mod`s and don't emit resolve errors fo…
estebank Dec 5, 2024
05c9d68
Fix tools
compiler-errors Dec 10, 2024
68a558c
Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk
matthiaskrgr Dec 13, 2024
de1c33c
Change the lookahead in `MacroParser::new`.
nnethercote Dec 11, 2024
46a1d70
Simplify `RefTokenTreeCursor::look_ahead`.
nnethercote Dec 11, 2024
cbec1df
Rename `RefTokenTreeCursor`.
nnethercote Dec 11, 2024
3aadb31
Only have one source of truth for keywords.
nnethercote Dec 13, 2024
aeca2c2
Rollup merge of #134253 - nnethercote:overhaul-keywords, r=petrochenkov
jieyouxu Dec 18, 2024
994b55e
Speed up `Parser::expected_token_types`.
nnethercote Dec 4, 2024
c6a272b
Make sure we don't lose default struct value when formatting struct
compiler-errors Dec 22, 2024
ba8ee71
Stabilize style_edition 2024 in-tree
compiler-errors Dec 30, 2024
105cbf8
Merge remote-tracking branch 'upstream/master' into subtree-push-nigh…
ytmimi Jan 2, 2025
f874199
chore: bump rustfmt toolchain to nightly-2025-01-02
Jan 2, 2025
ab98945
chore: fixes needed for subtree-push
ytmimi Jan 2, 2025
f649c4c
make `style-edition` a stable option on the CLI
ytmimi Jan 2, 2025
7397eee
add `#![feature(unsafe_binders)]` annotation to tests
ytmimi Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-12-02"
channel = "nightly-2025-01-02"
components = ["llvm-tools", "rustc-dev"]
23 changes: 10 additions & 13 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ fn make_opts() -> Options {
"Rust edition to use",
"[2015|2018|2021|2024]",
);
opts.optopt(
"",
"style-edition",
"The edition of the Style Guide (unstable).",
"[2015|2018|2021|2024]",
);
opts.optopt(
"",
"color",
Expand Down Expand Up @@ -186,12 +192,6 @@ fn make_opts() -> Options {
"skip-children",
"Don't reformat child modules (unstable).",
);
opts.optopt(
"",
"style-edition",
"The edition of the Style Guide (unstable).",
"[2015|2018|2021|2024]",
);
}

opts.optflag("v", "verbose", "Print verbose output");
Expand Down Expand Up @@ -568,10 +568,6 @@ impl GetOptsOptions {
if let Some(ref file_lines) = matches.opt_str("file-lines") {
options.file_lines = file_lines.parse()?;
}
if let Some(ref edition_str) = matches.opt_str("style-edition") {
options.style_edition =
Some(style_edition_from_style_edition_str(edition_str)?);
}
} else {
let mut unstable_options = vec![];
if matches.opt_present("skip-children") {
Expand All @@ -583,9 +579,6 @@ impl GetOptsOptions {
if matches.opt_present("file-lines") {
unstable_options.push("`--file-lines`");
}
if matches.opt_present("style-edition") {
unstable_options.push("`--style-edition`");
}
if !unstable_options.is_empty() {
let s = if unstable_options.len() == 1 { "" } else { "s" };
return Err(format_err!(
Expand Down Expand Up @@ -635,6 +628,10 @@ impl GetOptsOptions {
options.edition = Some(edition_from_edition_str(edition_str)?);
}

if let Some(ref edition_str) = matches.opt_str("style-edition") {
options.style_edition = Some(style_edition_from_style_edition_str(edition_str)?);
}

if matches.opt_present("backup") {
options.backup = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) mod style_edition;
// This macro defines configuration options used in rustfmt. Each option
// is defined as follows:
//
// `name: value type, default value, is stable, description;`
// `name: value type, is stable, description;`
create_config! {
// Fundamental stuff
max_width: MaxWidth, true, "Maximum width of each line";
Expand Down Expand Up @@ -149,7 +149,7 @@ create_config! {
blank_lines_lower_bound: BlankLinesLowerBound, false,
"Minimum number of blank lines which must be put between items";
edition: EditionConfig, true, "The edition of the parser (RFC 2052)";
style_edition: StyleEditionConfig, false, "The edition of the Style Guide (RFC 3338)";
style_edition: StyleEditionConfig, true, "The edition of the Style Guide (RFC 3338)";
version: VersionConfig, false, "Version of formatting rules";
inline_attribute_width: InlineAttributeWidth, false,
"Write an item and its attribute on the same line \
Expand Down
1 change: 0 additions & 1 deletion src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ pub enum StyleEdition {
Edition2021,
#[value = "2024"]
#[doc_hint = "2024"]
#[unstable_variant]
/// [Edition 2024]().
Edition2024,
#[value = "2027"]
Expand Down
3 changes: 2 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ pub(crate) fn format_expr(
ast::ExprKind::FormatArgs(..)
| ast::ExprKind::Type(..)
| ast::ExprKind::IncludedBytes(..)
| ast::ExprKind::OffsetOf(..) => {
| ast::ExprKind::OffsetOf(..)
| ast::ExprKind::UnsafeBinderCast(..) => {
// These don't normally occur in the AST because macros aren't expanded. However,
// rustfmt tries to parse macro arguments when formatting macros, so it's not totally
// impossible for rustfmt to come across one of these nodes when formatting a file.
Expand Down
7 changes: 6 additions & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,11 @@ pub(crate) fn rewrite_struct_field(
shape: Shape,
lhs_max_width: usize,
) -> RewriteResult {
// FIXME(default_field_values): Implement formatting.
if field.default.is_some() {
return Err(RewriteError::Unknown);
}

if contains_skip(&field.attrs) {
return Ok(context.snippet(field.span()).to_owned());
}
Expand Down Expand Up @@ -3581,7 +3586,7 @@ pub(crate) fn rewrite_extern_crate(
pub(crate) fn is_mod_decl(item: &ast::Item) -> bool {
!matches!(
item.kind,
ast::ItemKind::Mod(_, ast::ModKind::Loaded(_, ast::Inline::Yes, _))
ast::ItemKind::Mod(_, ast::ModKind::Loaded(_, ast::Inline::Yes, _, _))
)
}

Expand Down
30 changes: 15 additions & 15 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::collections::HashMap;
use std::panic::{AssertUnwindSafe, catch_unwind};

use rustc_ast::token::{BinOpToken, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::{RefTokenTreeCursor, TokenStream, TokenTree};
use rustc_ast::tokenstream::{TokenStream, TokenStreamIter, TokenTree};
use rustc_ast::{ast, ptr};
use rustc_ast_pretty::pprust;
use rustc_span::{
Expand Down Expand Up @@ -441,7 +441,7 @@ pub(crate) fn rewrite_macro_def(
}

let ts = def.body.tokens.clone();
let mut parser = MacroParser::new(ts.trees());
let mut parser = MacroParser::new(ts.iter());
let parsed_def = match parser.parse() {
Some(def) => def,
None => return snippet,
Expand Down Expand Up @@ -792,7 +792,7 @@ impl MacroArgParser {
self.buf.clear();
}

fn add_meta_variable(&mut self, iter: &mut RefTokenTreeCursor<'_>) -> Option<()> {
fn add_meta_variable(&mut self, iter: &mut TokenStreamIter<'_>) -> Option<()> {
match iter.next() {
Some(&TokenTree::Token(
Token {
Expand Down Expand Up @@ -824,7 +824,7 @@ impl MacroArgParser {
&mut self,
inner: Vec<ParsedMacroArg>,
delim: Delimiter,
iter: &mut RefTokenTreeCursor<'_>,
iter: &mut TokenStreamIter<'_>,
) -> Option<()> {
let mut buffer = String::new();
let mut first = true;
Expand Down Expand Up @@ -924,7 +924,7 @@ impl MacroArgParser {

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

while let Some(tok) = iter.next() {
match tok {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ fn format_macro_args(
}

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

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

impl<'a> MacroParser<'a> {
const fn new(toks: RefTokenTreeCursor<'a>) -> Self {
Self { toks }
const fn new(iter: TokenStreamIter<'a>) -> Self {
Self { iter }
}

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

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

// `(` ... `)` `=>` `{` ... `}`
fn parse_branch(&mut self) -> Option<MacroBranch> {
let tok = self.toks.next()?;
let tok = self.iter.next()?;
let (lo, args_paren_kind) = match tok {
TokenTree::Token(..) => return None,
&TokenTree::Delimited(delimited_span, _, d, _) => (delimited_span.open.lo(), d),
};
let args = TokenStream::new(vec![tok.clone()]);
match self.toks.next()? {
match self.iter.next()? {
TokenTree::Token(
Token {
kind: TokenKind::FatArrow,
Expand All @@ -1213,7 +1213,7 @@ impl<'a> MacroParser<'a> {
) => {}
_ => return None,
}
let (mut hi, body, whole_body) = match self.toks.next()? {
let (mut hi, body, whole_body) = match self.iter.next()? {
TokenTree::Token(..) => return None,
TokenTree::Delimited(delimited_span, ..) => {
let data = delimited_span.entire().data();
Expand All @@ -1235,10 +1235,10 @@ impl<'a> MacroParser<'a> {
span,
},
_,
)) = self.toks.look_ahead(0)
)) = self.iter.peek()
{
hi = span.hi();
self.toks.next();
self.iter.next();
}
Some(MacroBranch {
span: mk_sp(lo, hi),
Expand Down
7 changes: 3 additions & 4 deletions src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> {
self.directory = directory;
}
match (sub_mod.ast_mod_kind, sub_mod.items) {
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _, _))), _) => {
self.visit_mod_from_ast(items)
}
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _))), _) | (_, Cow::Owned(items)) => {
self.visit_mod_outside_ast(items)
}
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _, _))), _)
| (_, Cow::Owned(items)) => self.visit_mod_outside_ast(items),
(_, _) => Ok(()),
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/parse/macros/cfg_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind};

use rustc_ast::ast;
use rustc_ast::token::{Delimiter, TokenKind};
use rustc_parse::exp;
use rustc_parse::parser::ForceCollect;
use rustc_span::symbol::kw;

Expand Down Expand Up @@ -31,7 +32,7 @@ fn parse_cfg_if_inner<'a>(

while parser.token.kind != TokenKind::Eof {
if process_if_cfg {
if !parser.eat_keyword(kw::If) {
if !parser.eat_keyword(exp!(If)) {
return Err("Expected `if`");
}

Expand All @@ -55,7 +56,7 @@ fn parse_cfg_if_inner<'a>(
})?;
}

if !parser.eat(&TokenKind::OpenDelim(Delimiter::Brace)) {
if !parser.eat(exp!(OpenBrace)) {
return Err("Expected an opening brace");
}

Expand All @@ -78,15 +79,15 @@ fn parse_cfg_if_inner<'a>(
}
}

if !parser.eat(&TokenKind::CloseDelim(Delimiter::Brace)) {
if !parser.eat(exp!(CloseBrace)) {
return Err("Expected a closing brace");
}

if parser.eat(&TokenKind::Eof) {
if parser.eat(exp!(Eof)) {
break;
}

if !parser.eat_keyword(kw::Else) {
if !parser.eat_keyword(exp!(Else)) {
return Err("Expected `else`");
}

Expand Down
17 changes: 9 additions & 8 deletions src/parse/macros/lazy_static.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use rustc_ast::ast;
use rustc_ast::ptr::P;
use rustc_ast::token::TokenKind;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_span::symbol::{self, kw};
use rustc_parse::exp;
use rustc_span::symbol;

use crate::rewrite::RewriteContext;

Expand Down Expand Up @@ -31,19 +32,19 @@ pub(crate) fn parse_lazy_static(
}
}
}
while parser.token.kind != TokenKind::Eof {
while parser.token.kind != token::Eof {
// Parse a `lazy_static!` item.
// FIXME: These `eat_*` calls should be converted to `parse_or` to avoid
// silently formatting malformed lazy-statics.
let vis = parse_or!(parse_visibility, rustc_parse::parser::FollowedByType::No);
let _ = parser.eat_keyword(kw::Static);
let _ = parser.eat_keyword(kw::Ref);
let _ = parser.eat_keyword(exp!(Static));
let _ = parser.eat_keyword(exp!(Ref));
let id = parse_or!(parse_ident);
let _ = parser.eat(&TokenKind::Colon);
let _ = parser.eat(exp!(Colon));
let ty = parse_or!(parse_ty);
let _ = parser.eat(&TokenKind::Eq);
let _ = parser.eat(exp!(Eq));
let expr = parse_or!(parse_expr);
let _ = parser.eat(&TokenKind::Semi);
let _ = parser.eat(exp!(Semi));
result.push((vis, id, ty, expr));
}

Expand Down
Loading
Loading