Skip to content

Commit

Permalink
Merge pull request #6320 from ytmimi/subtree-push-nightly-2024-09-10
Browse files Browse the repository at this point in the history
subtree-push nightly-2024-09-10
  • Loading branch information
ytmimi committed Sep 12, 2024
2 parents 182a203 + d66e974 commit a1017ae
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 20 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-08-17"
channel = "nightly-2024-09-10"
components = ["llvm-tools", "rustc-dev"]
1 change: 1 addition & 0 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use rustc_ast::HasAttrs;
use rustc_ast::ast;
use rustc_span::{Span, symbol::sym};
use tracing::debug;

use self::doc_comment::DocCommentFormatter;
use crate::comment::{CommentStyle, contains_comment, rewrite_doc_comment};
Expand Down
1 change: 1 addition & 0 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use std::cmp::min;

use rustc_ast::{ast, ptr};
use rustc_span::{BytePos, Span, symbol};
use tracing::debug;

use crate::comment::{CharClasses, FullCodeCharKind, RichChar, rewrite_comment};
use crate::config::{IndentStyle, StyleEdition};
Expand Down
1 change: 1 addition & 0 deletions src/closures.rs
Original file line number Diff line number Diff line change
@@ -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::StyleEdition;
Expand Down
1 change: 1 addition & 0 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, RewriteErrorExt, RewriteResult};
Expand Down
13 changes: 7 additions & 6 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use itertools::Itertools;
use rustc_ast::token::{Delimiter, Lit, LitKind};
use rustc_ast::{ForLoopKind, MatchKind, ast, ptr, token};
use rustc_span::{BytePos, Span};
use tracing::debug;

use crate::chains::rewrite_chain;
use crate::closures;
Expand Down Expand Up @@ -467,7 +468,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;
}
Expand Down Expand Up @@ -537,7 +538,7 @@ fn rewrite_single_line_block(
.offset_left(last_line_width(prefix))
.max_width_error(shape.width, block_expr.span())?;
let expr_str = block_expr.rewrite_result(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 Ok(result);
Expand Down Expand Up @@ -572,7 +573,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
Expand Down Expand Up @@ -956,7 +957,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;

Expand Down Expand Up @@ -1189,9 +1190,9 @@ impl<'a> Rewrite for ControlFlow<'a> {
}
}

fn rewrite_label(opt_label: Option<ast::Label>) -> Cow<'static, str> {
fn rewrite_label(context: &RewriteContext<'_>, opt_label: Option<ast::Label>) -> 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(""),
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/format-diff/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 1 addition & 3 deletions src/git-rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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::{
Expand Down
1 change: 1 addition & 0 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use regex::Regex;
use rustc_ast::visit;
use rustc_ast::{ast, ptr};
use rustc_span::{BytePos, DUMMY_SP, Span, symbol};
use tracing::debug;

use crate::attr::filter_inline_attrs;
use crate::comment::{
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc_span::{
BytePos, DUMMY_SP, Span, Symbol,
symbol::{self, kw},
};
use tracing::debug;

use crate::comment::{
CharClasses, FindUncommented, FullCodeCharKind, LineClasses, contains_comment,
Expand Down Expand Up @@ -1104,7 +1105,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(..)
)
}

Expand All @@ -1129,7 +1130,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,
}
Expand Down
1 change: 1 addition & 0 deletions src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::iter::repeat;

use rustc_ast::{MatchKind, ast, ptr};
use rustc_span::{BytePos, Span};
use tracing::debug;

use crate::comment::{FindUncommented, combine_strs_with_missing_comments, rewrite_comment};
use crate::config::lists::*;
Expand Down
1 change: 1 addition & 0 deletions src/missed_spans.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_span::{BytePos, Pos, Span};
use tracing::debug;

use crate::comment::{CodeCharKind, CommentCodeSlices, is_last_comment_block, rewrite_comment};
use crate::config::FileName;
Expand Down
1 change: 1 addition & 0 deletions src/modules/visitor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::StyleEdition;
Expand Down
1 change: 1 addition & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
};

use rustfmt_config_proc_macro::nightly_only_test;
use tracing::{debug, warn};

mod configuration_snippet;
mod mod_resolver;
Expand Down
3 changes: 2 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ops::Deref;
use rustc_ast::ast::{self, FnRetTy, Mutability, Term};
use rustc_ast::ptr;
use rustc_span::{BytePos, Pos, Span, symbol::kw};
use tracing::debug;

use crate::comment::{combine_strs_with_missing_comments, contains_comment};
use crate::config::lists::*;
Expand Down Expand Up @@ -598,7 +599,7 @@ impl Rewrite for ast::Lifetime {
}

fn rewrite_result(&self, context: &RewriteContext<'_>, _: Shape) -> RewriteResult {
Ok(rewrite_ident(context, self.ident).to_owned())
Ok(context.snippet(self.ident.span).to_owned())
}
}

Expand Down
1 change: 1 addition & 0 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::rc::Rc;
use rustc_ast::{ast, token::Delimiter, visit};
use rustc_data_structures::sync::Lrc;
use rustc_span::{BytePos, Pos, Span, symbol};
use tracing::debug;

use crate::attr::*;
use crate::comment::{CodeCharKind, CommentCodeSlices, contains_comment, rewrite_comment};
Expand Down
15 changes: 15 additions & 0 deletions tests/target/raw-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -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() {}
1 change: 0 additions & 1 deletion tests/target/unsafe_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(unsafe_attributes)]
// https://github.com/rust-lang/rust/issues/123757
//
#![simple_ident]
Expand Down

0 comments on commit a1017ae

Please sign in to comment.