Skip to content

Commit

Permalink
Merge pull request #6412 from ytmimi/subtree-push-nightly-2024-12-02
Browse files Browse the repository at this point in the history
subtree-push nightly-2024-12-02
  • Loading branch information
ytmimi authored Dec 11, 2024
2 parents 9f8fcc2 + 334ee77 commit 8a2c073
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 141 deletions.
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-09-10"
channel = "nightly-2024-12-02"
components = ["llvm-tools", "rustc-dev"]
20 changes: 9 additions & 11 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn format_derive(
let item_spans = attr.meta_item_list().map(|meta_item_list| {
meta_item_list
.into_iter()
.map(|nested_meta_item| nested_meta_item.span())
.map(|meta_item_inner| meta_item_inner.span())
})?;

let items = itemize_list(
Expand Down Expand Up @@ -242,17 +242,15 @@ fn rewrite_initial_doc_comments(
Ok((0, None))
}

impl Rewrite for ast::NestedMetaItem {
impl Rewrite for ast::MetaItemInner {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
self.rewrite_result(context, shape).ok()
}

fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
match self {
ast::NestedMetaItem::MetaItem(ref meta_item) => {
meta_item.rewrite_result(context, shape)
}
ast::NestedMetaItem::Lit(ref l) => {
ast::MetaItemInner::MetaItem(ref meta_item) => meta_item.rewrite_result(context, shape),
ast::MetaItemInner::Lit(ref l) => {
rewrite_literal(context, l.as_token_lit(), l.span, shape)
}
}
Expand Down Expand Up @@ -530,10 +528,10 @@ pub(crate) trait MetaVisitor<'ast> {
fn visit_meta_list(
&mut self,
_meta_item: &'ast ast::MetaItem,
list: &'ast [ast::NestedMetaItem],
list: &'ast [ast::MetaItemInner],
) {
for nm in list {
self.visit_nested_meta_item(nm);
self.visit_meta_item_inner(nm);
}
}

Expand All @@ -546,10 +544,10 @@ pub(crate) trait MetaVisitor<'ast> {
) {
}

fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) {
fn visit_meta_item_inner(&mut self, nm: &'ast ast::MetaItemInner) {
match nm {
ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit),
ast::MetaItemInner::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
ast::MetaItemInner::Lit(ref lit) => self.visit_meta_item_lit(lit),
}
}

Expand Down
45 changes: 27 additions & 18 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ pub(crate) fn format_trait(
pos_before_where,
option,
)?;

// If the where-clause cannot fit on the same line,
// put the where-clause on a new line
if !where_clause_str.contains('\n')
Expand Down Expand Up @@ -1901,15 +1902,15 @@ pub(crate) fn rewrite_struct_field_prefix(
field: &ast::FieldDef,
) -> RewriteResult {
let vis = format_visibility(context, &field.vis);
let safety = format_safety(field.safety);
let type_annotation_spacing = type_annotation_spacing(context.config);
Ok(match field.ident {
Some(name) => format!(
"{}{}{}:",
vis,
"{vis}{safety}{}{}:",
rewrite_ident(context, name),
type_annotation_spacing.0
),
None => vis.to_string(),
None => format!("{vis}{safety}"),
})
}

Expand Down Expand Up @@ -1994,6 +1995,7 @@ pub(crate) struct StaticParts<'a> {
safety: ast::Safety,
vis: &'a ast::Visibility,
ident: symbol::Ident,
generics: Option<&'a ast::Generics>,
ty: &'a ast::Ty,
mutability: ast::Mutability,
expr_opt: Option<&'a ptr::P<ast::Expr>>,
Expand All @@ -2003,15 +2005,18 @@ pub(crate) struct StaticParts<'a> {

impl<'a> StaticParts<'a> {
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
let (defaultness, prefix, safety, ty, mutability, expr) = match &item.kind {
ast::ItemKind::Static(s) => (None, "static", s.safety, &s.ty, s.mutability, &s.expr),
let (defaultness, prefix, safety, ty, mutability, expr, generics) = match &item.kind {
ast::ItemKind::Static(s) => {
(None, "static", s.safety, &s.ty, s.mutability, &s.expr, None)
}
ast::ItemKind::Const(c) => (
Some(c.defaultness),
"const",
ast::Safety::Default,
&c.ty,
ast::Mutability::Not,
&c.expr,
Some(&c.generics),
),
_ => unreachable!(),
};
Expand All @@ -2020,6 +2025,7 @@ impl<'a> StaticParts<'a> {
safety,
vis: &item.vis,
ident: item.ident,
generics,
ty,
mutability,
expr_opt: expr.as_ref(),
Expand All @@ -2029,15 +2035,16 @@ impl<'a> StaticParts<'a> {
}

pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr_opt) = match &ti.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
let (defaultness, ty, expr_opt, generics) = match &ti.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)),
_ => unreachable!(),
};
StaticParts {
prefix: "const",
safety: ast::Safety::Default,
vis: &ti.vis,
ident: ti.ident,
generics,
ty,
mutability: ast::Mutability::Not,
expr_opt: expr_opt.as_ref(),
Expand All @@ -2047,15 +2054,16 @@ impl<'a> StaticParts<'a> {
}

pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr) = match &ii.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
let (defaultness, ty, expr, generics) = match &ii.kind {
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)),
_ => unreachable!(),
};
StaticParts {
prefix: "const",
safety: ast::Safety::Default,
vis: &ii.vis,
ident: ii.ident,
generics,
ty,
mutability: ast::Mutability::Not,
expr_opt: expr.as_ref(),
Expand All @@ -2070,6 +2078,14 @@ fn rewrite_static(
static_parts: &StaticParts<'_>,
offset: Indent,
) -> Option<String> {
// For now, if this static (or const) has generics, then bail.
if static_parts
.generics
.is_some_and(|g| !g.params.is_empty() || !g.where_clause.is_empty())
{
return None;
}

let colon = colon_spaces(context.config);
let mut prefix = format!(
"{}{}{}{} {}{}{}",
Expand Down Expand Up @@ -3420,21 +3436,14 @@ impl Rewrite for ast::ForeignItem {
ref generics,
ref body,
} = **fn_kind;
if let Some(ref body) = body {
if body.is_some() {
let mut visitor = FmtVisitor::from_context(context);
visitor.block_indent = shape.indent;
visitor.last_pos = self.span.lo();
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,
generics,
Some(body),
),
visit::FnKind::Fn(fn_ctxt, &self.ident, sig, &self.vis, generics, body),
&sig.decl,
self.span,
defaultness,
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ fn delim_token_to_str(
("{ ", " }")
}
}
Delimiter::Invisible => unreachable!(),
Delimiter::Invisible(_) => unreachable!(),
};
if use_multiple_lines {
let indent_str = shape.indent.to_string_with_newline(context.config);
Expand Down
24 changes: 11 additions & 13 deletions src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) enum OverflowableItem<'a> {
Expr(&'a ast::Expr),
GenericParam(&'a ast::GenericParam),
MacroArg(&'a MacroArg),
NestedMetaItem(&'a ast::NestedMetaItem),
MetaItemInner(&'a ast::MetaItemInner),
SegmentParam(&'a SegmentParam<'a>),
FieldDef(&'a ast::FieldDef),
TuplePatField(&'a TuplePatField<'a>),
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'a> OverflowableItem<'a> {
OverflowableItem::Expr(expr) => f(*expr),
OverflowableItem::GenericParam(gp) => f(*gp),
OverflowableItem::MacroArg(macro_arg) => f(*macro_arg),
OverflowableItem::NestedMetaItem(nmi) => f(*nmi),
OverflowableItem::MetaItemInner(nmi) => f(*nmi),
OverflowableItem::SegmentParam(sp) => f(*sp),
OverflowableItem::FieldDef(sf) => f(*sf),
OverflowableItem::TuplePatField(pat) => f(*pat),
Expand All @@ -138,9 +138,9 @@ impl<'a> OverflowableItem<'a> {
OverflowableItem::Expr(expr) => is_simple_expr(expr),
OverflowableItem::MacroArg(MacroArg::Keyword(..)) => true,
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item {
ast::NestedMetaItem::Lit(..) => true,
ast::NestedMetaItem::MetaItem(ref meta_item) => {
OverflowableItem::MetaItemInner(meta_item_inner) => match meta_item_inner {
ast::MetaItemInner::Lit(..) => true,
ast::MetaItemInner::MetaItem(ref meta_item) => {
matches!(meta_item.kind, ast::MetaItemKind::Word)
}
},
Expand Down Expand Up @@ -184,12 +184,10 @@ impl<'a> OverflowableItem<'a> {
MacroArg::Item(..) => len == 1,
MacroArg::Keyword(..) => false,
},
OverflowableItem::NestedMetaItem(nested_meta_item) if len == 1 => {
match nested_meta_item {
ast::NestedMetaItem::Lit(..) => false,
ast::NestedMetaItem::MetaItem(..) => true,
}
}
OverflowableItem::MetaItemInner(meta_item_inner) if len == 1 => match meta_item_inner {
ast::MetaItemInner::Lit(..) => false,
ast::MetaItemInner::MetaItem(..) => true,
},
OverflowableItem::SegmentParam(SegmentParam::Type(ty)) => {
can_be_overflowed_type(context, ty, len)
}
Expand All @@ -202,7 +200,7 @@ impl<'a> OverflowableItem<'a> {
fn special_cases(&self, config: &Config) -> impl Iterator<Item = &(&'static str, usize)> {
let base_cases = match self {
OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS,
OverflowableItem::NestedMetaItem(..) => SPECIAL_CASE_ATTR,
OverflowableItem::MetaItemInner(..) => SPECIAL_CASE_ATTR,
_ => &[],
};
let additional_cases = match self {
Expand Down Expand Up @@ -261,7 +259,7 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types {
impl_into_overflowable_item_for_ast_node!(
Expr,
GenericParam,
NestedMetaItem,
MetaItemInner,
FieldDef,
Ty,
Pat,
Expand Down
2 changes: 1 addition & 1 deletion src/parse/macros/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ use crate::rewrite::RewriteContext;
pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option<AsmArgs> {
let ts = mac.args.tokens.clone();
let mut parser = super::build_parser(context, ts);
parse_asm_args(&mut parser, mac.span(), false).ok()
parse_asm_args(&mut parser, mac.span(), ast::AsmMacro::Asm).ok()
}
8 changes: 4 additions & 4 deletions src/parse/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl SilentOnIgnoredFilesEmitter {
}

impl Translate for SilentOnIgnoredFilesEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
self.emitter.fluent_bundle()
}

Expand All @@ -56,7 +56,7 @@ impl Translate for SilentOnIgnoredFilesEmitter {
}

impl Emitter for SilentOnIgnoredFilesEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
None
}

Expand Down Expand Up @@ -344,7 +344,7 @@ mod tests {
}

impl Translate for TestEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
None
}

Expand All @@ -354,7 +354,7 @@ mod tests {
}

impl Emitter for TestEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
None
}

Expand Down
4 changes: 2 additions & 2 deletions src/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ fn get_skip_names(kind: &str, attrs: &[ast::Attribute]) -> Vec<String> {
}

if let Some(list) = attr.meta_item_list() {
for nested_meta_item in list {
if let Some(name) = nested_meta_item.ident() {
for meta_item_inner in list {
if let Some(name) = meta_item_inner.ident() {
skip_names.push(name.to_string());
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/spanned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ impl Spanned for ast::FieldDef {

impl Spanned for ast::WherePredicate {
fn span(&self) -> Span {
match *self {
ast::WherePredicate::BoundPredicate(ref p) => p.span,
ast::WherePredicate::RegionPredicate(ref p) => p.span,
ast::WherePredicate::EqPredicate(ref p) => p.span,
}
self.span
}
}

Expand All @@ -180,7 +176,7 @@ impl Spanned for ast::GenericArg {
impl Spanned for ast::GenericBound {
fn span(&self) -> Span {
match *self {
ast::GenericBound::Trait(ref ptr, _) => ptr.span,
ast::GenericBound::Trait(ref ptr) => ptr.span,
ast::GenericBound::Outlives(ref l) => l.ident.span,
ast::GenericBound::Use(_, span) => span,
}
Expand All @@ -199,7 +195,7 @@ impl Spanned for MacroArg {
}
}

impl Spanned for ast::NestedMetaItem {
impl Spanned for ast::MetaItemInner {
fn span(&self) -> Span {
self.span()
}
Expand Down
Loading

0 comments on commit 8a2c073

Please sign in to comment.