Skip to content

Subtree sync #5374

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8211d64
Merge commit '5ff7b632a95bac6955611d85040859128902c580' into sync-rus…
calebcartwright Mar 30, 2022
6c6ebec
Create 2024 edition
jhpratt Feb 28, 2022
11d0bae
span: move `MultiSpan`
davidtwco Mar 24, 2022
6eea2a8
errors: implement fallback diagnostic translation
davidtwco Mar 26, 2022
f8ad4b5
errors: implement sysroot/testing bundle loading
davidtwco Mar 28, 2022
b482bee
session: opt for enabling directionality markers
davidtwco Apr 3, 2022
0cf62ae
errors: lazily load fallback fluent bundle
davidtwco Apr 12, 2022
a11c79b
Rollup merge of #94461 - jhpratt:2024-edition, r=pnkfelix
Dylan-DPC Apr 15, 2022
10954cf
Visit generics inside visit_fn.
cjgillot Nov 19, 2021
e08df2d
Avoid producing `NoDelim` values in `MacArgs::delim()`.
nnethercote Apr 26, 2022
f300792
Make explicit an unreachable `NoDelim` case in `rustfmt`.
nnethercote Apr 26, 2022
70067e3
rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`
petrochenkov Apr 26, 2022
050978b
Fix the rustfmt build
scottmcm Apr 25, 2022
77f0964
Remove some unnecessary invisible delimiter checks.
nnethercote May 11, 2022
8fcf113
Rollup merge of #96543 - nnethercote:rm-make_token_stream-hacks, r=Aa…
JohnTitor May 11, 2022
f77fd90
ast: Introduce some traits to get AST node properties generically
petrochenkov May 1, 2022
b507c60
fix rustfmt
klensy May 18, 2022
86940d2
Fix typo
ydah May 20, 2022
241a6f6
Remove `crate` visibility modifier in libs, tests
jhpratt May 21, 2022
0d27f70
Remove feature: `crate` visibility modifier
jhpratt May 21, 2022
9b697d0
Merge crate and restricted visibilities
jhpratt May 21, 2022
1ac2ac0
Merge remote-tracking branch 'upstream/master' into subtree-sync-2022…
calebcartwright Jun 8, 2022
aedb396
chore: bump toolchain
calebcartwright Jun 8, 2022
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-2022-03-27"
channel = "nightly-2022-06-06"
components = ["rustc-dev"]
2 changes: 1 addition & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Format attributes and meta items.
use rustc_ast::ast;
use rustc_ast::AstLike;
use rustc_ast::HasAttrs;
use rustc_span::{symbol::sym, Span, Symbol};

use self::doc_comment::DocCommentFormatter;
Expand Down
1 change: 1 addition & 0 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
"2015" => Ok(Edition::Edition2015),
"2018" => Ok(Edition::Edition2018),
"2021" => Ok(Edition::Edition2021),
"2024" => Ok(Edition::Edition2024),
_ => Err(format_err!("Invalid value for `--edition`")),
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ pub enum Edition {
#[doc_hint = "2021"]
/// Edition 2021.
Edition2021,
#[value = "2024"]
#[doc_hint = "2024"]
/// Edition 2024.
Edition2024,
}

impl Default for Edition {
Expand All @@ -437,6 +441,7 @@ impl From<Edition> for rustc_span::edition::Edition {
Edition::Edition2015 => Self::Edition2015,
Edition::Edition2018 => Self::Edition2018,
Edition::Edition2021 => Self::Edition2021,
Edition::Edition2024 => Self::Edition2024,
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::min;
use std::collections::HashMap;

use itertools::Itertools;
use rustc_ast::token::{DelimToken, LitKind};
use rustc_ast::token::{Delimiter, LitKind};
use rustc_ast::{ast, ptr};
use rustc_span::{BytePos, Span};

Expand Down Expand Up @@ -274,6 +274,10 @@ fn format_expr_inner(
ast::ExprKind::Ret(Some(ref expr)) => {
rewrite_unary_prefix(context, "return ", &**expr, shape)
}
ast::ExprKind::Yeet(None) => Some("do yeet".to_owned()),
ast::ExprKind::Yeet(Some(ref expr)) => {
rewrite_unary_prefix(context, "do yeet ", &**expr, shape)
}
ast::ExprKind::Box(ref expr) => rewrite_unary_prefix(context, "box ", &**expr, shape),
ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => {
rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape)
Expand Down Expand Up @@ -461,7 +465,7 @@ pub(crate) fn rewrite_array<'a, T: 'a + IntoOverflowableItem<'a>>(
context: &'a RewriteContext<'_>,
shape: Shape,
force_separator_tactic: Option<SeparatorTactic>,
delim_token: Option<DelimToken>,
delim_token: Option<Delimiter>,
) -> Option<String> {
overflow::rewrite_with_square_brackets(
context,
Expand Down Expand Up @@ -1374,7 +1378,7 @@ pub(crate) fn can_be_overflowed_expr(
}
ast::ExprKind::MacCall(ref mac) => {
match (
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim()),
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim().unwrap()),
context.config.overflow_delimited_expr(),
) {
(Some(ast::MacDelimiter::Bracket), true)
Expand Down
1 change: 0 additions & 1 deletion src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::rc::Rc;
use std::time::{Duration, Instant};

use rustc_ast::ast;
use rustc_ast::AstLike;
use rustc_span::Span;

use self::newline_style::apply_newline_style;
Expand Down
15 changes: 10 additions & 5 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,11 @@ impl<'a> FnSig<'a> {

pub(crate) fn from_fn_kind(
fn_kind: &'a visit::FnKind<'_>,
generics: &'a ast::Generics,
decl: &'a ast::FnDecl,
defaultness: ast::Defaultness,
) -> FnSig<'a> {
match *fn_kind {
visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, _) => match fn_ctxt {
visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, generics, _) => match fn_ctxt {
visit::FnCtxt::Assoc(..) => {
let mut fn_sig = FnSig::from_method_sig(fn_sig, generics, vis);
fn_sig.defaultness = defaultness;
Expand Down Expand Up @@ -1362,7 +1361,7 @@ pub(crate) fn format_struct_struct(

fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
match vis.kind {
ast::VisibilityKind::Crate(..) | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
_ => default_span.lo(),
}
}
Expand Down Expand Up @@ -3180,8 +3179,14 @@ impl Rewrite for ast::ForeignItem {
let inner_attrs = inner_attributes(&self.attrs);
let fn_ctxt = visit::FnCtxt::Foreign;
visitor.visit_fn(
visit::FnKind::Fn(fn_ctxt, self.ident, sig, &self.vis, Some(body)),
generics,
visit::FnKind::Fn(
fn_ctxt,
self.ident,
sig,
&self.vis,
generics,
Some(body),
),
&sig.decl,
self.span,
defaultness,
Expand Down
74 changes: 37 additions & 37 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use std::collections::HashMap;
use std::panic::{catch_unwind, AssertUnwindSafe};

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

let style = if is_forced_bracket && !is_nested_macro {
DelimToken::Bracket
Delimiter::Bracket
} else {
original_style
};
Expand All @@ -212,21 +212,21 @@ fn rewrite_macro_inner(
let has_comment = contains_comment(context.snippet(mac.span()));
if ts.is_empty() && !has_comment {
return match style {
DelimToken::Paren if position == MacroPosition::Item => {
Delimiter::Parenthesis if position == MacroPosition::Item => {
Some(format!("{}();", macro_name))
}
DelimToken::Bracket if position == MacroPosition::Item => {
Delimiter::Bracket if position == MacroPosition::Item => {
Some(format!("{}[];", macro_name))
}
DelimToken::Paren => Some(format!("{}()", macro_name)),
DelimToken::Bracket => Some(format!("{}[]", macro_name)),
DelimToken::Brace => Some(format!("{} {{}}", macro_name)),
Delimiter::Parenthesis => Some(format!("{}()", macro_name)),
Delimiter::Bracket => Some(format!("{}[]", macro_name)),
Delimiter::Brace => Some(format!("{} {{}}", macro_name)),
_ => unreachable!(),
};
}
// Format well-known macros which cannot be parsed as a valid AST.
if macro_name == "lazy_static!" && !has_comment {
if let success @ Some(..) = format_lazy_static(context, shape, ts.trees().collect()) {
if let success @ Some(..) = format_lazy_static(context, shape, ts.clone()) {
return success;
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ fn rewrite_macro_inner(
}

match style {
DelimToken::Paren => {
Delimiter::Parenthesis => {
// Handle special case: `vec!(expr; expr)`
if vec_with_semi {
handle_vec_semi(context, shape, arg_vec, macro_name, style)
Expand All @@ -286,7 +286,7 @@ fn rewrite_macro_inner(
})
}
}
DelimToken::Bracket => {
Delimiter::Bracket => {
// Handle special case: `vec![expr; expr]`
if vec_with_semi {
handle_vec_semi(context, shape, arg_vec, macro_name, style)
Expand Down Expand Up @@ -323,7 +323,7 @@ fn rewrite_macro_inner(
Some(format!("{}{}", rewrite, comma))
}
}
DelimToken::Brace => {
Delimiter::Brace => {
// For macro invocations with braces, always put a space between
// the `macro_name!` and `{ /* macro_body */ }` but skip modifying
// anything in between the braces (for now).
Expand All @@ -342,11 +342,11 @@ fn handle_vec_semi(
shape: Shape,
arg_vec: Vec<MacroArg>,
macro_name: String,
delim_token: DelimToken,
delim_token: Delimiter,
) -> Option<String> {
let (left, right) = match delim_token {
DelimToken::Paren => ("(", ")"),
DelimToken::Bracket => ("[", "]"),
Delimiter::Parenthesis => ("(", ")"),
Delimiter::Bracket => ("[", "]"),
_ => unreachable!(),
};

Expand Down Expand Up @@ -528,7 +528,7 @@ enum MacroArgKind {
/// e.g., `$($foo: expr),*`
Repeat(
/// `()`, `[]` or `{}`.
DelimToken,
Delimiter,
/// Inner arguments inside delimiters.
Vec<ParsedMacroArg>,
/// Something after the closing delimiter and the repeat token, if available.
Expand All @@ -537,7 +537,7 @@ enum MacroArgKind {
Token,
),
/// e.g., `[derive(Debug)]`
Delimited(DelimToken, Vec<ParsedMacroArg>),
Delimited(Delimiter, Vec<ParsedMacroArg>),
/// A possible separator. e.g., `,` or `;`.
Separator(String, String),
/// Other random stuff that does not fit to other kinds.
Expand All @@ -547,22 +547,22 @@ enum MacroArgKind {

fn delim_token_to_str(
context: &RewriteContext<'_>,
delim_token: DelimToken,
delim_token: Delimiter,
shape: Shape,
use_multiple_lines: bool,
inner_is_empty: bool,
) -> (String, String) {
let (lhs, rhs) = match delim_token {
DelimToken::Paren => ("(", ")"),
DelimToken::Bracket => ("[", "]"),
DelimToken::Brace => {
Delimiter::Parenthesis => ("(", ")"),
Delimiter::Bracket => ("[", "]"),
Delimiter::Brace => {
if inner_is_empty || use_multiple_lines {
("{", "}")
} else {
("{ ", " }")
}
}
DelimToken::NoDelim => ("", ""),
Delimiter::Invisible => unreachable!(),
};
if use_multiple_lines {
let indent_str = shape.indent.to_string_with_newline(context.config);
Expand All @@ -583,8 +583,8 @@ impl MacroArgKind {
fn starts_with_brace(&self) -> bool {
matches!(
*self,
MacroArgKind::Repeat(DelimToken::Brace, _, _, _)
| MacroArgKind::Delimited(DelimToken::Brace, _)
MacroArgKind::Repeat(Delimiter::Brace, _, _, _)
| MacroArgKind::Delimited(Delimiter::Brace, _)
)
}

Expand Down Expand Up @@ -753,7 +753,7 @@ impl MacroArgParser {
}
}

fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: DelimToken) {
fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: Delimiter) {
self.result.push(ParsedMacroArg {
kind: MacroArgKind::Delimited(delim, inner),
});
Expand All @@ -763,7 +763,7 @@ impl MacroArgParser {
fn add_repeat(
&mut self,
inner: Vec<ParsedMacroArg>,
delim: DelimToken,
delim: Delimiter,
iter: &mut Cursor,
) -> Option<()> {
let mut buffer = String::new();
Expand Down Expand Up @@ -855,7 +855,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.into_trees();

while let Some(tok) = iter.next() {
match tok {
Expand Down Expand Up @@ -1083,18 +1083,18 @@ pub(crate) fn convert_try_mac(
}
}

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

if paren_pos < bracket_pos && paren_pos < brace_pos {
DelimToken::Paren
Delimiter::Parenthesis
} else if bracket_pos < brace_pos {
DelimToken::Bracket
Delimiter::Bracket
} else {
DelimToken::Brace
Delimiter::Brace
}
}

Expand Down Expand Up @@ -1174,7 +1174,7 @@ struct Macro {
// rather than clone them, if we can make the borrowing work out.
struct MacroBranch {
span: Span,
args_paren_kind: DelimToken,
args_paren_kind: Delimiter,
args: TokenStream,
body: Span,
whole_body: Span,
Expand All @@ -1188,7 +1188,7 @@ impl MacroBranch {
multi_branch_style: bool,
) -> Option<String> {
// Only attempt to format function-like macros.
if self.args_paren_kind != DelimToken::Paren {
if self.args_paren_kind != Delimiter::Parenthesis {
// FIXME(#1539): implement for non-sugared macros.
return None;
}
Expand Down Expand Up @@ -1350,18 +1350,18 @@ fn rewrite_macro_with_items(
items: &[MacroArg],
macro_name: &str,
shape: Shape,
style: DelimToken,
style: Delimiter,
position: MacroPosition,
span: Span,
) -> Option<String> {
let (opener, closer) = match style {
DelimToken::Paren => ("(", ")"),
DelimToken::Bracket => ("[", "]"),
DelimToken::Brace => (" {", "}"),
Delimiter::Parenthesis => ("(", ")"),
Delimiter::Bracket => ("[", "]"),
Delimiter::Brace => (" {", "}"),
_ => return None,
};
let trailing_semicolon = match style {
DelimToken::Paren | DelimToken::Bracket if position == MacroPosition::Item => ";",
Delimiter::Parenthesis | Delimiter::Bracket if position == MacroPosition::Item => ";",
_ => "",
};

Expand Down
12 changes: 1 addition & 11 deletions src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::path::{Path, PathBuf};

use rustc_ast::ast;
use rustc_ast::visit::Visitor;
use rustc_ast::AstLike;
use rustc_span::symbol::{self, sym, Symbol};
use rustc_span::Span;
use thiserror::Error;
Expand Down Expand Up @@ -50,19 +49,10 @@ impl<'a> Module<'a> {
ast_mod_kind,
}
}
}

impl<'a> AstLike for Module<'a> {
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = true;
fn attrs(&self) -> &[ast::Attribute] {
pub(crate) fn attrs(&self) -> &[ast::Attribute] {
&self.inner_attr
}
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<ast::Attribute>)) {
f(&mut self.inner_attr)
}
fn tokens_mut(&mut self) -> Option<&mut Option<rustc_ast::tokenstream::LazyTokenStream>> {
unimplemented!()
}
}

/// Maps each module to the corresponding file.
Expand Down
Loading