Merge pull request #5374 from calebcartwright/subtree-sync-2022-06-07
Subtree sync
This commit is contained in:
commit
75786fb0b7
21 changed files with 122 additions and 126 deletions
|
|
@ -1,3 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2022-03-27"
|
||||
channel = "nightly-2022-06-06"
|
||||
components = ["rustc-dev"]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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`")),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/expr.rs
10
src/expr.rs
|
|
@ -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};
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
@ -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,
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
15
src/items.rs
15
src/items.rs
|
|
@ -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;
|
||||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -203,7 +203,7 @@ fn rewrite_macro_inner(
|
|||
let is_forced_bracket = FORCED_BRACKET_MACROS.contains(&¯o_name[..]);
|
||||
|
||||
let style = if is_forced_bracket && !is_nested_macro {
|
||||
DelimToken::Bracket
|
||||
Delimiter::Bracket
|
||||
} else {
|
||||
original_style
|
||||
};
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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).
|
||||
|
|
@ -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!(),
|
||||
};
|
||||
|
||||
|
|
@ -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.
|
||||
|
|
@ -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.
|
||||
|
|
@ -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);
|
||||
|
|
@ -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, _)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -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),
|
||||
});
|
||||
|
|
@ -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();
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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,
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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 => ";",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
use std::cmp::min;
|
||||
|
||||
use itertools::Itertools;
|
||||
use rustc_ast::token::DelimToken;
|
||||
use rustc_ast::token::Delimiter;
|
||||
use rustc_ast::{ast, ptr};
|
||||
use rustc_span::Span;
|
||||
|
||||
|
|
@ -297,11 +297,11 @@ pub(crate) fn rewrite_with_square_brackets<'a, T: 'a + IntoOverflowableItem<'a>>
|
|||
shape: Shape,
|
||||
span: Span,
|
||||
force_separator_tactic: Option<SeparatorTactic>,
|
||||
delim_token: Option<DelimToken>,
|
||||
delim_token: Option<Delimiter>,
|
||||
) -> Option<String> {
|
||||
let (lhs, rhs) = match delim_token {
|
||||
Some(DelimToken::Paren) => ("(", ")"),
|
||||
Some(DelimToken::Brace) => ("{", "}"),
|
||||
Some(Delimiter::Parenthesis) => ("(", ")"),
|
||||
Some(Delimiter::Brace) => ("{", "}"),
|
||||
_ => ("[", "]"),
|
||||
};
|
||||
Context::new(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
|
||||
use rustc_ast::ast;
|
||||
use rustc_ast::token::{DelimToken, TokenKind};
|
||||
use rustc_ast::token::{Delimiter, TokenKind};
|
||||
use rustc_parse::parser::ForceCollect;
|
||||
use rustc_span::symbol::kw;
|
||||
|
||||
|
|
@ -47,11 +47,11 @@ fn parse_cfg_if_inner<'a>(
|
|||
.map_err(|_| "Failed to parse attributes")?;
|
||||
}
|
||||
|
||||
if !parser.eat(&TokenKind::OpenDelim(DelimToken::Brace)) {
|
||||
if !parser.eat(&TokenKind::OpenDelim(Delimiter::Brace)) {
|
||||
return Err("Expected an opening brace");
|
||||
}
|
||||
|
||||
while parser.token != TokenKind::CloseDelim(DelimToken::Brace)
|
||||
while parser.token != TokenKind::CloseDelim(Delimiter::Brace)
|
||||
&& parser.token.kind != TokenKind::Eof
|
||||
{
|
||||
let item = match parser.parse_item(ForceCollect::No) {
|
||||
|
|
@ -70,7 +70,7 @@ fn parse_cfg_if_inner<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
if !parser.eat(&TokenKind::CloseDelim(DelimToken::Brace)) {
|
||||
if !parser.eat(&TokenKind::CloseDelim(Delimiter::Brace)) {
|
||||
return Err("Expected a closing brace");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use rustc_ast::token::{DelimToken, TokenKind};
|
||||
use rustc_ast::token::{Delimiter, TokenKind};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{ast, ptr};
|
||||
use rustc_parse::parser::{ForceCollect, Parser};
|
||||
|
|
@ -79,9 +79,7 @@ fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
|
|||
for &keyword in RUST_KW.iter() {
|
||||
if parser.token.is_keyword(keyword)
|
||||
&& parser.look_ahead(1, |t| {
|
||||
t.kind == TokenKind::Eof
|
||||
|| t.kind == TokenKind::Comma
|
||||
|| t.kind == TokenKind::CloseDelim(DelimToken::NoDelim)
|
||||
t.kind == TokenKind::Eof || t.kind == TokenKind::Comma
|
||||
})
|
||||
{
|
||||
parser.bump();
|
||||
|
|
@ -97,7 +95,7 @@ fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
|
|||
pub(crate) fn parse_macro_args(
|
||||
context: &RewriteContext<'_>,
|
||||
tokens: TokenStream,
|
||||
style: DelimToken,
|
||||
style: Delimiter,
|
||||
forced_bracket: bool,
|
||||
) -> Option<ParsedMacroArgs> {
|
||||
let mut parser = build_parser(context, tokens);
|
||||
|
|
@ -105,7 +103,7 @@ pub(crate) fn parse_macro_args(
|
|||
let mut vec_with_semi = false;
|
||||
let mut trailing_comma = false;
|
||||
|
||||
if DelimToken::Brace != style {
|
||||
if Delimiter::Brace != style {
|
||||
loop {
|
||||
if let Some(arg) = check_keyword(&mut parser) {
|
||||
args.push(arg);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,12 @@ impl Emitter for SilentEmitter {
|
|||
None
|
||||
}
|
||||
fn emit_diagnostic(&mut self, _db: &Diagnostic) {}
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
None
|
||||
}
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
panic!("silent emitter attempted to translate a diagnostic");
|
||||
}
|
||||
}
|
||||
|
||||
fn silent_emitter() -> Box<dyn Emitter + Send> {
|
||||
|
|
@ -82,6 +88,14 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
|
|||
}
|
||||
self.handle_non_ignoreable_error(db);
|
||||
}
|
||||
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
self.emitter.fluent_bundle()
|
||||
}
|
||||
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
self.emitter.fallback_fluent_bundle()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_handler(
|
||||
|
|
@ -100,9 +114,13 @@ fn default_handler(
|
|||
let emitter = if hide_parse_errors {
|
||||
silent_emitter()
|
||||
} else {
|
||||
let fallback_bundle =
|
||||
rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false);
|
||||
Box::new(EmitterWriter::stderr(
|
||||
color_cfg,
|
||||
Some(source_map.clone()),
|
||||
None,
|
||||
fallback_bundle,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
|
|
@ -313,7 +331,8 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::config::IgnoreList;
|
||||
use crate::utils::mk_sp;
|
||||
use rustc_span::{FileName as SourceMapFileName, MultiSpan, RealFileName};
|
||||
use rustc_errors::MultiSpan;
|
||||
use rustc_span::{FileName as SourceMapFileName, RealFileName};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::AtomicU32;
|
||||
|
||||
|
|
@ -328,6 +347,12 @@ mod tests {
|
|||
fn emit_diagnostic(&mut self, _db: &Diagnostic) {
|
||||
self.num_emitted_errors.fetch_add(1, Ordering::Release);
|
||||
}
|
||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
||||
None
|
||||
}
|
||||
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
|
||||
panic!("test emitter attempted to translate a diagnostic");
|
||||
}
|
||||
}
|
||||
|
||||
fn build_diagnostic(level: DiagnosticLevel, span: Option<MultiSpan>) -> Diagnostic {
|
||||
|
|
|
|||
17
src/utils.rs
17
src/utils.rs
|
|
@ -1,7 +1,7 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use rustc_ast::ast::{
|
||||
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
||||
self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
||||
VisibilityKind,
|
||||
};
|
||||
use rustc_ast::ptr;
|
||||
|
|
@ -44,15 +44,7 @@ pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
|
|||
VisibilityKind::Restricted { path: q, .. },
|
||||
) => pprust::path_to_string(p) == pprust::path_to_string(q),
|
||||
(VisibilityKind::Public, VisibilityKind::Public)
|
||||
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
|
||||
| (
|
||||
VisibilityKind::Crate(CrateSugar::PubCrate),
|
||||
VisibilityKind::Crate(CrateSugar::PubCrate),
|
||||
)
|
||||
| (
|
||||
VisibilityKind::Crate(CrateSugar::JustCrate),
|
||||
VisibilityKind::Crate(CrateSugar::JustCrate),
|
||||
) => true,
|
||||
| (VisibilityKind::Inherited, VisibilityKind::Inherited) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -65,8 +57,6 @@ pub(crate) fn format_visibility(
|
|||
match vis.kind {
|
||||
VisibilityKind::Public => Cow::from("pub "),
|
||||
VisibilityKind::Inherited => Cow::from(""),
|
||||
VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
|
||||
VisibilityKind::Crate(CrateSugar::JustCrate) => Cow::from("crate "),
|
||||
VisibilityKind::Restricted { ref path, .. } => {
|
||||
let Path { ref segments, .. } = **path;
|
||||
let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));
|
||||
|
|
@ -75,7 +65,7 @@ pub(crate) fn format_visibility(
|
|||
.next()
|
||||
.expect("Non-global path in pub(restricted)?");
|
||||
}
|
||||
let is_keyword = |s: &str| s == "self" || s == "super";
|
||||
let is_keyword = |s: &str| s == "crate" || s == "self" || s == "super";
|
||||
let path = segments_iter.collect::<Vec<_>>().join("::");
|
||||
let in_str = if is_keyword(&path) { "" } else { "in " };
|
||||
|
||||
|
|
@ -512,6 +502,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
|
|||
| ast::ExprKind::Range(..)
|
||||
| ast::ExprKind::Repeat(..)
|
||||
| ast::ExprKind::Ret(..)
|
||||
| ast::ExprKind::Yeet(..)
|
||||
| ast::ExprKind::Tup(..)
|
||||
| ast::ExprKind::Type(..)
|
||||
| ast::ExprKind::Yield(None)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustc_ast::{ast, token::DelimToken, visit, AstLike};
|
||||
use rustc_ast::{ast, token::Delimiter, visit};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_span::{symbol, BytePos, Pos, Span};
|
||||
|
||||
|
|
@ -383,7 +383,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
pub(crate) fn visit_fn(
|
||||
&mut self,
|
||||
fk: visit::FnKind<'_>,
|
||||
generics: &ast::Generics,
|
||||
fd: &ast::FnDecl,
|
||||
s: Span,
|
||||
defaultness: ast::Defaultness,
|
||||
|
|
@ -392,12 +391,12 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
let indent = self.block_indent;
|
||||
let block;
|
||||
let rewrite = match fk {
|
||||
visit::FnKind::Fn(_, ident, _, _, Some(ref b)) => {
|
||||
visit::FnKind::Fn(_, ident, _, _, _, Some(ref b)) => {
|
||||
block = b;
|
||||
self.rewrite_fn_before_block(
|
||||
indent,
|
||||
ident,
|
||||
&FnSig::from_fn_kind(&fk, generics, fd, defaultness),
|
||||
&FnSig::from_fn_kind(&fk, fd, defaultness),
|
||||
mk_sp(s.lo(), b.span.lo()),
|
||||
)
|
||||
}
|
||||
|
|
@ -553,8 +552,14 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
_ => visit::FnCtxt::Foreign,
|
||||
};
|
||||
self.visit_fn(
|
||||
visit::FnKind::Fn(fn_ctxt, item.ident, sig, &item.vis, Some(body)),
|
||||
generics,
|
||||
visit::FnKind::Fn(
|
||||
fn_ctxt,
|
||||
item.ident,
|
||||
sig,
|
||||
&item.vis,
|
||||
generics,
|
||||
Some(body),
|
||||
),
|
||||
&sig.decl,
|
||||
item.span,
|
||||
defaultness,
|
||||
|
|
@ -643,8 +648,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
let inner_attrs = inner_attributes(&ai.attrs);
|
||||
let fn_ctxt = visit::FnCtxt::Assoc(assoc_ctxt);
|
||||
self.visit_fn(
|
||||
visit::FnKind::Fn(fn_ctxt, ai.ident, sig, &ai.vis, Some(body)),
|
||||
generics,
|
||||
visit::FnKind::Fn(fn_ctxt, ai.ident, sig, &ai.vis, generics, Some(body)),
|
||||
&sig.decl,
|
||||
ai.span,
|
||||
defaultness,
|
||||
|
|
@ -686,7 +690,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
// with whitespace between the delimiters and trailing semi (i.e. `foo!(abc) ;`)
|
||||
// are formatted correctly.
|
||||
let (span, rewrite) = match macro_style(mac, &self.get_context()) {
|
||||
DelimToken::Bracket | DelimToken::Paren if MacroPosition::Item == pos => {
|
||||
Delimiter::Bracket | Delimiter::Parenthesis if MacroPosition::Item == pos => {
|
||||
let search_span = mk_sp(mac.span().hi(), self.snippet_provider.end_pos());
|
||||
let hi = self.snippet_provider.span_before(search_span, ";");
|
||||
let target_span = mk_sp(mac.span().lo(), hi + BytePos(1));
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//! The features are detected using the `detect_features` function below.
|
||||
//! This function uses the CPUID instruction to read the feature flags from the
|
||||
//! CPU and encodes them in a `usize` where each bit position represents
|
||||
//! whether a feature is available (bit is set) or unavaiable (bit is cleared).
|
||||
//! whether a feature is available (bit is set) or unavailable (bit is cleared).
|
||||
//!
|
||||
//! The enum `Feature` is used to map bit positions to feature names, and the
|
||||
//! the `__crate::detect::check_for!` macro is used to map string literals (e.g.,
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ mod foo {
|
|||
// #2082
|
||||
pub(crate) fn init() {}
|
||||
|
||||
crate fn init() {}
|
||||
pub(crate) fn init() {}
|
||||
|
||||
// #2630
|
||||
fn make_map<T, F: (Fn(&T) -> String)>(records: &Vec<T>, key_fn: F) -> HashMap<String, usize> {}
|
||||
|
|
|
|||
|
|
@ -24,19 +24,6 @@ pub( crate ) enum WriteState<D> {
|
|||
WriteData(Writer<D>),
|
||||
}
|
||||
|
||||
crate enum WriteState<D> {
|
||||
WriteId {
|
||||
id: U64Writer,
|
||||
size: U64Writer,
|
||||
payload: Option<Writer<D>>,
|
||||
},
|
||||
WriteSize {
|
||||
size: U64Writer,
|
||||
payload: Option<Writer<D>>,
|
||||
},
|
||||
WriteData(Writer<D>),
|
||||
}
|
||||
|
||||
pub(in ::global:: path :: to::some_mod ) enum WriteState<D> {
|
||||
WriteId {
|
||||
id: U64Writer,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//! The features are detected using the `detect_features` function below.
|
||||
//! This function uses the CPUID instruction to read the feature flags from the
|
||||
//! CPU and encodes them in a `usize` where each bit position represents
|
||||
//! whether a feature is available (bit is set) or unavaiable (bit is cleared).
|
||||
//! whether a feature is available (bit is set) or unavailable (bit is cleared).
|
||||
//!
|
||||
//! The enum `Feature` is used to map bit positions to feature names, and the
|
||||
//! the `__crate::detect::check_for!` macro is used to map string literals (e.g.,
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ mod foo {
|
|||
// #2082
|
||||
pub(crate) fn init() {}
|
||||
|
||||
crate fn init() {}
|
||||
pub(crate) fn init() {}
|
||||
|
||||
// #2630
|
||||
fn make_map<T, F: (Fn(&T) -> String)>(records: &Vec<T>, key_fn: F) -> HashMap<String, usize> {}
|
||||
|
|
|
|||
|
|
@ -24,19 +24,6 @@ pub(crate) enum WriteState<D> {
|
|||
WriteData(Writer<D>),
|
||||
}
|
||||
|
||||
crate enum WriteState<D> {
|
||||
WriteId {
|
||||
id: U64Writer,
|
||||
size: U64Writer,
|
||||
payload: Option<Writer<D>>,
|
||||
},
|
||||
WriteSize {
|
||||
size: U64Writer,
|
||||
payload: Option<Writer<D>>,
|
||||
},
|
||||
WriteData(Writer<D>),
|
||||
}
|
||||
|
||||
pub(in global::path::to::some_mod) enum WriteState<D> {
|
||||
WriteId {
|
||||
id: U64Writer,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue