diff --git a/CHANGELOG.md b/CHANGELOG.md index 454ffc1a91c..b28723aa08e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,34 @@ ## [Unreleased] -### Changed -- The unstable `required_version` configuration option now defaults to a caret (`^`) semver requirement instead of an exact match when no comparator is given, matching how Cargo treats dependency version requirements. Use the explicit `=` operator (e.g. `required_version = "=1.2.3"`) to opt back into exact matching [#6729](https://github.com/rust-lang/rustfmt/issues/6729) + +## [1.12.0] 2026-12-24 +### Changed +- The unstable `required_version` configuration option now defaults to a caret (`^`) semver requirement instead of an exact match when no comparator is given, matching how Cargo treats dependency version requirements. Use the explicit `=` operator (e.g. `required_version = "=1.2.3"`) to opt back into exact matching [#6729](https://github.com/rust-lang/rustfmt/issues/6729) [#7048](https://github.com/rust-lang/rustfmt/pull/7048) +> [!IMPORTANT] +> Potential breaking changes: +> - When `--config-path` is a directory, rustfmt now also searches its parent directories for config files [#4660](https://github.com/rust-lang/rustfmt/issues/4660) [#7115](https://github.com/rust-lang/rustfmt/pull/7115) +> - Chains with comments now format under `use_try_shorthand=true` [#6121](https://github.com/rust-lang/rustfmt/issues/6121) [#7095](https://github.com/rust-lang/rustfmt/pull/7095) +> - Error on `--print-config minimal` with no output path [#7208](https://github.com/rust-lang/rustfmt/pull/7208) +> - Previously, this printed a warning and exited with `0`. + +### Fixed +- Fix ragged statement comment wrapping under unstable option `wrap_comments=true` and `comment_width` [#7167](https://github.com/rust-lang/rustfmt/issues/7167) [#7170](https://github.com/rust-lang/rustfmt/pull/7170) +- Enforce comment width in item lists [#7174](https://github.com/rust-lang/rustfmt/pull/7174) +- Fix lookup of global config files [#7178](https://github.com/rust-lang/rustfmt/issues/7178) [#7179](https://github.com/rust-lang/rustfmt/pull/7179) +- Don't remove empty generic args when formatting in a macro context [#7136](https://github.com/rust-lang/rustfmt/issues/7136) [#7181](https://github.com/rust-lang/rustfmt/pull/7181) +- Various `cfg_select!` fixes. Note that `cfg_select!` formatting is still nightly-gated. + - Fix `cfg_select!` parser recovery handling and error count leak [#7171](https://github.com/rust-lang/rustfmt/pull/7171) + - Don't remove necessary blocks when formatting `cfg_select!` arms [#7045](https://github.com/rust-lang/rustfmt/issues/7045) [#7183](https://github.com/rust-lang/rustfmt/pull/7183) + - Prevent more comment loss in `cfg_select!` [#7209](https://github.com/rust-lang/rustfmt/issues/7209) [rust-lang/rust#164815](https://github.com/rust-lang/rust/pull/164815) + - Don't lose comments and attributes between `cfg_select!` predicates, outer/inner blocks, arm body and trailing commas [#7209](https://github.com/rust-lang/rustfmt/issues/7209) [#7211](https://github.com/rust-lang/rustfmt/pull/7211) + - Have `cfg_select!` double-brace concise formatting respect `control_brace_style` unstable option [#7214](https://github.com/rust-lang/rustfmt/pull/7214) +- Prevent rustfmt from removing expression attributes when removing nested parentheses [#7190](https://github.com/rust-lang/rustfmt/issues/7190) [#7192](https://github.com/rust-lang/rustfmt/pull/7192) +- Fix `cfg_if!` error count leaks [#7195](https://github.com/rust-lang/rustfmt/pull/7195) +- Format comments after `where` clauses using `clause_shape` budget (affecting unstable options `wrap_comments=true` and `comment_width`) [#7148](https://github.com/rust-lang/rustfmt/issues/7148) [#7156](https://github.com/rust-lang/rustfmt/pull/7156) +- Fix ICE on failure to format generics in enum [#5738](https://github.com/rust-lang/rustfmt/issues/5738) [#6137](https://github.com/rust-lang/rustfmt/issues/6137) [#6318](https://github.com/rust-lang/rustfmt/issues/6318) [#6646](https://github.com/rust-lang/rustfmt/issues/6646) [#6396](https://github.com/rust-lang/rustfmt/pull/6396) +- Avoid leaking wrapper space from doc comment code block formatting (affecting unstable options `format_code_in_doc_comments=true` and `fn_single_line=true`) [#6832](https://github.com/rust-lang/rustfmt/issues/6832) [#6851](https://github.com/rust-lang/rustfmt/pull/6851) ## [1.11.0] 2026-11-12 @@ -28,7 +53,6 @@ - Correct visibility and defaultness order on associated impl type alias [#7064](https://github.com/rust-lang/rustfmt/pull/7064). - Correctly calculate the `shape` for inline const blocks when using `style_edition=2027` [#7065](https://github.com/rust-lang/rustfmt/pull/7065). - Prevent invalid code generation in macros that use raw identifiers [#7110](https://github.com/rust-lang/rustfmt/pull/7110). -- Prevent rustfmt from reporting on `max_width` configuration issues when formatting macros [#6651](https://github.com/rust-lang/rustfmt/pull/6651). ### Changed - No longer apply `use_field_init_shorthand` when formatting macros [#6981](https://github.com/rust-lang/rustfmt/pull/6981). diff --git a/Cargo.lock b/Cargo.lock index b83c8ec9612..38d5f7724e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -582,7 +582,7 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "1.11.0" +version = "1.12.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 9e689fc0041..78ee1fb2742 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustfmt-nightly" -version = "1.11.0" +version = "1.12.0" description = "Tool to find and fix Rust formatting issues" repository = "https://github.com/rust-lang/rustfmt" license = "Apache-2.0 OR MIT" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d621e4fb084..0a85b69efd3 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2026-10-22" +channel = "nightly-2026-11-02" components = ["llvm-tools", "rustc-dev"] diff --git a/src/parse/session.rs b/src/parse/session.rs index c61b43492ce..0df19406607 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -195,9 +195,7 @@ impl ParseSess { } pub(crate) fn span_to_file_contents(&self, span: Span) -> Arc { - self.raw_psess - .source_map() - .lookup_source_file(span.data().lo) + self.raw_psess.source_map().lookup_source_file(span.lo()) } pub(crate) fn span_to_first_line_string(&self, span: Span) -> String { diff --git a/tests/source/cfg_select/cfg_select_edge_cases.rs b/tests/source/cfg_select/cfg_select_edge_cases.rs index cec0bb4b9c2..8bf6a3240a9 100644 --- a/tests/source/cfg_select/cfg_select_edge_cases.rs +++ b/tests/source/cfg_select/cfg_select_edge_cases.rs @@ -61,6 +61,12 @@ fn cfg_select_comments_that_might_get_lost() { // before closing brace } } + cfg_select! { + _ => { /* after opening brace */ + { x } + /* before closing brace */ + } + } cfg_select! { _ => /* after => */ {{ x }} } diff --git a/tests/target/cfg_select/cfg_select_edge_cases.rs b/tests/target/cfg_select/cfg_select_edge_cases.rs index 6b2f713116e..ea6eaf92056 100644 --- a/tests/target/cfg_select/cfg_select_edge_cases.rs +++ b/tests/target/cfg_select/cfg_select_edge_cases.rs @@ -78,6 +78,13 @@ fn cfg_select_comments_that_might_get_lost() { // before closing brace } } + cfg_select! { + _ => { + /* after opening brace */ + { x } + /* before closing brace */ + } + } cfg_select! { _ => /* after => */ diff --git a/tests/target/issue_7209.rs b/tests/target/issue_7209.rs new file mode 100644 index 00000000000..0d7d015459a --- /dev/null +++ b/tests/target/issue_7209.rs @@ -0,0 +1,28 @@ +//@ rustfmt-unstable: true + +fn gettid() -> u64 { + cfg_select! { + any(target_os = "android", target_os = "linux") => gettid_linux_like(), + any(target_os = "nto", target_os = "qnx") => unsafe { libc::gettid() as u64 }, + target_os = "openbsd" => unsafe { libc::getthrid() as u64 }, + target_os = "freebsd" => unsafe { libc::pthread_getthreadid_np() as u64 }, + target_os = "netbsd" => unsafe { libc::_lwp_self() as u64 }, + any(target_os = "solaris", target_os = "illumos") => { + // On Solaris and Illumos, the `pthread_t` is the OS TID. + unsafe { libc::pthread_self() as u64 } + } + target_vendor = "apple" => { + let mut id = 0u64; + let status: libc::c_int = unsafe { libc::pthread_threadid_np(0, &mut id) }; + assert_eq!(status, 0); + id + } + windows => { + use windows_sys::Win32::System::Threading::GetCurrentThreadId; + unsafe { GetCurrentThreadId() as u64 } + } + _ => { + compile_error!("platform has no gettid") + } + } +}