Skip to content

Commit 8a2c073

Browse files
authored
Merge pull request #6412 from ytmimi/subtree-push-nightly-2024-12-02
subtree-push nightly-2024-12-02
2 parents 9f8fcc2 + 334ee77 commit 8a2c073

19 files changed

+188
-141
lines changed

Diff for: rust-toolchain

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

Diff for: src/attr.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn format_derive(
8989
let item_spans = attr.meta_item_list().map(|meta_item_list| {
9090
meta_item_list
9191
.into_iter()
92-
.map(|nested_meta_item| nested_meta_item.span())
92+
.map(|meta_item_inner| meta_item_inner.span())
9393
})?;
9494

9595
let items = itemize_list(
@@ -242,17 +242,15 @@ fn rewrite_initial_doc_comments(
242242
Ok((0, None))
243243
}
244244

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

250250
fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
251251
match self {
252-
ast::NestedMetaItem::MetaItem(ref meta_item) => {
253-
meta_item.rewrite_result(context, shape)
254-
}
255-
ast::NestedMetaItem::Lit(ref l) => {
252+
ast::MetaItemInner::MetaItem(ref meta_item) => meta_item.rewrite_result(context, shape),
253+
ast::MetaItemInner::Lit(ref l) => {
256254
rewrite_literal(context, l.as_token_lit(), l.span, shape)
257255
}
258256
}
@@ -530,10 +528,10 @@ pub(crate) trait MetaVisitor<'ast> {
530528
fn visit_meta_list(
531529
&mut self,
532530
_meta_item: &'ast ast::MetaItem,
533-
list: &'ast [ast::NestedMetaItem],
531+
list: &'ast [ast::MetaItemInner],
534532
) {
535533
for nm in list {
536-
self.visit_nested_meta_item(nm);
534+
self.visit_meta_item_inner(nm);
537535
}
538536
}
539537

@@ -546,10 +544,10 @@ pub(crate) trait MetaVisitor<'ast> {
546544
) {
547545
}
548546

549-
fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) {
547+
fn visit_meta_item_inner(&mut self, nm: &'ast ast::MetaItemInner) {
550548
match nm {
551-
ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
552-
ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit),
549+
ast::MetaItemInner::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
550+
ast::MetaItemInner::Lit(ref lit) => self.visit_meta_item_lit(lit),
553551
}
554552
}
555553

Diff for: src/items.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ pub(crate) fn format_trait(
12231223
pos_before_where,
12241224
option,
12251225
)?;
1226+
12261227
// If the where-clause cannot fit on the same line,
12271228
// put the where-clause on a new line
12281229
if !where_clause_str.contains('\n')
@@ -1901,15 +1902,15 @@ pub(crate) fn rewrite_struct_field_prefix(
19011902
field: &ast::FieldDef,
19021903
) -> RewriteResult {
19031904
let vis = format_visibility(context, &field.vis);
1905+
let safety = format_safety(field.safety);
19041906
let type_annotation_spacing = type_annotation_spacing(context.config);
19051907
Ok(match field.ident {
19061908
Some(name) => format!(
1907-
"{}{}{}:",
1908-
vis,
1909+
"{vis}{safety}{}{}:",
19091910
rewrite_ident(context, name),
19101911
type_annotation_spacing.0
19111912
),
1912-
None => vis.to_string(),
1913+
None => format!("{vis}{safety}"),
19131914
})
19141915
}
19151916

@@ -1994,6 +1995,7 @@ pub(crate) struct StaticParts<'a> {
19941995
safety: ast::Safety,
19951996
vis: &'a ast::Visibility,
19961997
ident: symbol::Ident,
1998+
generics: Option<&'a ast::Generics>,
19971999
ty: &'a ast::Ty,
19982000
mutability: ast::Mutability,
19992001
expr_opt: Option<&'a ptr::P<ast::Expr>>,
@@ -2003,15 +2005,18 @@ pub(crate) struct StaticParts<'a> {
20032005

20042006
impl<'a> StaticParts<'a> {
20052007
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
2006-
let (defaultness, prefix, safety, ty, mutability, expr) = match &item.kind {
2007-
ast::ItemKind::Static(s) => (None, "static", s.safety, &s.ty, s.mutability, &s.expr),
2008+
let (defaultness, prefix, safety, ty, mutability, expr, generics) = match &item.kind {
2009+
ast::ItemKind::Static(s) => {
2010+
(None, "static", s.safety, &s.ty, s.mutability, &s.expr, None)
2011+
}
20082012
ast::ItemKind::Const(c) => (
20092013
Some(c.defaultness),
20102014
"const",
20112015
ast::Safety::Default,
20122016
&c.ty,
20132017
ast::Mutability::Not,
20142018
&c.expr,
2019+
Some(&c.generics),
20152020
),
20162021
_ => unreachable!(),
20172022
};
@@ -2020,6 +2025,7 @@ impl<'a> StaticParts<'a> {
20202025
safety,
20212026
vis: &item.vis,
20222027
ident: item.ident,
2028+
generics,
20232029
ty,
20242030
mutability,
20252031
expr_opt: expr.as_ref(),
@@ -2029,15 +2035,16 @@ impl<'a> StaticParts<'a> {
20292035
}
20302036

20312037
pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self {
2032-
let (defaultness, ty, expr_opt) = match &ti.kind {
2033-
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
2038+
let (defaultness, ty, expr_opt, generics) = match &ti.kind {
2039+
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)),
20342040
_ => unreachable!(),
20352041
};
20362042
StaticParts {
20372043
prefix: "const",
20382044
safety: ast::Safety::Default,
20392045
vis: &ti.vis,
20402046
ident: ti.ident,
2047+
generics,
20412048
ty,
20422049
mutability: ast::Mutability::Not,
20432050
expr_opt: expr_opt.as_ref(),
@@ -2047,15 +2054,16 @@ impl<'a> StaticParts<'a> {
20472054
}
20482055

20492056
pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self {
2050-
let (defaultness, ty, expr) = match &ii.kind {
2051-
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
2057+
let (defaultness, ty, expr, generics) = match &ii.kind {
2058+
ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)),
20522059
_ => unreachable!(),
20532060
};
20542061
StaticParts {
20552062
prefix: "const",
20562063
safety: ast::Safety::Default,
20572064
vis: &ii.vis,
20582065
ident: ii.ident,
2066+
generics,
20592067
ty,
20602068
mutability: ast::Mutability::Not,
20612069
expr_opt: expr.as_ref(),
@@ -2070,6 +2078,14 @@ fn rewrite_static(
20702078
static_parts: &StaticParts<'_>,
20712079
offset: Indent,
20722080
) -> Option<String> {
2081+
// For now, if this static (or const) has generics, then bail.
2082+
if static_parts
2083+
.generics
2084+
.is_some_and(|g| !g.params.is_empty() || !g.where_clause.is_empty())
2085+
{
2086+
return None;
2087+
}
2088+
20732089
let colon = colon_spaces(context.config);
20742090
let mut prefix = format!(
20752091
"{}{}{}{} {}{}{}",
@@ -3420,21 +3436,14 @@ impl Rewrite for ast::ForeignItem {
34203436
ref generics,
34213437
ref body,
34223438
} = **fn_kind;
3423-
if let Some(ref body) = body {
3439+
if body.is_some() {
34243440
let mut visitor = FmtVisitor::from_context(context);
34253441
visitor.block_indent = shape.indent;
34263442
visitor.last_pos = self.span.lo();
34273443
let inner_attrs = inner_attributes(&self.attrs);
34283444
let fn_ctxt = visit::FnCtxt::Foreign;
34293445
visitor.visit_fn(
3430-
visit::FnKind::Fn(
3431-
fn_ctxt,
3432-
self.ident,
3433-
sig,
3434-
&self.vis,
3435-
generics,
3436-
Some(body),
3437-
),
3446+
visit::FnKind::Fn(fn_ctxt, &self.ident, sig, &self.vis, generics, body),
34383447
&sig.decl,
34393448
self.span,
34403449
defaultness,

Diff for: src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ fn delim_token_to_str(
618618
("{ ", " }")
619619
}
620620
}
621-
Delimiter::Invisible => unreachable!(),
621+
Delimiter::Invisible(_) => unreachable!(),
622622
};
623623
if use_multiple_lines {
624624
let indent_str = shape.indent.to_string_with_newline(context.config);

Diff for: src/overflow.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(crate) enum OverflowableItem<'a> {
7878
Expr(&'a ast::Expr),
7979
GenericParam(&'a ast::GenericParam),
8080
MacroArg(&'a MacroArg),
81-
NestedMetaItem(&'a ast::NestedMetaItem),
81+
MetaItemInner(&'a ast::MetaItemInner),
8282
SegmentParam(&'a SegmentParam<'a>),
8383
FieldDef(&'a ast::FieldDef),
8484
TuplePatField(&'a TuplePatField<'a>),
@@ -123,7 +123,7 @@ impl<'a> OverflowableItem<'a> {
123123
OverflowableItem::Expr(expr) => f(*expr),
124124
OverflowableItem::GenericParam(gp) => f(*gp),
125125
OverflowableItem::MacroArg(macro_arg) => f(*macro_arg),
126-
OverflowableItem::NestedMetaItem(nmi) => f(*nmi),
126+
OverflowableItem::MetaItemInner(nmi) => f(*nmi),
127127
OverflowableItem::SegmentParam(sp) => f(*sp),
128128
OverflowableItem::FieldDef(sf) => f(*sf),
129129
OverflowableItem::TuplePatField(pat) => f(*pat),
@@ -138,9 +138,9 @@ impl<'a> OverflowableItem<'a> {
138138
OverflowableItem::Expr(expr) => is_simple_expr(expr),
139139
OverflowableItem::MacroArg(MacroArg::Keyword(..)) => true,
140140
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
141-
OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item {
142-
ast::NestedMetaItem::Lit(..) => true,
143-
ast::NestedMetaItem::MetaItem(ref meta_item) => {
141+
OverflowableItem::MetaItemInner(meta_item_inner) => match meta_item_inner {
142+
ast::MetaItemInner::Lit(..) => true,
143+
ast::MetaItemInner::MetaItem(ref meta_item) => {
144144
matches!(meta_item.kind, ast::MetaItemKind::Word)
145145
}
146146
},
@@ -184,12 +184,10 @@ impl<'a> OverflowableItem<'a> {
184184
MacroArg::Item(..) => len == 1,
185185
MacroArg::Keyword(..) => false,
186186
},
187-
OverflowableItem::NestedMetaItem(nested_meta_item) if len == 1 => {
188-
match nested_meta_item {
189-
ast::NestedMetaItem::Lit(..) => false,
190-
ast::NestedMetaItem::MetaItem(..) => true,
191-
}
192-
}
187+
OverflowableItem::MetaItemInner(meta_item_inner) if len == 1 => match meta_item_inner {
188+
ast::MetaItemInner::Lit(..) => false,
189+
ast::MetaItemInner::MetaItem(..) => true,
190+
},
193191
OverflowableItem::SegmentParam(SegmentParam::Type(ty)) => {
194192
can_be_overflowed_type(context, ty, len)
195193
}
@@ -202,7 +200,7 @@ impl<'a> OverflowableItem<'a> {
202200
fn special_cases(&self, config: &Config) -> impl Iterator<Item = &(&'static str, usize)> {
203201
let base_cases = match self {
204202
OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS,
205-
OverflowableItem::NestedMetaItem(..) => SPECIAL_CASE_ATTR,
203+
OverflowableItem::MetaItemInner(..) => SPECIAL_CASE_ATTR,
206204
_ => &[],
207205
};
208206
let additional_cases = match self {
@@ -261,7 +259,7 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types {
261259
impl_into_overflowable_item_for_ast_node!(
262260
Expr,
263261
GenericParam,
264-
NestedMetaItem,
262+
MetaItemInner,
265263
FieldDef,
266264
Ty,
267265
Pat,

Diff for: src/parse/macros/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ use crate::rewrite::RewriteContext;
77
pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option<AsmArgs> {
88
let ts = mac.args.tokens.clone();
99
let mut parser = super::build_parser(context, ts);
10-
parse_asm_args(&mut parser, mac.span(), false).ok()
10+
parse_asm_args(&mut parser, mac.span(), ast::AsmMacro::Asm).ok()
1111
}

Diff for: src/parse/session.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl SilentOnIgnoredFilesEmitter {
4646
}
4747

4848
impl Translate for SilentOnIgnoredFilesEmitter {
49-
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
49+
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
5050
self.emitter.fluent_bundle()
5151
}
5252

@@ -56,7 +56,7 @@ impl Translate for SilentOnIgnoredFilesEmitter {
5656
}
5757

5858
impl Emitter for SilentOnIgnoredFilesEmitter {
59-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
59+
fn source_map(&self) -> Option<&SourceMap> {
6060
None
6161
}
6262

@@ -344,7 +344,7 @@ mod tests {
344344
}
345345

346346
impl Translate for TestEmitter {
347-
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
347+
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
348348
None
349349
}
350350

@@ -354,7 +354,7 @@ mod tests {
354354
}
355355

356356
impl Emitter for TestEmitter {
357-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
357+
fn source_map(&self) -> Option<&SourceMap> {
358358
None
359359
}
360360

Diff for: src/skip.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ fn get_skip_names(kind: &str, attrs: &[ast::Attribute]) -> Vec<String> {
116116
}
117117

118118
if let Some(list) = attr.meta_item_list() {
119-
for nested_meta_item in list {
120-
if let Some(name) = nested_meta_item.ident() {
119+
for meta_item_inner in list {
120+
if let Some(name) = meta_item_inner.ident() {
121121
skip_names.push(name.to_string());
122122
}
123123
}

Diff for: src/spanned.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ impl Spanned for ast::FieldDef {
150150

151151
impl Spanned for ast::WherePredicate {
152152
fn span(&self) -> Span {
153-
match *self {
154-
ast::WherePredicate::BoundPredicate(ref p) => p.span,
155-
ast::WherePredicate::RegionPredicate(ref p) => p.span,
156-
ast::WherePredicate::EqPredicate(ref p) => p.span,
157-
}
153+
self.span
158154
}
159155
}
160156

@@ -180,7 +176,7 @@ impl Spanned for ast::GenericArg {
180176
impl Spanned for ast::GenericBound {
181177
fn span(&self) -> Span {
182178
match *self {
183-
ast::GenericBound::Trait(ref ptr, _) => ptr.span,
179+
ast::GenericBound::Trait(ref ptr) => ptr.span,
184180
ast::GenericBound::Outlives(ref l) => l.ident.span,
185181
ast::GenericBound::Use(_, span) => span,
186182
}
@@ -199,7 +195,7 @@ impl Spanned for MacroArg {
199195
}
200196
}
201197

202-
impl Spanned for ast::NestedMetaItem {
198+
impl Spanned for ast::MetaItemInner {
203199
fn span(&self) -> Span {
204200
self.span()
205201
}

0 commit comments

Comments
 (0)