Skip to content

prepare v1.4.30 release #4605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

## [Unreleased]

## [1.4.30] 2020-12-20

### Fixed
- Last character in derive no longer erroneously stripped when `indent_style` is overridden to `Visual`. ([#4584](https://github.com/rust-lang/rustfmt/issues/4584))
- Brace wrapping of closure bodies maintained in cases where the closure has an explicit return type and the body consists of a single expression statement. ([#4577](https://github.com/rust-lang/rustfmt/issues/4577))
- No more panics on invalid code with `err` and `typeof` types ([#4357](https://github.com/rust-lang/rustfmt/issues/4357), [#4586](https://github.com/rust-lang/rustfmt/issues/4586))

### Install/Download Options
- **crates.io package** - *pending*
- **rustup (nightly)** - *pending*
- **GitHub Release Binaries** - [Release v1.4.30](https://github.com/rust-lang/rustfmt/releases/tag/v1.4.30)
- **Build from source** - [Tag v1.4.30](https://github.com/rust-lang/rustfmt/tree/v1.4.30), see instructions for how to [install rustfmt from source][install-from-source]

## [1.4.29] 2020-12-04

### Fixed
- Negative polarity on non-trait impl now preserved. ([#4566](https://github.com/rust-lang/rustfmt/issues/4566))

### Install/Download Options
- **crates.io package** - *pending*
- **rustup (nightly)** - *pending*
- **rustup (nightly)** - Starting in `2020-12-07`
- **GitHub Release Binaries** - [Release v1.4.29](https://github.com/rust-lang/rustfmt/releases/tag/v1.4.29)
- **Build from source** - [Tag v1.4.29](https://github.com/rust-lang/rustfmt/tree/v1.4.29), see instructions for how to [install rustfmt from source][install-from-source]

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "rustfmt-nightly"
version = "1.4.29"
version = "1.4.30"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang/rustfmt"
Expand Down
4 changes: 3 additions & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ fn format_derive(
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
// Retain the trailing comma.
result.push_str(&item_str);
} else {
} else if item_str.ends_with(",") {
// Remove the trailing comma.
result.push_str(&item_str[..item_str.len() - 1]);
} else {
result.push_str(&item_str);
}
result.push_str(")]");

Expand Down
23 changes: 13 additions & 10 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,21 @@ pub(crate) fn rewrite_last_closure(
if is_block_closure_forced(context, body) {
return rewrite_closure_with_block(body, &prefix, context, body_shape).and_then(
|body_str| {
// If the expression can fit in a single line, we need not force block closure.
if body_str.lines().count() <= 7 {
match rewrite_closure_expr(body, &prefix, context, shape) {
Some(ref single_line_body_str)
if !single_line_body_str.contains('\n') =>
{
Some(single_line_body_str.clone())
match fn_decl.output {
ast::FnRetTy::Default(..) if body_str.lines().count() <= 7 => {
// If the expression can fit in a single line, we need not force block
// closure. However, if the closure has a return type, then we must
// keep the blocks.
match rewrite_closure_expr(body, &prefix, context, shape) {
Some(ref single_line_body_str)
if !single_line_body_str.contains('\n') =>
{
Some(single_line_body_str.clone())
}
_ => Some(body_str),
}
_ => Some(body_str),
}
} else {
Some(body_str)
_ => Some(body_str),
}
},
);
Expand Down
13 changes: 11 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use rustc_span::{symbol::kw, BytePos, Pos, Span};
use crate::comment::{combine_strs_with_missing_comments, contains_comment};
use crate::config::lists::*;
use crate::config::{IndentStyle, TypeDensity, Version};
use crate::expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType};
use crate::expr::{
format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType,
};
use crate::lists::{
definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
};
Expand Down Expand Up @@ -797,7 +799,14 @@ impl Rewrite for ast::Ty {
})
}
ast::TyKind::CVarArgs => Some("...".to_owned()),
ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
ast::TyKind::Err => Some(context.snippet(self.span).to_owned()),
ast::TyKind::Typeof(ref anon_const) => rewrite_call(
context,
"typeof",
&[anon_const.value.clone()],
self.span,
shape,
),
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/source/issue-4577.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fn main() {
let s: String = "ABAABBAA".chars()
.filter(|c| {
if *c == 'A' {
true
}
else {
false
}
})
.map(|c| -> char {
if c == 'A' {
'0'
} else {
'1'
}
}).collect();

println!("{}", s);
}
19 changes: 19 additions & 0 deletions tests/source/issue_4584.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// rustfmt-indent_style: Visual

#[derive(Debug,)]
pub enum Case {
Upper,
Lower
}

#[derive(Debug, Clone, PartialEq, Eq,)]
pub enum Case {
Upper,
Lower
}

// NB - This formatting looks potentially off the desired state, but is
// consistent with current behavior. Included here to provide a line wrapped
// derive case with the changes applied to resolve issue #4584
#[derive(Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize, Mul,)]
struct Foo {}
6 changes: 6 additions & 0 deletions tests/source/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,9 @@ impl<T: ? const Trait> Foo<T> {
Self(t)
}
}

// #4357
type T = typeof(
1);
impl T for .. {
}
15 changes: 15 additions & 0 deletions tests/target/issue-4577.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
let s: String = "ABAABBAA"
.chars()
.filter(|c| if *c == 'A' { true } else { false })
.map(|c| -> char {
if c == 'A' {
'0'
} else {
'1'
}
})
.collect();

println!("{}", s);
}
32 changes: 32 additions & 0 deletions tests/target/issue_4584.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// rustfmt-indent_style: Visual

#[derive(Debug)]
pub enum Case {
Upper,
Lower,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Case {
Upper,
Lower,
}

// NB - This formatting looks potentially off the desired state, but is
// consistent with current behavior. Included here to provide a line wrapped
// derive case with the changes applied to resolve issue #4584
#[derive(Add,
Sub,
Mul,
Div,
Clone,
Copy,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Hash,
Serialize,
Mul)]
struct Foo {}
4 changes: 4 additions & 0 deletions tests/target/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,7 @@ impl<T: ?const Trait> Foo<T> {
Self(t)
}
}

// #4357
type T = typeof(1);
impl T for .. {}