Skip to content

Sync from rustfmt #130593

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 109 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
1d1989f
Fix rustfmt
compiler-errors Jun 17, 2024
0c5a75a
Use a dedicated type instead of a reference for the diagnostic context
oli-obk Jun 18, 2024
ebce054
Merge commit 'e4944185ae09c99f59b460e358909f329010ea9c' into sync-fro…
calebcartwright Jun 22, 2024
8b36bc0
Fix rustfmt
compiler-errors Jun 17, 2024
081ae53
fix bad merge conflict resolution
calebcartwright Jun 22, 2024
5faf95c
Rework pattern and expression nonterminal kinds.
nnethercote Jun 22, 2024
10277c9
Implement use<> formatting in rustfmt
compiler-errors Jun 20, 2024
8f8a463
Rollup merge of #126851 - nnethercote:NtExprKind-NtPatKind, r=compile…
matthiaskrgr Jun 23, 2024
22aac49
Remove stray println from rustfmt
compiler-errors Jun 24, 2024
bd0a886
Rollup merge of #126754 - compiler-errors:use-rustfmt, r=calebcartwright
matthiaskrgr Jun 24, 2024
514fe39
Rollup merge of #126888 - compiler-errors:oops-debug-printing, r=dtolnay
matthiaskrgr Jun 24, 2024
b5fa338
Merge remote-tracking branch 'origin/master' into sync-from-rust-2024…
compiler-errors Jun 25, 2024
a3a84e5
Bump toolchain to nightly-2024-06-24
compiler-errors Jun 25, 2024
c528496
Remove stray println from rustfmt
compiler-errors Jun 24, 2024
51df533
Tighten spans for async blocks
compiler-errors Jun 27, 2024
88f98c2
Implement RTN support in rustfmt
compiler-errors Jun 28, 2024
6093d48
Merge pull request #6217 from compiler-errors/sync-from-rust-2024-06-24
calebcartwright Jul 1, 2024
f65d04a
fix link syntax
hattizai Jul 2, 2024
533b760
remove duplicate word
hattizai Jul 2, 2024
905ca54
add rewrite_result method to Rewrite trait
ding-young Jun 19, 2024
21afdb8
add Ext trait for converting Option->RewriteResult
ding-young Jun 25, 2024
f62d730
impl rewrite_result for AssocItemConstraintKind, GenericArg, GenericB…
ding-young Jun 29, 2024
eed7e23
rewrite_result for GenericBounds, GenericParam, SegmentParam
ding-young Jun 30, 2024
c8290a5
ensure parse errors aren't emitted when formatting doc comments (#6232)
giordan12 Jul 8, 2024
add0459
add release date for v1.7.1
ytmimi Jul 6, 2024
163d26e
Remove rustdoc tests which no longer parse
compiler-errors Jul 12, 2024
bb56224
refactor rewrite_block
ding-young Jul 6, 2024
071ca7d
refactor rewrite_closure
ding-young Jul 9, 2024
7cdb426
Implement `StyleEditionDefault` for each config option
ytmimi Oct 8, 2023
3cbc91e
modify rewrite_path and impl rewrite_result for related AST nodes
ding-young Jul 10, 2024
babc2f9
modify rewrite_struct_lit, rewrite_struct_pat
ding-young Jul 10, 2024
ea02de2
refactor rewrite_match and impl rewrite_result for ArmWrapper
ding-young Jul 12, 2024
6ccf539
modify trait bound of itemize_list
ding-young Jul 17, 2024
1313d61
modfiy ListItem to hold RewriteResult as the item field
ding-young Jul 18, 2024
e21c1e2
refactor rewrite_array, pair, tuple, call
ding-young Jul 18, 2024
a23d3cc
refactor: track configs set from cli flags
calebcartwright Jul 26, 2024
d8ae6a9
tests: add a few for style edition config defaults
calebcartwright Jul 27, 2024
c2c9be5
feat: implement Style Edition support
calebcartwright Jul 19, 2024
7c41e2b
refactor: switch from 'version' to 'style_edition'
calebcartwright Jul 19, 2024
b6c89fc
feat: add --style-edition option to rustfmt binary
calebcartwright Jul 19, 2024
e04e411
tests: validate style_edition derivation
calebcartwright Jul 19, 2024
aa8a53f
refactor: switch idempotence/system tests to style_edition
calebcartwright Jul 19, 2024
7a5a936
docs: use StyleEdition in dev guide
calebcartwright Jul 19, 2024
d65daa9
refactor: rebase with set_cli() behavior
calebcartwright Jul 27, 2024
d66ab31
tests: add new load_config tests
calebcartwright Jul 28, 2024
cf352a7
chore: apply review suggestions
calebcartwright Jul 28, 2024
90a86a7
Suppress must_use on eat calls in rustfmt
compiler-errors Jul 30, 2024
6159460
rustfmt: Remove `has_cpuid` from test
workingjubilee Aug 2, 2024
5325b9e
modify rewrite_literal
ding-young Jul 22, 2024
3d468e2
update combine_strs_with_missing_comments
ding-young Jul 22, 2024
b8a5b21
impl rewrite_result for ChainItem
ding-young Jul 29, 2024
63d50dd
Add `cd` and `git clone` functionality to check-diff crate
benluiwj Jun 6, 2024
a1361bd
Run check-diff tests in ci
benluiwj Jul 20, 2024
17c5869
Print a deterministic length of commit hash in --version
dtolnay Jul 30, 2024
15c75fe
Check exit status of git commands spawned by build script
dtolnay Aug 4, 2024
8894466
Print empty commit info without trailing hyphen
dtolnay Aug 4, 2024
40f5075
impl rewrite_result for Pat, TuplePatField
ding-young Aug 1, 2024
87949d7
Stabilize `unsafe_attributes`
carbotaniuman Aug 7, 2024
57af02c
Link `std` statically in `rustc_driver`
Zoxc Mar 12, 2024
7b2299a
Use `impl PartialEq<TokenKind> for Token` more.
nnethercote Aug 9, 2024
68dc912
update rewrite functions in imports.rs
ding-young Aug 1, 2024
caaa612
Ensure that `fn config_path` returns canonicalized paths.
anforowicz Aug 7, 2024
fbe0424
update rewrite_chain to return RewriteResult
ding-young Aug 7, 2024
6bcadd6
Merge remote-tracking branch 'upstream/master' into subtree-push-nigh…
ytmimi Aug 17, 2024
d34fca4
bump toolchain to nightly-2024-08-17
ytmimi Aug 17, 2024
9cfbd23
Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethe…
bors Aug 17, 2024
4489061
Merge pull request #6285 from ytmimi/subtree-push-nightly-2024-08-17
ytmimi Aug 19, 2024
6f5e99b
update macro rewrite functions to return RewriteResult
ding-young Jul 22, 2024
5ee4d3b
Remove outdated comment from `mac.yml`
beetrees Aug 24, 2024
53d5ccd
refactor: use style edition when loading from partial config
calebcartwright Aug 1, 2024
c0c3dc7
refactor: include edition & style edition in CliOptions
calebcartwright Aug 2, 2024
0c6515c
feat: support style edition differing defaults in config loading
calebcartwright Aug 2, 2024
0652586
feat: implement 2024 Style Edition for expr overflows
calebcartwright Aug 2, 2024
46cb7d3
refactor: improve mapping of legacy 'version' to 'style_edition'
calebcartwright Aug 14, 2024
1fcfd57
Remove `#[macro_use] extern crate tracing` from rustfmt helpers.
nnethercote Aug 30, 2024
c3beb05
Remove `#[macro_use] extern crate tracing` from rustfmt.
nnethercote Aug 30, 2024
1930514
update rewrite_assignment to return RewriteResult
ding-young Aug 28, 2024
35b3889
impl rewrite_result for ControlFlow, Stmt, update rewrite_index
ding-young Aug 23, 2024
40909b4
Fix `test_editions_2015_2018_2021_identical`
Sep 1, 2024
9d407bf
Avoid allocating intermediate strings in `ItemizedBlock::trimmed_bloc…
Sep 1, 2024
5d30ce6
Avoid allocating intermediate strings in `determine_operation`
Sep 1, 2024
1681c91
implement version-sorting algorithm for rust identifiers
ytmimi Jul 9, 2024
2964172
use version-sort when reordering imports using `style_edition=2024`
ytmimi Jul 9, 2024
ae59ee7
sort rustfmt imports
ytmimi Aug 16, 2024
06e1644
Add test cases for issue 4381
ytmimi Aug 16, 2024
1a70f40
Avoid allocation in `ChainItemKind::is_tup_field_access`
Sep 1, 2024
2639370
impl rewrite_result for TraitAliasBounds, WherePredicate
ding-young Aug 28, 2024
b40c3cc
impl rewrite_result for ForeignItem
ding-young Sep 1, 2024
d720a7e
impl rewrite_result for ast::Expr
ding-young Aug 25, 2024
e1712ea
Fix tools
compiler-errors Jun 14, 2024
91b2c17
Add missing backtick in comment (#6317)
cuishuang Sep 9, 2024
182a203
ci: bump actions/checkout to v4
trivikr Sep 9, 2024
348a499
Merge remote-tracking branch 'upstream/master' into subtree-push-nigh…
ytmimi Sep 10, 2024
bd5873a
bump toolchain to nightly-2024-09-10
ytmimi Sep 10, 2024
d66e974
remove stray comments
ytmimi Sep 12, 2024
a1017ae
Merge pull request #6320 from ytmimi/subtree-push-nightly-2024-09-10
ytmimi Sep 12, 2024
2e66891
remove unused tracing-attributes
klensy Jun 23, 2024
7e507a8
config_proc_macro: reduce syn's features
klensy Jul 11, 2024
16f0ecc
config_proc_macro: bump edition to 2021
klensy Jul 30, 2024
14d5165
refactor - show file path in error message when parsing config from toml
rufevean Sep 1, 2024
df06d7e
Format trailing where clauses in rustfmt
compiler-errors Aug 16, 2023
d6d9e76
Add tests showing how comments are handled
compiler-errors Aug 27, 2023
5230e8f
Non-panicking Display for Path
Rawk Sep 15, 2024
019578f
Use `usize::MAX` instead of deprecated `usize::max_value`
Rawk Sep 17, 2024
008b3df
Avoid allocating `Vec` in `light_rewrite_comment`
Rawk Sep 14, 2024
b552eb9
Avoid an allocation in `rewrite_int_lit`
Rawk Sep 14, 2024
31e799f
Document changes for the next release
ytmimi Sep 17, 2024
b23b699
chore: prep v1.8.0 release
ytmimi Sep 19, 2024
eeda9dd
Merge commit 'b23b69900eab1260be510b2bd8922f4b6de6cf1e' into sync-fro…
ytmimi Sep 20, 2024
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
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4630,7 +4630,7 @@ dependencies = [

[[package]]
name = "rustfmt-nightly"
version = "1.7.1"
version = "1.8.0"
dependencies = [
"annotate-snippets 0.9.2",
"anyhow",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/.github/workflows/check_diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: install rustup
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/.github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# Run build
- name: install rustup
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/.github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# Run build
- name: install rustup
Expand Down
3 changes: 1 addition & 2 deletions src/tools/rustfmt/.github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
jobs:
test:
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources
# macOS Catalina 10.15
runs-on: macos-latest
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
env:
Expand All @@ -23,7 +22,7 @@ jobs:

steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# Run build
- name: install rustup
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/.github/workflows/rustdoc_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: rustdoc check
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: install rustup
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/.github/workflows/upload-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Run build
- name: install rustup
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/.github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: disable git eol translation
run: git config --global core.autocrlf false
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# Run build
- name: Install Rustup using win.rustup.rs
Expand Down
64 changes: 62 additions & 2 deletions src/tools/rustfmt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,66 @@
# Changelog

## [Unreleased]
## [1.8.0] 2024-09-20

### Fixed
- Fix issue where rustfmt would crash on Windows when using the `ignore` option [#6178](https://github.com/rust-lang/rustfmt/issues/6178)

### Changed
- `rustfmt --version` now prints a commit hash that is 10 characters long [#6258](https://github.com/rust-lang/rustfmt/pull/6258)
- `rustfmt --version` will no longer print empty git information when git information isn't available at build time.
For example, git information is not available when building rustfmt from a source tarball [#6266](https://github.com/rust-lang/rustfmt/pull/6266)
- `version` has been soft deprecated and replaced by `style_edition`.
`style_edition=2024` is equivalent to `version=Two` and `style_edition={2015|2018|2021}`
are equivalent to `version=One` [#6247](https://github.com/rust-lang/rustfmt/pull/6247)
- When `style_edition=2024` is configured `overflow_delimited_expr` will default to `true` [#6260](https://github.com/rust-lang/rustfmt/pull/6260).
```rust
// with style_edition=2015
do_thing(
x,
Bar {
x: value,
y: value2,
},
);

