Skip to content

Commit 4dbeea4

Browse files
authored
Merge branch 'master' into add-edition-2027
2 parents 43fffbd + 6157568 commit 4dbeea4

File tree

13 files changed

+90
-37
lines changed

13 files changed

+90
-37
lines changed

CHANGELOG.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,64 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [1.8.0] 2024-09-20
4+
5+
### Fixed
6+
- Fix issue where rustfmt would crash on Windows when using the `ignore` option [#6178](https://github.com/rust-lang/rustfmt/issues/6178)
7+
8+
### Changed
9+
- `rustfmt --version` now prints a commit hash that is 10 characters long [#6258](https://github.com/rust-lang/rustfmt/pull/6258)
10+
- `rustfmt --version` will no longer print empty git information when git information isn't available at build time.
11+
For example, git information is not available when building rustfmt from a source tarball [#6266](https://github.com/rust-lang/rustfmt/pull/6266)
12+
- `version` has been soft deprecated and replaced by `style_edition`.
13+
`style_edition=2024` is equivalent to `version=Two` and `style_edition={2015|2018|2021}`
14+
are equivalent to `version=One` [#6247](https://github.com/rust-lang/rustfmt/pull/6247)
15+
- When `style_edition=2024` is configured `overflow_delimited_expr` will default to `true` [#6260](https://github.com/rust-lang/rustfmt/pull/6260).
16+
```rust
17+
// with style_edition=2015
18+
do_thing(
19+
x,
20+
Bar {
21+
x: value,
22+
y: value2,
23+
},
24+
);
25+
26+
// with style_edition=2024
27+
do_thing(x, Bar {
28+
x: value,
29+
y: value2,
30+
});
31+
```
32+
- When `style_edition=2024` is configured rustfmt will apply the [style guide's version sorting algorithm]
33+
when sorting imports [#6284](https://github.com/rust-lang/rustfmt/pull/6284)
34+
```rust
35+
// with style_edition=2015
36+
use std::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8};
37+
38+
// with style_edition=2024
39+
use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64};
40+
```
41+
[style guide's version sorting algorithm]: https://doc.rust-lang.org/nightly/style-guide/#sorting
42+
- When parsing rustfmt configurations fails, rustfmt will now include the path to the toml file in the erorr message [#6302](https://github.com/rust-lang/rustfmt/issues/6302)
43+
44+
### Added
45+
- rustfmt now formats trailing where clauses in type aliases [#5887](https://github.com/rust-lang/rustfmt/pull/5887)
46+
```rust
47+
type Foo
48+
= Bar
49+
where
50+
A: B,
51+
C: D;
52+
```
53+
- Users can now configure which `style_edition` rustfmt uses when formatting their code as specified
54+
in [RFC 3338](https://rust-lang.github.io/rfcs/3338-style-evolution.html). Users are encouraged to configure `style_edition`
55+
in their `rustfmt.toml` files, but the value can also be specified via the cli with `--unstable-features --style-edition={style_edition}`.
56+
When `style_edition` is not explicitly configured it will be inferred from the `edition` configuration.
57+
When neither `style_edition` nor `edition` are configured `style_edition` defaults to `2015` [#6247](https://github.com/rust-lang/rustfmt/pull/6247)
58+
59+
### Misc
60+
- Removed `tracing-attributes` dependency [#6208](https://github.com/rust-lang/rustfmt/pull/6208)
61+
- Reduced syn's features in the internal `config_proc_macro` crate [#6237](https://github.com/rust-lang/rustfmt/pull/6237)
462

563
## [1.7.1] 2024-06-24
664

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "rustfmt-nightly"
4-
version = "1.7.1"
4+
version = "1.8.0"
55
description = "Tool to find and fix Rust formatting issues"
66
repository = "https://github.com/rust-lang/rustfmt"
77
readme = "README.md"

src/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,10 @@ fn format(
341341

342342
for file in files {
343343
if !file.exists() {
344-
eprintln!("Error: file `{}` does not exist", file.to_str().unwrap());
344+
eprintln!("Error: file `{}` does not exist", file.display());
345345
session.add_operational_error();
346346
} else if file.is_dir() {
347-
eprintln!("Error: `{}` is a directory", file.to_str().unwrap());
347+
eprintln!("Error: `{}` is a directory", file.display());
348348
session.add_operational_error();
349349
} else {
350350
// Check the file directory if the config-path could not be read or not provided

src/comment.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::{borrow::Cow, iter};
44

5-
use itertools::{MultiPeek, multipeek};
5+
use itertools::{Itertools as _, MultiPeek, multipeek};
66
use rustc_span::Span;
77
use tracing::{debug, trace};
88

@@ -1056,8 +1056,7 @@ fn light_rewrite_comment(
10561056
config: &Config,
10571057
is_doc_comment: bool,
10581058
) -> String {
1059-
let lines: Vec<&str> = orig
1060-
.lines()
1059+
orig.lines()
10611060
.map(|l| {
10621061
// This is basically just l.trim(), but in the case that a line starts
10631062
// with `*` we want to leave one space before it, so it aligns with the
@@ -1075,8 +1074,7 @@ fn light_rewrite_comment(
10751074
// Preserve markdown's double-space line break syntax in doc comment.
10761075
trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment)
10771076
})
1078-
.collect();
1079-
lines.join(&format!("\n{}", offset.to_string(config)))
1077+
.join(&format!("\n{}", offset.to_string(config)))
10801078
}
10811079

10821080
/// Trims comment characters and possibly a single space from the left of a string.

src/config/file_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl From<rustc_span::FileName> for FileName {
3838
impl fmt::Display for FileName {
3939
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4040
match self {
41-
FileName::Real(p) => write!(f, "{}", p.to_str().unwrap()),
41+
FileName::Real(p) => write!(f, "{}", p.display()),
4242
FileName::Stdin => write!(f, "<stdin>"),
4343
}
4444
}

src/config/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,10 +1049,10 @@ make_backup = false
10491049
max_width = 100
10501050
"#;
10511051
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
1052-
assert_eq!(config.array_width(), usize::max_value());
1053-
assert_eq!(config.attr_fn_like_width(), usize::max_value());
1054-
assert_eq!(config.chain_width(), usize::max_value());
1055-
assert_eq!(config.fn_call_width(), usize::max_value());
1052+
assert_eq!(config.array_width(), usize::MAX);
1053+
assert_eq!(config.attr_fn_like_width(), usize::MAX);
1054+
assert_eq!(config.chain_width(), usize::MAX);
1055+
assert_eq!(config.fn_call_width(), usize::MAX);
10561056
assert_eq!(config.single_line_if_else_max_width(), 0);
10571057
assert_eq!(config.struct_lit_width(), 0);
10581058
assert_eq!(config.struct_variant_width(), 0);

src/config/options.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ impl WidthHeuristics {
255255
// Using this WidthHeuristics means we ignore heuristics.
256256
pub fn null() -> WidthHeuristics {
257257
WidthHeuristics {
258-
fn_call_width: usize::max_value(),
259-
attr_fn_like_width: usize::max_value(),
258+
fn_call_width: usize::MAX,
259+
attr_fn_like_width: usize::MAX,
260260
struct_lit_width: 0,
261261
struct_variant_width: 0,
262-
array_width: usize::max_value(),
263-
chain_width: usize::max_value(),
262+
array_width: usize::MAX,
263+
chain_width: usize::MAX,
264264
single_line_if_else_max_width: 0,
265265
single_line_let_else_max_width: 0,
266266
}

src/emitter/json.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use crate::rustfmt_diff::{DiffLine, Mismatch, make_diff};
33
use serde::Serialize;
4-
use serde_json::to_string as to_json_string;
4+
use serde_json::to_writer as to_json_writer;
55

66
#[derive(Debug, Default)]
77
pub(crate) struct JsonEmitter {
@@ -26,7 +26,8 @@ struct MismatchedFile {
2626

2727
impl Emitter for JsonEmitter {
2828
fn emit_footer(&self, output: &mut dyn Write) -> Result<(), io::Error> {
29-
writeln!(output, "{}", &to_json_string(&self.mismatched_files)?)
29+
to_json_writer(&mut *output, &self.mismatched_files)?;
30+
writeln!(output)
3031
}
3132

3233
fn emit_formatted_file(
@@ -56,7 +57,7 @@ impl JsonEmitter {
5657
filename: &FileName,
5758
diff: Vec<Mismatch>,
5859
) -> Result<(), io::Error> {
59-
let mut mismatches = vec![];
60+
let mut mismatches = Vec::with_capacity(diff.len());
6061
for mismatch in diff {
6162
let original_begin_line = mismatch.line_number_orig;
6263
let expected_begin_line = mismatch.line_number;
@@ -252,7 +253,7 @@ mod tests {
252253
)
253254
.unwrap();
254255
let _ = emitter.emit_footer(&mut writer);
255-
let exp_json = to_json_string(&vec![MismatchedFile {
256+
let exp_json = serde_json::to_string(&vec![MismatchedFile {
256257
name: String::from(file_name),
257258
mismatches: vec![
258259
MismatchedBlock {
@@ -338,7 +339,7 @@ mod tests {
338339
}],
339340
};
340341

341-
let exp_json = to_json_string(&vec![exp_bin, exp_lib]).unwrap();
342+
let exp_json = serde_json::to_string(&vec![exp_bin, exp_lib]).unwrap();
342343
assert_eq!(&writer[..], format!("{exp_json}\n").as_bytes());
343344
}
344345
}

src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ fn rewrite_int_lit(
13301330
format!(
13311331
"0x{}{}",
13321332
hex_lit,
1333-
token_lit.suffix.map_or(String::new(), |s| s.to_string())
1333+
token_lit.suffix.as_ref().map_or("", |s| s.as_str())
13341334
),
13351335
context.config.max_width(),
13361336
shape,

src/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,9 +1163,9 @@ pub(crate) fn convert_try_mac(
11631163

11641164
pub(crate) fn macro_style(mac: &ast::MacCall, context: &RewriteContext<'_>) -> Delimiter {
11651165
let snippet = context.snippet(mac.span());
1166-
let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::max_value());
1167-
let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::max_value());
1168-
let brace_pos = snippet.find_uncommented("{").unwrap_or(usize::max_value());
1166+
let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::MAX);
1167+
let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::MAX);
1168+
let brace_pos = snippet.find_uncommented("{").unwrap_or(usize::MAX);
11691169

11701170
if paren_pos < bracket_pos && paren_pos < brace_pos {
11711171
Delimiter::Parenthesis

src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(crate) fn rewrite_string<'a>(
8484
stripped_str
8585
.len()
8686
.checked_next_power_of_two()
87-
.unwrap_or(usize::max_value()),
87+
.unwrap_or(usize::MAX),
8888
);
8989
result.push_str(fmt.opener);
9090

src/test/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ fn is_file_skip(path: &Path) -> bool {
105105
fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
106106
let mut files = vec![];
107107
if path.is_dir() {
108-
for entry in fs::read_dir(path).expect(&format!(
109-
"couldn't read directory {}",
110-
path.to_str().unwrap()
111-
)) {
108+
for entry in
109+
fs::read_dir(path).expect(&format!("couldn't read directory {}", path.display()))
110+
{
112111
let entry = entry.expect("couldn't get `DirEntry`");
113112
let path = entry.path();
114113
if path.is_dir() && recursive {
@@ -122,10 +121,7 @@ fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
122121
}
123122

124123
fn verify_config_used(path: &Path, config_name: &str) {
125-
for entry in fs::read_dir(path).expect(&format!(
126-
"couldn't read {} directory",
127-
path.to_str().unwrap()
128-
)) {
124+
for entry in fs::read_dir(path).expect(&format!("couldn't read {} directory", path.display())) {
129125
let entry = entry.expect("couldn't get directory entry");
130126
let path = entry.path();
131127
if path.extension().map_or(false, |f| f == "rs") {

0 commit comments

Comments
 (0)