Skip to content

Commit 00dc215

Browse files
authored
Merge branch 'master' into issue-6470-dont-delete-white-space-on-triple-colon
2 parents 518ae6a + 0332da0 commit 00dc215

File tree

9 files changed

+91
-9
lines changed

9 files changed

+91
-9
lines changed

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
6+
## [1.9.0] 2025-01-03
7+
8+
### Fixed
9+
- No longer strip `r#` prefix from `break` and `continue` labels [#6411](https://github.com/rust-lang/rustfmt/issues/6411)
10+
```rust
11+
fn main() {
12+
'r#if: {
13+
break 'r#if;
14+
}
15+
}
16+
```
17+
- Fix panic when sorting imports [#6333](https://github.com/rust-lang/rustfmt/issues/6333)
18+
- Fix issue with `wrap_comments` invalidating code blocks [#6417](https://github.com/rust-lang/rustfmt/pull/6417)
19+
- No longer remove closure block label within a macro call [#6465](https://github.com/rust-lang/rustfmt/issues/6465)
20+
21+
### Changed
22+
- Stabilize `style_edition=2024` and stabilize the `style_edition` command line option [#6431](https://github.com/rust-lang/rustfmt/pull/6431) [rust-lang/rust#134929](https://github.com/rust-lang/rust/pull/134929)
23+
- Apply version sorting to module declarations when using `style_edition=2024` [#6368](https://github.com/rust-lang/rustfmt/pull/6368)
24+
- When users set the deprecated `version` config, rustfmt now gives a hint about which equivalent `style_edition` they should use [#6361](https://github.com/rust-lang/rustfmt/pull/6361)
25+
- Correct version chunk splitting in the internal version sort algorithm [#6407](https://github.com/rust-lang/rustfmt/pull/6407)
26+
- Extend support for single line let-chain formatting to include cases where the left hand side operand is a literal, in alignment with finalized style rules as part of let-chain stabilization [#6492](https://github.com/rust-lang/rustfmt/pull/6492)
27+
- Begin initial formatting for `use closures` and `use chains` (`#![feature(ergonomic_clones)]`). Previously, the closure and chain was left as the developer wrote it [#6532](https://github.com/rust-lang/rustfmt/pull/6532)
28+
29+
### Added
30+
- Add `style_edition=2027` to gate unstable formatting [#6324](https://github.com/rust-lang/rustfmt/pull/6324)
31+
- Support discovering and formatting files via external mods imported within `cfg_match`, similar to `cfg_if` behavior [#6522](https://github.com/rust-lang/rustfmt/pull/6522)
32+
- Add new nightly-only `match_arm_indent` option [#6525](https://github.com/rust-lang/rustfmt/pull/6525)
33+
- more details in the [configuration section for this new option](https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#match_arm_indent)
34+
35+
336
## [1.8.0] 2024-09-20
437

538
### Fixed

Configurations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ fn example() {
22452245

22462246
Remove nested parens.
22472247

2248-
- **Default value**: `true`,
2248+
- **Default value**: `true`
22492249
- **Possible values**: `true`, `false`
22502250
- **Stable**: Yes
22512251

@@ -3046,6 +3046,7 @@ fn main() {
30463046
let y = 2;
30473047
let z = 3;
30483048
let a = Foo { x, y, z };
3049+
let b = Foo { x, y, z };
30493050
}
30503051
```
30513052

src/cargo-fmt/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use std::cmp::Ordering;
77
use std::collections::{BTreeMap, BTreeSet};
88
use std::env;
9-
use std::ffi::OsStr;
109
use std::fs;
1110
use std::hash::{Hash, Hasher};
1211
use std::io::{self, Write};
@@ -151,11 +150,13 @@ fn execute() -> i32 {
151150
}
152151

153152
fn rustfmt_command() -> Command {
154-
let rustfmt_var = env::var_os("RUSTFMT");
155-
let rustfmt = match &rustfmt_var {
156-
Some(rustfmt) => rustfmt,
157-
None => OsStr::new("rustfmt"),
153+
let rustfmt = match env::var_os("RUSTFMT") {
154+
Some(rustfmt) => PathBuf::from(rustfmt),
155+
None => env::current_exe()
156+
.expect("current executable path invalid")
157+
.with_file_name("rustfmt"),
158158
};
159+
159160
Command::new(rustfmt)
160161
}
161162

src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,11 @@ fn rewrite_let(
20222022
// TODO(ytmimi) comments could appear between `let` and the `pat`
20232023

20242024
// 4 = "let ".len()
2025-
let pat_shape = shape.offset_left(4, pat.span)?;
2025+
let mut pat_shape = shape.offset_left(4, pat.span)?;
2026+
if context.config.style_edition() >= StyleEdition::Edition2027 {
2027+
// 2 for the length of " ="
2028+
pat_shape = pat_shape.sub_width(2, pat.span)?;
2029+
}
20262030
let pat_str = pat.rewrite_result(context, pat_shape)?;
20272031
result.push_str(&pat_str);
20282032

src/imports.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,13 @@ impl UseTree {
566566

567567
// Normalise foo::self -> foo.
568568
if let UseSegmentKind::Slf(None) = last.kind {
569-
if !self.path.is_empty() {
570-
return self;
569+
if let Some(second_last) = self.path.pop() {
570+
if matches!(second_last.kind, UseSegmentKind::Slf(_)) {
571+
self.path.push(second_last);
572+
} else {
573+
self.path.push(second_last);
574+
return self;
575+
}
571576
}
572577
}
573578

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// max_width = 120
2+
// error_on_line_overflow = true
3+
// style_edition = "2027"
4+
5+
impl EarlyLintPass for NeedlessContinue {
6+
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
7+
if let ExprKind::Loop(body, label, ..) | ExprKind::While(_, body, label) | ExprKind::ForLoop { body, label, .. } =
8+
&expr.kind
9+
&& !in_external_macro(cx.sess, expr.span)
10+
{
11+
check_final_block_stmt(cx, body, label, expr.span.ctxt());
12+
}
13+
}
14+
}

tests/source/issue_6558.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Removing `self::self` breaks idempotence, leaving it causes a compilation error
2+
// which the user should be made aware of #6558
3+
use self;
4+
use self::self;
5+
use self::self::self;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// max_width = 120
2+
// error_on_line_overflow = true
3+
// style_edition = "2027"
4+
5+
impl EarlyLintPass for NeedlessContinue {
6+
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
7+
if let ExprKind::Loop(body, label, ..)
8+
| ExprKind::While(_, body, label)
9+
| ExprKind::ForLoop { body, label, .. } = &expr.kind
10+
&& !in_external_macro(cx.sess, expr.span)
11+
{
12+
check_final_block_stmt(cx, body, label, expr.span.ctxt());
13+
}
14+
}
15+
}

tests/target/issue_6558.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Removing `self::self` breaks idempotence, leaving it causes a compilation error
2+
// which the user should be made aware of #6558
3+
use self::self;
4+
use self::self::self;

0 commit comments

Comments
 (0)