// with style_edition=2024
do_thing(x, Bar {
x: value,
y: value2,
});
```
- When `style_edition=2024` is configured rustfmt will apply the [style guide's version sorting algorithm]
when sorting imports [#6284](https://github.com/rust-lang/rustfmt/pull/6284)
```rust
// with style_edition=2015
use std::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8};

// with style_edition=2024
use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64};
```
[style guide's version sorting algorithm]: https://doc.rust-lang.org/nightly/style-guide/#sorting
- 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)

### Added
- rustfmt now formats trailing where clauses in type aliases [#5887](https://github.com/rust-lang/rustfmt/pull/5887)
```rust
type Foo
= Bar
where
A: B,
C: D;
```
- Users can now configure which `style_edition` rustfmt uses when formatting their code as specified
in [RFC 3338](https://rust-lang.github.io/rfcs/3338-style-evolution.html). Users are encouraged to configure `style_edition`
in their `rustfmt.toml` files, but the value can also be specified via the cli with `--unstable-features --style-edition={style_edition}`.
When `style_edition` is not explicitly configured it will be inferred from the `edition` configuration.
When neither `style_edition` nor `edition` are configured `style_edition` defaults to `2015` [#6247](https://github.com/rust-lang/rustfmt/pull/6247)

### Misc
- Removed `tracing-attributes` dependency [#6208](https://github.com/rust-lang/rustfmt/pull/6208)
- Reduced syn's features in the internal `config_proc_macro` crate [#6237](https://github.com/rust-lang/rustfmt/pull/6237)

## [1.7.1] 2024-06-24

### Fixed

Expand Down Expand Up @@ -238,7 +298,7 @@

### Added

- New configuration option (`skip_macro_invocations`)[https://rust-lang.github.io/rustfmt/?version=master&search=#skip_macro_invocations] [#5347](https://github.com/rust-lang/rustfmt/pull/5347) that can be used to globally define a single enumerated list of macro calls that rustfmt should skip formatting. rustfmt [currently also supports this via a custom tool attribute](https://github.com/rust-lang/rustfmt#tips), however, these cannot be used in all contexts because [custom inner attributes are unstable](https://github.com/rust-lang/rust/issues/54726)
- New configuration option [`skip_macro_invocations`](https://rust-lang.github.io/rustfmt/?version=master&search=#skip_macro_invocations) [#5347](https://github.com/rust-lang/rustfmt/pull/5347) that can be used to globally define a single enumerated list of macro calls that rustfmt should skip formatting. rustfmt [currently also supports this via a custom tool attribute](https://github.com/rust-lang/rustfmt#tips), however, these cannot be used in all contexts because [custom inner attributes are unstable](https://github.com/rust-lang/rust/issues/54726)

### Misc

Expand Down
14 changes: 1 addition & 13 deletions src/tools/rustfmt/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ dependencies = [

[[package]]
name = "rustfmt-nightly"
version = "1.7.1"
version = "1.8.0"
dependencies = [
"annotate-snippets",
"anyhow",
Expand Down Expand Up @@ -710,21 +710,9 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]

[[package]]
name = "tracing-attributes"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

[[package]]
name = "tracing-core"
version = "0.1.31"
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rustfmt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "rustfmt-nightly"
version = "1.7.1"
version = "1.8.0"
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang/rustfmt"
readme = "README.md"
Expand Down Expand Up @@ -50,7 +50,7 @@ serde_json = "1.0"
term = "0.7"
thiserror = "1.0.40"
toml = "0.7.4"
tracing = "0.1.37"
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
unicode-segmentation = "1.9"
unicode-width = "0.1"
Expand Down
17 changes: 13 additions & 4 deletions src/tools/rustfmt/Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ Note that this option may be soft-deprecated in the future once the [ignore](#ig
Specifies which edition is used by the parser.

- **Default value**: `"2015"`
- **Possible values**: `"2015"`, `"2018"`, `"2021"`
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"`
- **Stable**: Yes

Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed
Expand Down Expand Up @@ -2692,6 +2692,17 @@ By default this option is set as a percentage of [`max_width`](#max_width) provi

See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)

