From 87949d7ddea525a7284bed36741e0968c15cfe2e Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Wed, 7 Aug 2024 01:36:28 -0500 Subject: [PATCH 1/6] Stabilize `unsafe_attributes` --- tests/target/unsafe_attributes.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/target/unsafe_attributes.rs b/tests/target/unsafe_attributes.rs index a05bedc751a..d79c56f2147 100644 --- a/tests/target/unsafe_attributes.rs +++ b/tests/target/unsafe_attributes.rs @@ -1,4 +1,3 @@ -#![feature(unsafe_attributes)] // https://github.com/rust-lang/rust/issues/123757 // #![simple_ident] From 1fcfd57e2fbd59d2b4edbb6e3e86846646823357 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 30 Aug 2024 13:31:05 +1000 Subject: [PATCH 2/6] Remove `#[macro_use] extern crate tracing` from rustfmt helpers. --- src/format-diff/main.rs | 4 +--- src/git-rustfmt/main.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/format-diff/main.rs b/src/format-diff/main.rs index f9eb70f6e04..d8616c63df9 100644 --- a/src/format-diff/main.rs +++ b/src/format-diff/main.rs @@ -4,12 +4,10 @@ #![deny(warnings)] -#[macro_use] -extern crate tracing; - use serde::{Deserialize, Serialize}; use serde_json as json; use thiserror::Error; +use tracing::debug; use tracing_subscriber::EnvFilter; use std::collections::HashSet; diff --git a/src/git-rustfmt/main.rs b/src/git-rustfmt/main.rs index 5674f40bef9..b8b0432aa95 100644 --- a/src/git-rustfmt/main.rs +++ b/src/git-rustfmt/main.rs @@ -2,9 +2,6 @@ // `rustc_driver`. #![feature(rustc_private)] -#[macro_use] -extern crate tracing; - use std::env; use std::io::stdout; use std::path::{Path, PathBuf}; @@ -13,6 +10,7 @@ use std::str::FromStr; use getopts::{Matches, Options}; use rustfmt_nightly as rustfmt; +use tracing::debug; use tracing_subscriber::EnvFilter; use crate::rustfmt::{load_config, CliOptions, FormatReportFormatterBuilder, Input, Session}; From c3beb056871f477c23462c4cf838759dc214dfe2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 30 Aug 2024 13:35:05 +1000 Subject: [PATCH 3/6] Remove `#[macro_use] extern crate tracing` from rustfmt. --- src/attr.rs | 1 + src/chains.rs | 1 + src/closures.rs | 1 + src/comment.rs | 1 + src/expr.rs | 1 + src/formatting.rs | 1 + src/items.rs | 1 + src/lib.rs | 4 ++-- src/macros.rs | 1 + src/matches.rs | 1 + src/missed_spans.rs | 1 + src/modules/visitor.rs | 1 + src/overflow.rs | 1 + src/test/mod.rs | 1 + src/types.rs | 1 + src/visitor.rs | 1 + 16 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index 433b9256202..a2c0a28d66e 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -3,6 +3,7 @@ use rustc_ast::ast; use rustc_ast::HasAttrs; use rustc_span::{symbol::sym, Span}; +use tracing::debug; use self::doc_comment::DocCommentFormatter; use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle}; diff --git a/src/chains.rs b/src/chains.rs index ea23690caed..96fbe7a963a 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -60,6 +60,7 @@ use std::cmp::min; use rustc_ast::{ast, ptr}; use rustc_span::{symbol, BytePos, Span}; +use tracing::debug; use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar}; use crate::config::{IndentStyle, Version}; diff --git a/src/closures.rs b/src/closures.rs index 5bf29441b54..b5c26235e77 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -1,6 +1,7 @@ use rustc_ast::{ast, ptr}; use rustc_span::Span; use thin_vec::thin_vec; +use tracing::debug; use crate::attr::get_attrs_from_stmt; use crate::config::lists::*; diff --git a/src/comment.rs b/src/comment.rs index 24a5a1be2c3..e76be0fd162 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -4,6 +4,7 @@ use std::{borrow::Cow, iter}; use itertools::{multipeek, MultiPeek}; use rustc_span::Span; +use tracing::{debug, trace}; use crate::config::Config; use crate::rewrite::RewriteContext; diff --git a/src/expr.rs b/src/expr.rs index c7c4b680b07..6ba5217bc92 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -5,6 +5,7 @@ use itertools::Itertools; use rustc_ast::token::{Delimiter, Lit, LitKind}; use rustc_ast::{ast, ptr, token, ForLoopKind, MatchKind}; use rustc_span::{BytePos, Span}; +use tracing::debug; use crate::chains::rewrite_chain; use crate::closures; diff --git a/src/formatting.rs b/src/formatting.rs index 7f442230b12..5e71fe107eb 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -6,6 +6,7 @@ use std::time::{Duration, Instant}; use rustc_ast::ast; use rustc_span::Span; +use tracing::debug; use self::newline_style::apply_newline_style; use crate::comment::{CharClasses, FullCodeCharKind}; diff --git a/src/items.rs b/src/items.rs index eb11604b277..cbf7ce90e37 100644 --- a/src/items.rs +++ b/src/items.rs @@ -7,6 +7,7 @@ use regex::Regex; use rustc_ast::visit; use rustc_ast::{ast, ptr}; use rustc_span::{symbol, BytePos, Span, DUMMY_SP}; +use tracing::debug; use crate::attr::filter_inline_attrs; use crate::comment::{ diff --git a/src/lib.rs b/src/lib.rs index ff2b14af078..4263a49fd72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,8 @@ #![allow(clippy::match_like_matches_macro)] #![allow(unreachable_pub)] -#[macro_use] -extern crate tracing; +// #[macro_use] +// extern crate tracing; // N.B. these crates are loaded from the sysroot, so they need extern crate. extern crate rustc_ast; diff --git a/src/macros.rs b/src/macros.rs index a0582b061c0..b14b74a4938 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -20,6 +20,7 @@ use rustc_span::{ symbol::{self, kw}, BytePos, Span, Symbol, DUMMY_SP, }; +use tracing::debug; use crate::comment::{ contains_comment, CharClasses, FindUncommented, FullCodeCharKind, LineClasses, diff --git a/src/matches.rs b/src/matches.rs index e4fa077073c..30bf6271b2e 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -4,6 +4,7 @@ use std::iter::repeat; use rustc_ast::{ast, ptr, MatchKind}; use rustc_span::{BytePos, Span}; +use tracing::debug; use crate::comment::{combine_strs_with_missing_comments, rewrite_comment, FindUncommented}; use crate::config::lists::*; diff --git a/src/missed_spans.rs b/src/missed_spans.rs index b1a7769c21b..56adb2e5e69 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -1,4 +1,5 @@ use rustc_span::{BytePos, Pos, Span}; +use tracing::debug; use crate::comment::{is_last_comment_block, rewrite_comment, CodeCharKind, CommentCodeSlices}; use crate::config::file_lines::FileLines; diff --git a/src/modules/visitor.rs b/src/modules/visitor.rs index 3e05b6d0c5d..8b46899eaf2 100644 --- a/src/modules/visitor.rs +++ b/src/modules/visitor.rs @@ -1,6 +1,7 @@ use rustc_ast::ast; use rustc_ast::visit::Visitor; use rustc_span::Symbol; +use tracing::debug; use crate::attr::MetaVisitor; use crate::parse::macros::cfg_if::parse_cfg_if; diff --git a/src/overflow.rs b/src/overflow.rs index a1de71a35be..cdb735be8a4 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -6,6 +6,7 @@ use itertools::Itertools; use rustc_ast::token::Delimiter; use rustc_ast::{ast, ptr}; use rustc_span::Span; +use tracing::debug; use crate::closures; use crate::config::Version; diff --git a/src/test/mod.rs b/src/test/mod.rs index 7c563801c32..286e8b8760a 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -16,6 +16,7 @@ use crate::source_file; use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session}; use rustfmt_config_proc_macro::nightly_only_test; +use tracing::{debug, warn}; mod configuration_snippet; mod mod_resolver; diff --git a/src/types.rs b/src/types.rs index c826547e9d0..875c61113c5 100644 --- a/src/types.rs +++ b/src/types.rs @@ -3,6 +3,7 @@ use std::ops::Deref; use rustc_ast::ast::{self, FnRetTy, Mutability, Term}; use rustc_ast::ptr; use rustc_span::{symbol::kw, BytePos, Pos, Span}; +use tracing::debug; use crate::comment::{combine_strs_with_missing_comments, contains_comment}; use crate::config::lists::*; diff --git a/src/visitor.rs b/src/visitor.rs index 1de9f5a9524..ac68fc5fecf 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -4,6 +4,7 @@ use std::rc::Rc; use rustc_ast::{ast, token::Delimiter, visit}; use rustc_data_structures::sync::Lrc; use rustc_span::{symbol, BytePos, Pos, Span}; +use tracing::debug; use crate::attr::*; use crate::comment::{contains_comment, rewrite_comment, CodeCharKind, CommentCodeSlices}; From e1712ea92f008e3e58cecda8716cfb669f4e62ca Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 13 Jun 2024 21:37:19 -0400 Subject: [PATCH 4/6] Fix tools --- src/expr.rs | 12 ++++++------ src/macros.rs | 6 ++++-- src/types.rs | 2 +- tests/target/raw-lifetimes.rs | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 tests/target/raw-lifetimes.rs diff --git a/src/expr.rs b/src/expr.rs index 6ba5217bc92..75c75c523b0 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -462,7 +462,7 @@ fn rewrite_empty_block( return None; } - let label_str = rewrite_label(label); + let label_str = rewrite_label(context, label); if attrs.map_or(false, |a| !inner_attributes(a).is_empty()) { return None; } @@ -527,7 +527,7 @@ fn rewrite_single_line_block( if let Some(block_expr) = stmt::Stmt::from_simple_block(context, block, attrs) { let expr_shape = shape.offset_left(last_line_width(prefix))?; let expr_str = block_expr.rewrite(context, expr_shape)?; - let label_str = rewrite_label(label); + let label_str = rewrite_label(context, label); let result = format!("{prefix}{label_str}{{ {expr_str} }}"); if result.len() <= shape.width && !result.contains('\n') { return Some(result); @@ -562,7 +562,7 @@ pub(crate) fn rewrite_block_with_visitor( } let inner_attrs = attrs.map(inner_attributes); - let label_str = rewrite_label(label); + let label_str = rewrite_label(context, label); visitor.visit_block(block, inner_attrs.as_deref(), has_braces); let visitor_context = visitor.get_context(); context @@ -939,7 +939,7 @@ impl<'a> ControlFlow<'a> { fresh_shape }; - let label_string = rewrite_label(self.label); + let label_string = rewrite_label(context, self.label); // 1 = space after keyword. let offset = self.keyword.len() + label_string.len() + 1; @@ -1168,9 +1168,9 @@ impl<'a> Rewrite for ControlFlow<'a> { } } -fn rewrite_label(opt_label: Option) -> Cow<'static, str> { +fn rewrite_label(context: &RewriteContext<'_>, opt_label: Option) -> Cow<'static, str> { match opt_label { - Some(label) => Cow::from(format!("{}: ", label.ident)), + Some(label) => Cow::from(format!("{}: ", context.snippet(label.ident.span))), None => Cow::from(""), } } diff --git a/src/macros.rs b/src/macros.rs index b14b74a4938..524fc666fae 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1074,7 +1074,7 @@ fn force_space_before(tok: &TokenKind) -> bool { fn ident_like(tok: &Token) -> bool { matches!( tok.kind, - TokenKind::Ident(..) | TokenKind::Literal(..) | TokenKind::Lifetime(_) + TokenKind::Ident(..) | TokenKind::Literal(..) | TokenKind::Lifetime(..) ) } @@ -1099,7 +1099,9 @@ fn next_space(tok: &TokenKind) -> SpaceState { | TokenKind::OpenDelim(_) | TokenKind::CloseDelim(_) => SpaceState::Never, - TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(_) => SpaceState::Ident, + TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(..) => { + SpaceState::Ident + } _ => SpaceState::Always, } diff --git a/src/types.rs b/src/types.rs index 875c61113c5..7730aa467ce 100644 --- a/src/types.rs +++ b/src/types.rs @@ -548,7 +548,7 @@ impl Rewrite for ast::AnonConst { impl Rewrite for ast::Lifetime { fn rewrite(&self, context: &RewriteContext<'_>, _: Shape) -> Option { - Some(rewrite_ident(context, self.ident).to_owned()) + Some(context.snippet(self.ident.span).to_owned()) } } diff --git a/tests/target/raw-lifetimes.rs b/tests/target/raw-lifetimes.rs new file mode 100644 index 00000000000..62fb9be6882 --- /dev/null +++ b/tests/target/raw-lifetimes.rs @@ -0,0 +1,15 @@ +// rustfmt-edition: 2021 + +// Simple idempotence test for raw lifetimes. + +fn test<'r#gen>() -> &'r#gen () { + // Test raw lifetimes... +} + +fn label() { + 'r#label: { + // Test raw labels. + } +} + +fn main() {} From bd5873ae1206127011d7d4918d51ffeab5ce4ac0 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Tue, 10 Sep 2024 01:16:16 -0400 Subject: [PATCH 5/6] bump toolchain to nightly-2024-09-10 --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 7b7081bfe81..80723123274 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-08-17" +channel = "nightly-2024-09-10" components = ["llvm-tools", "rustc-dev"] From d66e974c70ea180e7d7de5ba1c6378e34cd02a7d Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Wed, 11 Sep 2024 23:21:24 -0400 Subject: [PATCH 6/6] remove stray comments --- src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 064b82ff746..898689933e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,6 @@ #![recursion_limit = "256"] #![allow(clippy::match_like_matches_macro)] -// #[macro_use] -// extern crate tracing; - // N.B. these crates are loaded from the sysroot, so they need extern crate. extern crate rustc_ast; extern crate rustc_ast_pretty;