Skip to content

Commit f43c966

Browse files
Merge remote-tracking branch 'upstream/master' into subtree-sync-2022-06-22
2 parents ac2b7a2 + 08105e8 commit f43c966

File tree

27 files changed

+502
-175
lines changed

27 files changed

+502
-175
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,5 @@ jobs:
3535
sh rustup-init.sh -y --default-toolchain none
3636
rustup target add ${{ matrix.target }}
3737
38-
- name: build
39-
run: |
40-
rustc -Vv
41-
cargo -V
42-
cargo build
43-
env:
44-
RUSTFLAGS: '-D warnings'
45-
46-
- name: test
47-
run: cargo test
48-
env:
49-
RUSTFLAGS: '-D warnings'
38+
- name: Build and Test
39+
run: ./ci/build_and_test.sh

.github/workflows/mac.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,5 @@ jobs:
3232
sh rustup-init.sh -y --default-toolchain none
3333
rustup target add ${{ matrix.target }}
3434
35-
- name: build
36-
run: |
37-
rustc -Vv
38-
cargo -V
39-
cargo build
40-
41-
- name: test
42-
run: cargo test
35+
- name: Build and Test
36+
run: ./ci/build_and_test.sh

.github/workflows/windows.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ jobs:
5757
if: matrix.target == 'x86_64-pc-windows-gnu' && matrix.channel == 'nightly'
5858
shell: bash
5959

60-
- name: build
61-
run: |
62-
rustc -Vv
63-
cargo -V
64-
cargo build
65-
shell: cmd
66-
67-
- name: test
68-
run: cargo test
60+
- name: Build and Test
6961
shell: cmd
62+
run: ci\build_and_test.bat

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" }
6565
rustc-workspace-hack = "1.0.0"
6666

6767
# Rustc dependencies are loaded from the sysroot, Cargo doesn't know about them.
68+
69+
[package.metadata.rust-analyzer]
70+
# This package uses #[feature(rustc_private)]
71+
rustc_private = true

Configurations.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,14 @@ fn add_one(x: i32) -> i32 {
926926
}
927927
```
928928

929+
## `doc_comment_code_block_width`
930+
931+
Max width for code snippets included in doc comments. Only used if [`format_code_in_doc_comments`](#format_code_in_doc_comments) is true.
932+
933+
- **Default value**: `100`
934+
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
935+
- **Stable**: No (tracking issue: [#5359](https://github.com/rust-lang/rustfmt/issues/5359))
936+
929937
## `format_generated_files`
930938

931939
Format generated files. A file is considered generated

ci/build_and_test.bat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set "RUSTFLAGS=-D warnings"
2+
3+
:: Print version information
4+
rustc -Vv || exit /b 1
5+
cargo -V || exit /b 1
6+
7+
:: Build and test main crate
8+
cargo build --locked || exit /b 1
9+
cargo test || exit /b 1
10+
11+
:: Build and test other crates
12+
cd config_proc_macro || exit /b 1
13+
cargo build --locked || exit /b 1
14+
cargo test || exit /b 1

ci/build_and_test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
export RUSTFLAGS="-D warnings"
6+
7+
# Print version information
8+
rustc -Vv
9+
cargo -V
10+
11+
# Build and test main crate
12+
cargo build --locked
13+
cargo test
14+
15+
# Build and test other crates
16+
cd config_proc_macro
17+
cargo build --locked
18+
cargo test

ci/integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -ex
1515
# it again.
1616
#
1717
#which cargo-fmt || cargo install --force
18-
CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force
18+
CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force --locked
1919

2020
echo "Integration tests for: ${INTEGRATION}"
2121
cargo fmt -- --version

config_proc_macro/Cargo.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config_proc_macro/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub fn config_type(_args: TokenStream, input: TokenStream) -> TokenStream {
2929
/// Used to conditionally output the TokenStream for tests that need to be run on nightly only.
3030
///
3131
/// ```rust
32+
/// # use rustfmt_config_proc_macro::nightly_only_test;
33+
///
3234
/// #[nightly_only_test]
3335
/// #[test]
3436
/// fn test_needs_nightly_rustfmt() {
@@ -49,6 +51,8 @@ pub fn nightly_only_test(_args: TokenStream, input: TokenStream) -> TokenStream
4951
/// Used to conditionally output the TokenStream for tests that need to be run on stable only.
5052
///
5153
/// ```rust
54+
/// # use rustfmt_config_proc_macro::stable_only_test;
55+
///
5256
/// #[stable_only_test]
5357
/// #[test]
5458
/// fn test_needs_stable_rustfmt() {

src/cargo-fmt/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ use std::path::{Path, PathBuf};
1414
use std::process::Command;
1515
use std::str;
1616

17-
use clap::{CommandFactory, Parser};
17+
use clap::{AppSettings, CommandFactory, Parser};
1818

1919
#[path = "test/mod.rs"]
2020
#[cfg(test)]
2121
mod cargo_fmt_tests;
2222

2323
#[derive(Parser)]
2424
#[clap(
25+
global_setting(AppSettings::NoAutoVersion),
2526
bin_name = "cargo fmt",
2627
about = "This utility formats all bin and lib files of \
2728
the current crate using rustfmt."

src/comment.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ impl<'a> CommentRewrite<'a> {
730730
{
731731
let mut config = self.fmt.config.clone();
732732
config.set().wrap_comments(false);
733+
let comment_max_width = config
734+
.doc_comment_code_block_width()
735+
.min(config.max_width());
736+
config.set().max_width(comment_max_width);
733737
if let Some(s) =
734738
crate::format_code_block(&self.code_block_buffer, &config, false)
735739
{

src/config/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ create_config! {
5757
// Comments. macros, and strings
5858
wrap_comments: bool, false, false, "Break comments to fit on the line";
5959
format_code_in_doc_comments: bool, false, false, "Format the code snippet in doc comments.";
60+
doc_comment_code_block_width: usize, 100, false, "Maximum width for code snippets in doc \
61+
comments. No effect unless format_code_in_doc_comments = true";
6062
comment_width: usize, 80, false,
6163
"Maximum length of comments. No effect unless wrap_comments = true";
6264
normalize_comments: bool, false, false, "Convert /* */ comments to // comments where possible";
@@ -532,6 +534,7 @@ chain_width = 60
532534
single_line_if_else_max_width = 50
533535
wrap_comments = false
534536
format_code_in_doc_comments = false
537+
doc_comment_code_block_width = 100
535538
comment_width = 80
536539
normalize_comments = false
537540
normalize_doc_attributes = false

0 commit comments

Comments
 (0)