Skip to content

Commit a1017ae

Browse files
authored
Merge pull request #6320 from ytmimi/subtree-push-nightly-2024-09-10
subtree-push nightly-2024-09-10
2 parents 182a203 + d66e974 commit a1017ae

21 files changed

+44
-20
lines changed

rust-toolchain

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

src/attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use rustc_ast::HasAttrs;
44
use rustc_ast::ast;
55
use rustc_span::{Span, symbol::sym};
6+
use tracing::debug;
67

78
use self::doc_comment::DocCommentFormatter;
89
use crate::comment::{CommentStyle, contains_comment, rewrite_doc_comment};

src/chains.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use std::cmp::min;
6060

6161
use rustc_ast::{ast, ptr};
6262
use rustc_span::{BytePos, Span, symbol};
63+
use tracing::debug;
6364

6465
use crate::comment::{CharClasses, FullCodeCharKind, RichChar, rewrite_comment};
6566
use crate::config::{IndentStyle, StyleEdition};

src/closures.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_ast::{ast, ptr};
22
use rustc_span::Span;
33
use thin_vec::thin_vec;
4+
use tracing::debug;
45

56
use crate::attr::get_attrs_from_stmt;
67
use crate::config::StyleEdition;

src/comment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{borrow::Cow, iter};
44

55
use itertools::{MultiPeek, multipeek};
66
use rustc_span::Span;
7+
use tracing::{debug, trace};
78

89
use crate::config::Config;
910
use crate::rewrite::{RewriteContext, RewriteErrorExt, RewriteResult};

src/expr.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use itertools::Itertools;
55
use rustc_ast::token::{Delimiter, Lit, LitKind};
66
use rustc_ast::{ForLoopKind, MatchKind, ast, ptr, token};
77
use rustc_span::{BytePos, Span};
8+
use tracing::debug;
89

910
use crate::chains::rewrite_chain;
1011
use crate::closures;
@@ -467,7 +468,7 @@ fn rewrite_empty_block(
467468
return None;
468469
}
469470

