Merge remote-tracking branch 'upstream/master' into subtree_push_2023_12_12
This commit is contained in:
commit
227e361187
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -343,9 +343,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.10.3"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
|
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# https://github.com/rust-lang/rustfmt/issues/5675
|
|
||||||
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH
|
|
||||||
|
|
||||||
function print_usage() {
|
function print_usage() {
|
||||||
echo "usage check_diff REMOTE_REPO FEATURE_BRANCH [COMMIT_HASH] [OPTIONAL_RUSTFMT_CONFIGS]"
|
echo "usage check_diff REMOTE_REPO FEATURE_BRANCH [COMMIT_HASH] [OPTIONAL_RUSTFMT_CONFIGS]"
|
||||||
}
|
}
|
||||||
@ -114,15 +111,42 @@ function compile_rustfmt() {
|
|||||||
git remote add feature $REMOTE_REPO
|
git remote add feature $REMOTE_REPO
|
||||||
git fetch feature $FEATURE_BRANCH
|
git fetch feature $FEATURE_BRANCH
|
||||||
|
|
||||||
cargo build --release --bin rustfmt && cp target/release/rustfmt $1/rustfmt
|
CARGO_VERSON=$(cargo --version)
|
||||||
|
echo -e "\ncompiling with $CARGO_VERSON\n"
|
||||||
|
|
||||||
|
# Because we're building standalone binaries we need to set `LD_LIBRARY_PATH` so each
|
||||||
|
# binary can find it's runtime dependencies. See https://github.com/rust-lang/rustfmt/issues/5675
|
||||||
|
# This will prepend the `LD_LIBRARY_PATH` for the master rustfmt binary
|
||||||
|
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH
|
||||||
|
|
||||||
|
echo "Building rustfmt from src"
|
||||||
|
cargo build -q --release --bin rustfmt && cp target/release/rustfmt $1/rustfmt
|
||||||
|
|
||||||
if [ -z "$OPTIONAL_COMMIT_HASH" ] || [ "$FEATURE_BRANCH" = "$OPTIONAL_COMMIT_HASH" ]; then
|
if [ -z "$OPTIONAL_COMMIT_HASH" ] || [ "$FEATURE_BRANCH" = "$OPTIONAL_COMMIT_HASH" ]; then
|
||||||
git switch $FEATURE_BRANCH
|
git switch $FEATURE_BRANCH
|
||||||
else
|
else
|
||||||
git switch $OPTIONAL_COMMIT_HASH --detach
|
git switch $OPTIONAL_COMMIT_HASH --detach
|
||||||
fi
|
fi
|
||||||
cargo build --release --bin rustfmt && cp target/release/rustfmt $1/feature_rustfmt
|
|
||||||
|
# This will prepend the `LD_LIBRARY_PATH` for the feature branch rustfmt binary.
|
||||||
|
# In most cases the `LD_LIBRARY_PATH` should be the same for both rustfmt binaries that we build
|
||||||
|
# in `compile_rustfmt`, however, there are scenarios where each binary has different runtime
|
||||||
|
# dependencies. For example, during subtree syncs we bump the nightly toolchain required to build
|
||||||
|
# rustfmt, and therefore the feature branch relies on a newer set of runtime dependencies.
|
||||||
|
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH
|
||||||
|
|
||||||
|
echo "Building feature rustfmt from src"
|
||||||
|
cargo build -q --release --bin rustfmt && cp target/release/rustfmt $1/feature_rustfmt
|
||||||
|
|
||||||
|
echo -e "\nRuntime dependencies for rustfmt -- LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
|
||||||
|
|
||||||
RUSFMT_BIN=$1/rustfmt
|
RUSFMT_BIN=$1/rustfmt
|
||||||
|
RUSTFMT_VERSION=$($RUSFMT_BIN --version)
|
||||||
|
echo -e "\nRUSFMT_BIN $RUSTFMT_VERSION\n"
|
||||||
|
|
||||||
FEATURE_BIN=$1/feature_rustfmt
|
FEATURE_BIN=$1/feature_rustfmt
|
||||||
|
FEATURE_VERSION=$($FEATURE_BIN --version)
|
||||||
|
echo -e "FEATURE_BIN $FEATURE_VERSION\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check the diff for running rustfmt and the feature branch on all the .rs files in the repo.
|
# Check the diff for running rustfmt and the feature branch on all the .rs files in the repo.
|
||||||
@ -155,7 +179,7 @@ function check_repo() {
|
|||||||
STATUSES+=($?)
|
STATUSES+=($?)
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "removing tmp_dir $tmp_dir"
|
echo -e "removing tmp_dir $tmp_dir\n\n"
|
||||||
rm -rf $tmp_dir
|
rm -rf $tmp_dir
|
||||||
cd $WORKDIR
|
cd $WORKDIR
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#[allow(unreachable_pub)]
|
#[allow(unreachable_pub)]
|
||||||
pub(crate) mod lists;
|
pub(crate) mod lists;
|
||||||
pub(crate) mod macro_names;
|
pub(crate) mod macro_names;
|
||||||
|
pub(crate) mod style_edition;
|
||||||
|
|
||||||
// This macro defines configuration options used in rustfmt. Each option
|
// This macro defines configuration options used in rustfmt. Each option
|
||||||
// is defined as follows:
|
// is defined as follows:
|
||||||
|
@ -470,3 +470,27 @@ pub enum MatchArmLeadingPipe {
|
|||||||
/// Preserve any existing leading pipes
|
/// Preserve any existing leading pipes
|
||||||
Preserve,
|
Preserve,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Defines the default values for each config according to [the style guide].
|
||||||
|
/// rustfmt output may differ between style editions.
|
||||||
|
///
|
||||||
|
/// [the style guide]: https://doc.rust-lang.org/nightly/style-guide/
|
||||||
|
#[config_type]
|
||||||
|
pub enum StyleEdition {
|
||||||
|
#[value = "2015"]
|
||||||
|
#[doc_hint = "2015"]
|
||||||
|
/// [Edition 2015]()
|
||||||
|
Edition2015,
|
||||||
|
#[value = "2018"]
|
||||||
|
#[doc_hint = "2018"]
|
||||||
|
/// [Edition 2018]()
|
||||||
|
Edition2018,
|
||||||
|
#[value = "2021"]
|
||||||
|
#[doc_hint = "2021"]
|
||||||
|
/// [Edition 2021]()
|
||||||
|
Edition2021,
|
||||||
|
#[value = "2024"]
|
||||||
|
#[doc_hint = "2024"]
|
||||||
|
/// [Edition 2024]().
|
||||||
|
Edition2024,
|
||||||
|
}
|
||||||
|
69
src/config/style_edition.rs
Normal file
69
src/config/style_edition.rs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
use crate::config::StyleEdition;
|
||||||
|
|
||||||
|
/// Defines the default value for the given style edition
|
||||||
|
pub(crate) trait StyleEditionDefault {
|
||||||
|
type ConfigType;
|
||||||
|
fn style_edition_default(style_edition: StyleEdition) -> Self::ConfigType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// macro to help implement `StyleEditionDefault` for config options
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! style_edition_default {
|
||||||
|
($ty:ident, $config_ty:ty, _ => $default:expr) => {
|
||||||
|
impl $crate::config::style_edition::StyleEditionDefault for $ty {
|
||||||
|
type ConfigType = $config_ty;
|
||||||
|
|
||||||
|
fn style_edition_default(_: $crate::config::StyleEdition) -> Self::ConfigType {
|
||||||
|
$default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
($ty:ident, $config_ty:ty, Edition2024 => $default_2024:expr, _ => $default_2015:expr) => {
|
||||||
|
impl $crate::config::style_edition::StyleEditionDefault for $ty {
|
||||||
|
type ConfigType = $config_ty;
|
||||||
|
|
||||||
|
fn style_edition_default(
|
||||||
|
style_edition: $crate::config::StyleEdition,
|
||||||
|
) -> Self::ConfigType {
|
||||||
|
match style_edition {
|
||||||
|
$crate::config::StyleEdition::Edition2015
|
||||||
|
| $crate::config::StyleEdition::Edition2018
|
||||||
|
| $crate::config::StyleEdition::Edition2021 => $default_2015,
|
||||||
|
$crate::config::StyleEdition::Edition2024 => $default_2024,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use crate::config::StyleEdition;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_impl_default_style_edition_struct_for_all_editions() {
|
||||||
|
struct Unit;
|
||||||
|
style_edition_default!(Unit, usize, _ => 100);
|
||||||
|
|
||||||
|
// regardless of the style edition used the value will always return 100
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2015), 100);
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2018), 100);
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2021), 100);
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2024), 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_impl_default_style_edition_for_old_and_new_editions() {
|
||||||
|
struct Unit;
|
||||||
|
style_edition_default!(Unit, usize, Edition2024 => 50, _ => 100);
|
||||||
|
|
||||||
|
// style edition 2015-2021 are all the same
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2015), 100);
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2018), 100);
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2021), 100);
|
||||||
|
|
||||||
|
// style edition 2024
|
||||||
|
assert_eq!(Unit::style_edition_default(StyleEdition::Edition2024), 50);
|
||||||
|
}
|
||||||
|
}
|
10
src/items.rs
10
src/items.rs
@ -832,13 +832,15 @@ pub(crate) fn format_impl(
|
|||||||
|
|
||||||
if is_impl_single_line(context, items.as_slice(), &result, &where_clause_str, item)? {
|
if is_impl_single_line(context, items.as_slice(), &result, &where_clause_str, item)? {
|
||||||
result.push_str(&where_clause_str);
|
result.push_str(&where_clause_str);
|
||||||
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
|
if where_clause_str.contains('\n') {
|
||||||
// if the where_clause contains extra comments AND
|
// If there is only one where-clause predicate
|
||||||
// there is only one where-clause predicate
|
// and the where-clause spans multiple lines,
|
||||||
// recover the suppressed comma in single line where_clause formatting
|
// then recover the suppressed comma in single line where-clause formatting
|
||||||
if generics.where_clause.predicates.len() == 1 {
|
if generics.where_clause.predicates.len() == 1 {
|
||||||
result.push(',');
|
result.push(',');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
|
||||||
result.push_str(&format!("{sep}{{{sep}}}"));
|
result.push_str(&format!("{sep}{{{sep}}}"));
|
||||||
} else {
|
} else {
|
||||||
result.push_str(" {}");
|
result.push_str(" {}");
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#![warn(unreachable_pub)]
|
#![warn(unreachable_pub)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(clippy::match_like_matches_macro)]
|
#![allow(clippy::match_like_matches_macro)]
|
||||||
#![allow(unreachable_pub)]
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -451,8 +451,8 @@ fn rewrite_match_body(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let block_sep = match context.config.control_brace_style() {
|
let block_sep = match context.config.control_brace_style() {
|
||||||
ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix),
|
|
||||||
_ if body_prefix.is_empty() => "".to_owned(),
|
_ if body_prefix.is_empty() => "".to_owned(),
|
||||||
|
ControlBraceStyle::AlwaysNextLine => format!("{}{}", alt_block_sep, body_prefix),
|
||||||
_ if forbid_same_line || !arrow_comment.is_empty() => {
|
_ if forbid_same_line || !arrow_comment.is_empty() => {
|
||||||
format!("{}{}", alt_block_sep, body_prefix)
|
format!("{}{}", alt_block_sep, body_prefix)
|
||||||
}
|
}
|
||||||
|
@ -184,3 +184,19 @@ fn dont_emit_ICE() {
|
|||||||
assert!(!stderr.contains("thread 'main' panicked"));
|
assert!(!stderr.contains("thread 'main' panicked"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rustfmt_emits_error_when_control_brace_style_is_always_next_line() {
|
||||||
|
// See also https://github.com/rust-lang/rustfmt/issues/5912
|
||||||
|
let args = [
|
||||||
|
"--config=color=Never",
|
||||||
|
"--config",
|
||||||
|
"control_brace_style=AlwaysNextLine",
|
||||||
|
"--config",
|
||||||
|
"match_arm_blocks=false",
|
||||||
|
"tests/target/issue_5912.rs",
|
||||||
|
];
|
||||||
|
|
||||||
|
let (_stdout, stderr) = rustfmt(&args);
|
||||||
|
assert!(!stderr.contains("error[internal]: left behind trailing whitespace"))
|
||||||
|
}
|
||||||
|
15
tests/source/issue_5912.rs
Normal file
15
tests/source/issue_5912.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// rustfmt-match_arm_blocks: false
|
||||||
|
// rustfmt-control_brace_style: AlwaysNextLine
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
match 0 {
|
||||||
|
0 => {
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
}
|
||||||
|
_ => 2,
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,11 @@ impl<T> Foo for T
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #5941
|
||||||
|
impl T where (): Clone // Should not add comma to comment
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// #1823
|
// #1823
|
||||||
default impl Trait for X {}
|
default impl Trait for X {}
|
||||||
default unsafe impl Trait for Y {}
|
default unsafe impl Trait for Y {}
|
||||||
|
15
tests/target/issue_5912.rs
Normal file
15
tests/target/issue_5912.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// rustfmt-match_arm_blocks: false
|
||||||
|
// rustfmt-control_brace_style: AlwaysNextLine
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
match 0
|
||||||
|
{
|
||||||
|
0 =>
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
+ bbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||||
|
_ => 2,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user