mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 04:55:22 +03:00
Make trace! formatting consistent with other log macros (#5989)
Fixes 5987 rustfmt already special cases the formatting for the `debug!`, `info!`, `warn!`, and `error!`, macros from the `log` crate. However, this speical case handling did not apply to the `trace!` macro. Now when using `Version=Two` rustfmt will also special case the formatting for the `trace!` macro.
This commit is contained in:
+1
-4
@@ -173,10 +173,7 @@ pub(crate) fn combine_strs_with_missing_comments(
|
||||
) -> Option<String> {
|
||||
trace!(
|
||||
"combine_strs_with_missing_comments `{}` `{}` {:?} {:?}",
|
||||
prev_str,
|
||||
next_str,
|
||||
span,
|
||||
shape
|
||||
prev_str, next_str, span, shape
|
||||
);
|
||||
|
||||
let mut result =
|
||||
|
||||
+19
-7
@@ -8,8 +8,8 @@
|
||||
use rustc_span::Span;
|
||||
|
||||
use crate::closures;
|
||||
use crate::config::lists::*;
|
||||
use crate::config::Version;
|
||||
use crate::config::{lists::*, Config};
|
||||
use crate::expr::{
|
||||
can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr,
|
||||
rewrite_cond,
|
||||
@@ -60,6 +60,13 @@
|
||||
("debug_assert_ne!", 2),
|
||||
];
|
||||
|
||||
/// Additional special case macros for version 2; these are separated to avoid breaking changes in
|
||||
/// version 1.
|
||||
const SPECIAL_CASE_MACROS_V2: &[(&str, usize)] = &[
|
||||
// From the `log` crate.
|
||||
("trace!", 0),
|
||||
];
|
||||
|
||||
const SPECIAL_CASE_ATTR: &[(&str, usize)] = &[
|
||||
// From the `failure` crate.
|
||||
("fail", 0),
|
||||
@@ -182,12 +189,17 @@ pub(crate) fn can_be_overflowed(&self, context: &RewriteContext<'_>, len: usize)
|
||||
}
|
||||
}
|
||||
|
||||
fn special_cases(&self) -> &'static [(&'static str, usize)] {
|
||||
match self {
|
||||
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,
|
||||
_ => &[],
|
||||
}
|
||||
};
|
||||
let additional_cases = match (self, config.version()) {
|
||||
(OverflowableItem::MacroArg(..), Version::Two) => SPECIAL_CASE_MACROS_V2,
|
||||
_ => &[],
|
||||
};
|
||||
base_cases.iter().chain(additional_cases)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +563,7 @@ fn try_overflow_last_item(&self, list_items: &mut Vec<ListItem>) -> DefinitiveLi
|
||||
|
||||
if tactic == DefinitiveListTactic::Vertical {
|
||||
if let Some((all_simple, num_args_before)) =
|
||||
maybe_get_args_offset(self.ident, &self.items)
|
||||
maybe_get_args_offset(self.ident, &self.items, &self.context.config)
|
||||
{
|
||||
let one_line = all_simple
|
||||
&& definitive_tactic(
|
||||
@@ -771,11 +783,11 @@ fn no_long_items(list: &[ListItem], short_array_element_width_threshold: usize)
|
||||
pub(crate) fn maybe_get_args_offset(
|
||||
callee_str: &str,
|
||||
args: &[OverflowableItem<'_>],
|
||||
config: &Config,
|
||||
) -> Option<(bool, usize)> {
|
||||
if let Some(&(_, num_args_before)) = args
|
||||
.get(0)?
|
||||
.special_cases()
|
||||
.iter()
|
||||
.special_cases(config)
|
||||
.find(|&&(s, _)| s == callee_str)
|
||||
{
|
||||
let all_simple = args.len() > num_args_before
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// rustfmt-version: Two
|
||||
|
||||
fn main() {
|
||||
trace!(
|
||||
"get some longer length in here yes yes {} {}",
|
||||
"hello",
|
||||
"world"
|
||||
);
|
||||
debug!(
|
||||
"get some longer length in here yes yes {} {}",
|
||||
"hello", "world"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// rustfmt-version: One
|
||||
|
||||
fn main() {
|
||||
trace!(
|
||||
"get some longer length in here yes yes {} {}",
|
||||
"hello",
|
||||
"world"
|
||||
);
|
||||
debug!(
|
||||
"get some longer length in here yes yes {} {}",
|
||||
"hello", "world"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// rustfmt-version: Two
|
||||
|
||||
fn main() {
|
||||
trace!(
|
||||
"get some longer length in here yes yes {} {}",
|
||||
"hello", "world"
|
||||
);
|
||||
debug!(
|
||||
"get some longer length in here yes yes {} {}",
|
||||
"hello", "world"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user