470-
let label_str = rewrite_label(label);
471+
let label_str = rewrite_label(context, label);
471472
if attrs.map_or(false, |a| !inner_attributes(a).is_empty()) {
472473
return None;
473474
}
@@ -537,7 +538,7 @@ fn rewrite_single_line_block(
537538
.offset_left(last_line_width(prefix))
538539
.max_width_error(shape.width, block_expr.span())?;
539540
let expr_str = block_expr.rewrite_result(context, expr_shape)?;
540-
let label_str = rewrite_label(label);
541+
let label_str = rewrite_label(context, label);
541542
let result = format!("{prefix}{label_str}{{ {expr_str} }}");
542543
if result.len() <= shape.width && !result.contains('\n') {
543544
return Ok(result);
@@ -572,7 +573,7 @@ pub(crate) fn rewrite_block_with_visitor(
572573
}
573574

574575
let inner_attrs = attrs.map(inner_attributes);
575-
let label_str = rewrite_label(label);
576+
let label_str = rewrite_label(context, label);
576577
visitor.visit_block(block, inner_attrs.as_deref(), has_braces);
577578
let visitor_context = visitor.get_context();
578579
context
@@ -956,7 +957,7 @@ impl<'a> ControlFlow<'a> {
956957
fresh_shape
957958
};
958959

959-
let label_string = rewrite_label(self.label);
960+
let label_string = rewrite_label(context, self.label);
960961
// 1 = space after keyword.
961962
let offset = self.keyword.len() + label_string.len() + 1;
962963

@@ -1189,9 +1190,9 @@ impl<'a> Rewrite for ControlFlow<'a> {
11891190
}
11901191
}
11911192

1192-
fn rewrite_label(opt_label: Option<ast::Label>) -> Cow<'static, str> {
1193+
fn rewrite_label(context: &RewriteContext<'_>, opt_label: Option<ast::Label>) -> Cow<'static, str> {
11931194
match opt_label {
1194-
Some(label) => Cow::from(format!("{}: ", label.ident)),
1195+
Some(label) => Cow::from(format!("{}: ", context.snippet(label.ident.span))),
11951196
None => Cow::from(""),
11961197
}
11971198
}

src/format-diff/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
#![deny(warnings)]
66

7-
#[macro_use]
8-
extern crate tracing;
9-
107
use serde::{Deserialize, Serialize};
118
use serde_json as json;
129
use thiserror::Error;
10+
use tracing::debug;
1311
use tracing_subscriber::EnvFilter;
1412

1513
use std::collections::HashSet;

src/formatting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::time::{Duration, Instant};
66

77
use rustc_ast::ast;
88
use rustc_span::Span;
9+
use tracing::debug;
910

1011
use self::newline_style::apply_newline_style;
1112
use crate::comment::{CharClasses, FullCodeCharKind};

src/git-rustfmt/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// `rustc_driver`.
33
#![feature(rustc_private)]
44

5-
#[macro_use]
6-
extern crate tracing;
7-
85
use std::env;
96
use std::io::stdout;
107
use std::path::{Path, PathBuf};
@@ -13,6 +10,7 @@ use std::str::FromStr;
1310

1411
use getopts::{Matches, Options};
1512
use rustfmt_nightly as rustfmt;
13+
use tracing::debug;
1614
use tracing_subscriber::EnvFilter;
1715

1816
use crate::rustfmt::{

src/items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use regex::Regex;
77
use rustc_ast::visit;
88
use rustc_ast::{ast, ptr};
99
use rustc_span::{BytePos, DUMMY_SP, Span, symbol};
10+
use tracing::debug;
1011

1112
use crate::attr::filter_inline_attrs;
1213
use crate::comment::{

src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#![recursion_limit = "256"]
55
#![allow(clippy::match_like_matches_macro)]
66

7-
#[macro_use]
8-
extern crate tracing;
9-
107
// N.B. these crates are loaded from the sysroot, so they need extern crate.
118
extern crate rustc_ast;
129
extern crate rustc_ast_pretty;

src/macros.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_span::{
2020
BytePos, DUMMY_SP, Span, Symbol,
2121
symbol::{self, kw},
2222
};
23+
use tracing::debug;
2324

2425
use crate::comment::{
2526
CharClasses, FindUncommented, FullCodeCharKind, LineClasses, contains_comment,
@@ -1104,7 +1105,7 @@ fn force_space_before(tok: &TokenKind) -> bool {
11041105
fn ident_like(tok: &Token) -> bool {
11051106
matches!(
11061107
tok.kind,
1107-
TokenKind::Ident(..) | TokenKind::Literal(..) | TokenKind::Lifetime(_)
1108+
TokenKind::Ident(..) | TokenKind::Literal(..) | TokenKind::Lifetime(..)
11081109
)
11091110
}
11101111

@@ -1129,7 +1130,9 @@ fn next_space(tok: &TokenKind) -> SpaceState {
11291130
| TokenKind::OpenDelim(_)
11301131
| TokenKind::CloseDelim(_) => SpaceState::Never,
11311132

1132-
TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(_) => SpaceState::Ident,
1133+
TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(..) => {
1134+
SpaceState::Ident
1135+
}
11331136

11341137
_ => SpaceState::Always,
11351138
}

src/matches.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::iter::repeat;
44

55
use rustc_ast::{MatchKind, ast, ptr};
66
use rustc_span::{BytePos, Span};
7+
use tracing::debug;
78

89
use crate::comment::{FindUncommented, combine_strs_with_missing_comments, rewrite_comment};
910
use crate::config::lists::*;

src/missed_spans.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_span::{BytePos, Pos, Span};
2+
use tracing::debug;
23

34
use crate::comment::{CodeCharKind, CommentCodeSlices, is_last_comment_block, rewrite_comment};
45
use crate::config::FileName;

src/modules/visitor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_ast::ast;
22
use rustc_ast::visit::Visitor;
33
use rustc_span::Symbol;
4+
use tracing::debug;
45

56
use crate::attr::MetaVisitor;
67
use crate::parse::macros::cfg_if::parse_cfg_if;

src/overflow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use itertools::Itertools;
66
use rustc_ast::token::Delimiter;
77
use rustc_ast::{ast, ptr};
88
use rustc_span::Span;
9+
use tracing::debug;
910

1011
use crate::closures;
1112
use crate::config::StyleEdition;

src/test/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
};
2020

2121
use rustfmt_config_proc_macro::nightly_only_test;
22+
use tracing::{debug, warn};
2223

2324
mod configuration_snippet;
2425
mod mod_resolver;

src/types.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::ops::Deref;
33
use rustc_ast::ast::{self, FnRetTy, Mutability, Term};
44
use rustc_ast::ptr;
55
use rustc_span::{BytePos, Pos, Span, symbol::kw};
6+
use tracing::debug;
67

78
use crate::comment::{combine_strs_with_missing_comments, contains_comment};
89
use crate::config::lists::*;
@@ -598,7 +599,7 @@ impl Rewrite for ast::Lifetime {
598599
}
599600

600601
fn rewrite_result(&self, context: &RewriteContext<'_>, _: Shape) -> RewriteResult {
601-
Ok(rewrite_ident(context, self.ident).to_owned())
602+
Ok(context.snippet(self.ident.span).to_owned())
602603
}
603604
}
604605

src/visitor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::rc::Rc;
44
use rustc_ast::{ast, token::Delimiter, visit};
55
use rustc_data_structures::sync::Lrc;
66
use rustc_span::{BytePos, Pos, Span, symbol};
7+
use tracing::debug;
78

89
use crate::attr::*;
910
use crate::comment::{CodeCharKind, CommentCodeSlices, contains_comment, rewrite_comment};

tests/target/raw-lifetimes.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-edition: 2021
2+
3+
// Simple idempotence test for raw lifetimes.
4+
5+
fn test<'r#gen>() -> &'r#gen () {
6+
// Test raw lifetimes...
7+
}
8+
9+
fn label() {
10+
'r#label: {
11+
// Test raw labels.
12+
}
13+
}
14+
15+
fn main() {}

tests/target/unsafe_attributes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(unsafe_attributes)]
21
// https://github.com/rust-lang/rust/issues/123757
32
//
43
#![simple_ident]

0 commit comments

Comments
 (0)