mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
add config inline_attribute_width
If the line width is width within config width, attribute is inline. I don't want to change default rustfmt behavior, so config default value is 0. - fix description - fix test comment - remove unnecessary clone - remove unnecessary test file - fix test for β version - attributes => attribute
This commit is contained in:
parent
7a3b7c9275
commit
0e408bf83c
@ -105,6 +105,9 @@ create_config! {
|
||||
"Minimum number of blank lines which must be put between items";
|
||||
edition: Edition, Edition::Edition2015, true, "The edition of the parser (RFC 2052)";
|
||||
version: Version, Version::One, false, "Version of formatting rules";
|
||||
inline_attribute_width: usize, 0, false,
|
||||
"Write an item and its attribute on the same line \
|
||||
if their combined width is below a threshold";
|
||||
|
||||
// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
|
||||
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
|
||||
|
@ -7,7 +7,7 @@ use syntax::source_map::{self, BytePos, Span, DUMMY_SP};
|
||||
|
||||
use crate::comment::combine_strs_with_missing_comments;
|
||||
use crate::config::lists::*;
|
||||
use crate::config::{Edition, IndentStyle};
|
||||
use crate::config::{Edition, IndentStyle, Version};
|
||||
use crate::lists::{
|
||||
definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
|
||||
};
|
||||
@ -249,7 +249,23 @@ impl UseTree {
|
||||
let lo = attrs.last().as_ref()?.span().hi();
|
||||
let hi = self.span.lo();
|
||||
let span = mk_sp(lo, hi);
|
||||
combine_strs_with_missing_comments(context, &attr_str, &use_str, span, shape, false)
|
||||
|
||||
let allow_extend = if context.config.version() == Version::Two {
|
||||
let line_len = attr_str.len() + 1 + use_str.len();
|
||||
!attrs.first().unwrap().is_sugared_doc
|
||||
&& context.config.inline_attribute_width() >= line_len
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
combine_strs_with_missing_comments(
|
||||
context,
|
||||
&attr_str,
|
||||
&use_str,
|
||||
span,
|
||||
shape,
|
||||
allow_extend,
|
||||
)
|
||||
} else {
|
||||
Some(use_str)
|
||||
}
|
||||
|
48
tests/source/issue-3343.rs
Normal file
48
tests/source/issue-3343.rs
Normal file
@ -0,0 +1,48 @@
|
||||
// rustfmt-inline_attribute_width: 50
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use core::slice;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use total_len_is::_50__;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use total_len_is::_51___;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate len_is_50_;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate len_is_51__;
|
||||
|
||||
/// this is a comment to test is_sugared_doc property
|
||||
use core::convert;
|
||||
|
||||
#[fooooo]
|
||||
#[barrrrr]
|
||||
use total_len_is_::_51______;
|
||||
|
||||
#[cfg(not(all(
|
||||
feature = "std",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)
|
||||
)))]
|
||||
use core::slice;
|
45
tests/target/issue-3343.rs
Normal file
45
tests/target/issue-3343.rs
Normal file
@ -0,0 +1,45 @@
|
||||
// rustfmt-inline_attribute_width: 50
|
||||
|
||||
#[cfg(feature = "alloc")] use core::slice;
|
||||
|
||||
#[cfg(feature = "alloc")] use total_len_is::_50__;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use total_len_is::_51___;
|
||||
|
||||
#[cfg(feature = "alloc")] extern crate len_is_50_;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate len_is_51__;
|
||||
|
||||
/// this is a comment to test is_sugared_doc property
|
||||
use core::convert;
|
||||
|
||||
#[fooooo]
|
||||
#[barrrrr]
|
||||
use total_len_is_::_51______;
|
||||
|
||||
#[cfg(not(all(
|
||||
feature = "std",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)
|
||||
)))]
|
||||
use core::slice;
|
Loading…
Reference in New Issue
Block a user