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 1 commit
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
Prev Previous commit
Next Next commit
refactor: track configs set from cli flags
  • Loading branch information
calebcartwright committed Jul 27, 2024
commit a23d3ccb840621183f395906cdbe468d643a381f
57 changes: 39 additions & 18 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,35 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32> {
let (mut config, _) = load_config(Some(Path::new(".")), Some(options.clone()))?;

if options.check {
config.set().emit_mode(EmitMode::Diff);
config.set_cli().emit_mode(EmitMode::Diff);
} else {
match options.emit_mode {
// Emit modes which work with standard input
// None means default, which is Stdout.
None | Some(EmitMode::Stdout) | Some(EmitMode::Checkstyle) | Some(EmitMode::Json) => {}
None => {
config
.set()
.emit_mode(options.emit_mode.unwrap_or(EmitMode::Stdout));
}
Some(EmitMode::Stdout) | Some(EmitMode::Checkstyle) | Some(EmitMode::Json) => {
config
.set_cli()
.emit_mode(options.emit_mode.unwrap_or(EmitMode::Stdout));
}
Some(emit_mode) => {
return Err(OperationError::StdinBadEmit(emit_mode).into());
}
}
config
.set()
.emit_mode(options.emit_mode.unwrap_or(EmitMode::Stdout));
}
config.set().verbose(Verbosity::Quiet);

// parse file_lines
config.set().file_lines(options.file_lines);
if options.file_lines.is_all() {
config.set().file_lines(options.file_lines);
} else {
config.set_cli().file_lines(options.file_lines);
}

for f in config.file_lines().files() {
match *f {
FileName::Stdin => {}
Expand Down Expand Up @@ -650,36 +661,46 @@ impl GetOptsOptions {
impl CliOptions for GetOptsOptions {
fn apply_to(self, config: &mut Config) {
if self.verbose {
config.set().verbose(Verbosity::Verbose);
config.set_cli().verbose(Verbosity::Verbose);
} else if self.quiet {
config.set().verbose(Verbosity::Quiet);
config.set_cli().verbose(Verbosity::Quiet);
} else {
config.set().verbose(Verbosity::Normal);
}
config.set().file_lines(self.file_lines);
config.set().unstable_features(self.unstable_features);

if self.file_lines.is_all() {
config.set().file_lines(self.file_lines);
} else {
config.set_cli().file_lines(self.file_lines);
}

if self.unstable_features {
config.set_cli().unstable_features(self.unstable_features);
} else {
config.set().unstable_features(self.unstable_features);
}
if let Some(skip_children) = self.skip_children {
config.set().skip_children(skip_children);
config.set_cli().skip_children(skip_children);
}
if let Some(error_on_unformatted) = self.error_on_unformatted {
config.set().error_on_unformatted(error_on_unformatted);
config.set_cli().error_on_unformatted(error_on_unformatted);
}
if let Some(edition) = self.edition {
config.set().edition(edition);
config.set_cli().edition(edition);
}
if self.check {
config.set().emit_mode(EmitMode::Diff);
config.set_cli().emit_mode(EmitMode::Diff);
} else if let Some(emit_mode) = self.emit_mode {
config.set().emit_mode(emit_mode);
config.set_cli().emit_mode(emit_mode);
}
if self.backup {
config.set().make_backup(true);
config.set_cli().make_backup(true);
}
if let Some(color) = self.color {
config.set().color(color);
config.set_cli().color(color);
}
if self.print_misformatted_file_names {
config.set().print_misformatted_file_names(true);
config.set_cli().print_misformatted_file_names(true);
}

for (key, val) in self.inline_config {
Expand Down
61 changes: 59 additions & 2 deletions src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ macro_rules! create_config {
// - 1: true if the option was manually initialized
// - 2: the option value
// - 3: true if the option is unstable
$($i: (Cell<bool>, bool, <$ty as StyleEditionDefault>::ConfigType, bool)),+
// - 4: true if the option was set manually from a CLI flag
// FIXME: 4 is probably unnecessary and duplicative
// https://github.com/rust-lang/rustfmt/issues/6252
$($i: (Cell<bool>, bool, <$ty as StyleEditionDefault>::ConfigType, bool, bool)),+
}

// Just like the Config struct but with each property wrapped
Expand Down Expand Up @@ -136,6 +139,35 @@ macro_rules! create_config {
)+
}

#[allow(unreachable_pub)]
pub struct CliConfigSetter<'a>(&'a mut Config);

impl<'a> CliConfigSetter<'a> {
$(
#[allow(unreachable_pub)]
pub fn $i(&mut self, value: <$ty as StyleEditionDefault>::ConfigType) {
(self.0).$i.2 = value;
(self.0).$i.4 = true;
match stringify!($i) {
"max_width"
| "use_small_heuristics"
| "fn_call_width"
| "single_line_if_else_max_width"
| "single_line_let_else_max_width"
| "attr_fn_like_width"
| "struct_lit_width"
| "struct_variant_width"
| "array_width"
| "chain_width" => self.0.set_heuristics(),
"merge_imports" => self.0.set_merge_imports(),
"fn_args_layout" => self.0.set_fn_args_layout(),
"hide_parse_errors" => self.0.set_hide_parse_errors(),
&_ => (),
}
}
)+
}

// Query each option, returns true if the user set the option, false if
// a default was used.
#[allow(unreachable_pub)]
Expand All @@ -150,6 +182,20 @@ macro_rules! create_config {
)+
}

// Query each option, returns true if the user set the option via a CLI flag,
// false if a default was used.
#[allow(unreachable_pub)]
pub struct CliConfigWasSet<'a>(&'a Config);

impl<'a> CliConfigWasSet<'a> {
$(
#[allow(unreachable_pub)]
pub fn $i(&self) -> bool {
(self.0).$i.4
}
)+
}

impl Config {
$(
#[allow(unreachable_pub)]
Expand All @@ -169,7 +215,8 @@ macro_rules! create_config {
<$ty as StyleEditionDefault>::style_edition_default(
style_edition
),
$stb
$stb,
false,
),
)+
}
Expand All @@ -180,11 +227,21 @@ macro_rules! create_config {
ConfigSetter(self)
}

#[allow(unreachable_pub)]
pub fn set_cli(&mut self) -> CliConfigSetter<'_> {
CliConfigSetter(self)
}

#[allow(unreachable_pub)]
pub fn was_set(&self) -> ConfigWasSet<'_> {
ConfigWasSet(self)
}

#[allow(unreachable_pub)]
pub fn was_set_cli(&self) -> CliConfigWasSet<'_> {
CliConfigWasSet(self)
}

fn fill_from_parsed_config(mut self, parsed: PartialConfig, dir: &Path) -> Config {
$(
if let Some(option_value) = parsed.$i {
Expand Down
2 changes: 1 addition & 1 deletion src/config/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl FileLines {
}

/// Returns `true` if this `FileLines` contains all lines in all files.
pub(crate) fn is_all(&self) -> bool {
pub fn is_all(&self) -> bool {
self.0.is_none()
}

Expand Down
14 changes: 14 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,20 @@ make_backup = false
assert_eq!(config.unstable_features(), true);
}

#[test]
fn test_set_cli() {
let mut config = Config::default();
assert_eq!(config.was_set().edition(), false);
assert_eq!(config.was_set_cli().edition(), false);
config.set().edition(Edition::Edition2021);
assert_eq!(config.was_set().edition(), false);
assert_eq!(config.was_set_cli().edition(), false);
config.set_cli().edition(Edition::Edition2021);
assert_eq!(config.was_set().edition(), false);
assert_eq!(config.was_set_cli().edition(), true);
assert_eq!(config.was_set_cli().emit_mode(), false);
}

#[cfg(test)]
mod deprecated_option_merge_imports {
use super::*;
Expand Down