## `style_edition`

Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338])

- **Default value**: `"2015"`
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant)
- **Stable**: No

[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html

## `tab_spaces`

Number of spaces per tab
Expand Down Expand Up @@ -3051,9 +3062,7 @@ fn main() {

## `version`

Which version of the formatting rules to use. `Version::One` is backwards-compatible
with Rustfmt 1.0. Other versions are only backwards compatible within a major
version number.
This option is deprecated and has been replaced by [`style_edition`](#style_edition)

- **Default value**: `One`
- **Possible values**: `One`, `Two`
Expand Down
21 changes: 11 additions & 10 deletions src/tools/rustfmt/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ If you want to test modified `cargo-fmt`, or run `rustfmt` on the whole project
RUSTFMT="./target/debug/rustfmt" cargo run --bin cargo-fmt -- --manifest-path path/to/project/you/want2test/Cargo.toml
```

### Version-gate formatting changes
### Gate formatting changes

A change that introduces a different code-formatting should be gated on the
`version` configuration. This is to ensure the formatting of the current major
release is preserved, while allowing fixes to be implemented for the next
release.
A change that introduces a different code-formatting must be gated on the
`style_edition` configuration. This is to ensure rustfmt upholds its formatting
stability guarantees and adheres to the Style Edition process set in [RFC 3338]

This is done by conditionally guarding the change like so:
This can be done by conditionally guarding the formatting change, e.g.:

```rust
if config.version() == Version::One { // if the current major release is 1.x
// if the current stable Style Edition is Edition 2024
if config.style_edition() <= StyleEdition::Edition2024 {
// current formatting
} else {
// new formatting
Expand All @@ -129,13 +129,14 @@ if config.version() == Version::One { // if the current major release is 1.x
This allows the user to apply the next formatting explicitly via the
configuration, while being stable by default.

When the next major release is done, the code block of the previous formatting
can be deleted, e.g., the first block in the example above when going from `1.x`
to `2.x`.
This can then be enhanced as needed if and when there are
new Style Editions with differing formatting prescriptions.

| Note: Only formatting changes with default options need to be gated. |
| --- |

[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html

### A quick tour of Rustfmt

Rustfmt is basically a pretty printer - that is, its mode of operation is to
Expand Down
19 changes: 11 additions & 8 deletions src/tools/rustfmt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
// (git not installed or if this is not a git repository) just return an empty string.
fn commit_info() -> String {
match (channel(), commit_hash(), commit_date()) {
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_end(), date),
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash, date),
_ => String::new(),
}
}
Expand All @@ -39,17 +39,20 @@ fn channel() -> String {
}

fn commit_hash() -> Option<String> {
Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
.ok()?;
let mut stdout = output.status.success().then_some(output.stdout)?;
stdout.truncate(10);
String::from_utf8(stdout).ok()
}

fn commit_date() -> Option<String> {
Command::new("git")
let output = Command::new("git")
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
.ok()?;
let stdout = output.status.success().then_some(output.stdout)?;
String::from_utf8(stdout).ok()
}
Loading
Loading