Skip to content

Commit 7e6d0d4

Browse files
authored
Merge branch 'master' into compile-rsfmt-rewrite
2 parents 97c53be + 182a203 commit 7e6d0d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2066
-711
lines changed

.github/workflows/check_diff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: checkout
24-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2525

2626
- name: install rustup
2727
run: |

.github/workflows/integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464

6565
steps:
6666
- name: checkout
67-
uses: actions/checkout@v3
67+
uses: actions/checkout@v4
6868

6969
# Run build
7070
- name: install rustup

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
steps:
2828
- name: checkout
29-
uses: actions/checkout@v3
29+
uses: actions/checkout@v4
3030

3131
# Run build
3232
- name: install rustup

.github/workflows/mac.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
jobs:
99
test:
1010
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources
11-
# macOS Catalina 10.15
1211
runs-on: macos-latest
1312
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
1413
env:
@@ -23,7 +22,7 @@ jobs:
2322

2423
steps:
2524
- name: checkout
26-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2726

2827
# Run build
2928
- name: install rustup

.github/workflows/rustdoc_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: rustdoc check
1212
steps:
1313
- name: checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: install rustup
1717
run: |

.github/workflows/upload-assets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
target: x86_64-pc-windows-msvc
3232
runs-on: ${{ matrix.os }}
3333
steps:
34-
- uses: actions/checkout@v3
34+
- uses: actions/checkout@v4
3535

3636
# Run build
3737
- name: install rustup

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: disable git eol translation
3434
run: git config --global core.autocrlf false
3535
- name: checkout
36-
uses: actions/checkout@v3
36+
uses: actions/checkout@v4
3737

3838
# Run build
3939
- name: Install Rustup using win.rustup.rs

config_proc_macro/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use proc_macro2::TokenStream;
2-
use quote::{quote, ToTokens};
2+
use quote::{ToTokens, quote};
33

44
pub fn fold_quote<F, I, T>(input: impl Iterator<Item = I>, f: F) -> TokenStream
55
where

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-06-25"
2+
channel = "nightly-2024-08-17"
33
components = ["llvm-tools", "rustc-dev"]

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
error_on_line_overflow = true
22
error_on_unformatted = true
33
style_edition = "2024"
4+
overflow_delimited_expr = false

src/attr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
//! Format attributes and meta items.
22
3-
use rustc_ast::ast;
43
use rustc_ast::HasAttrs;
5-
use rustc_span::{symbol::sym, Span};
4+
use rustc_ast::ast;
5+
use rustc_span::{Span, symbol::sym};
66

77
use self::doc_comment::DocCommentFormatter;
8-
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
9-
use crate::config::lists::*;
8+
use crate::comment::{CommentStyle, contains_comment, rewrite_doc_comment};
109
use crate::config::IndentStyle;
10+
use crate::config::lists::*;
1111
use crate::expr::rewrite_literal;
12-
use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
12+
use crate::lists::{ListFormatting, Separator, definitive_tactic, itemize_list, write_list};
1313
use crate::overflow;
1414
use crate::rewrite::{Rewrite, RewriteContext, RewriteError, RewriteErrorExt, RewriteResult};
1515
use crate::shape::Shape;
1616
use crate::source_map::SpanUtils;
17-
use crate::types::{rewrite_path, PathContext};
17+
use crate::types::{PathContext, rewrite_path};
1818
use crate::utils::{count_newlines, mk_sp};
1919

2020
mod doc_comment;

src/bin/main.rs

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(rustc_private)]
22

3-
use anyhow::{format_err, Result};
3+
use anyhow::{Result, format_err};
44

55
use io::Error as IoError;
66
use thiserror::Error;
@@ -11,15 +11,15 @@ use tracing_subscriber::EnvFilter;
1111
use std::collections::HashMap;
1212
use std::env;
1313
use std::fs::File;
14-
use std::io::{self, stdout, Read, Write};
14+
use std::io::{self, Read, Write, stdout};
1515
use std::path::{Path, PathBuf};
1616
use std::str::FromStr;
1717

1818
use getopts::{Matches, Options};
1919

2020
use crate::rustfmt::{
21-
load_config, CliOptions, Color, Config, Edition, EmitMode, FileLines, FileName,
22-
FormatReportFormatterBuilder, Input, Session, StyleEdition, Verbosity,
21+
CliOptions, Color, Config, Edition, EmitMode, FileLines, FileName,
22+
FormatReportFormatterBuilder, Input, Session, StyleEdition, Verbosity, Version, load_config,
2323
};
2424

2525
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug";
@@ -462,16 +462,15 @@ fn print_version() {
462462

463463
fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
464464
if matches.opt_present("h") {
465-
let topic = matches.opt_str("h");
466-
if topic.is_none() {
465+
let Some(topic) = matches.opt_str("h") else {
467466
return Ok(Operation::Help(HelpOp::None));
468-
} else if topic == Some("config".to_owned()) {
469-
return Ok(Operation::Help(HelpOp::Config));
470-
} else if topic == Some("file-lines".to_owned()) && is_nightly() {
471-
return Ok(Operation::Help(HelpOp::FileLines));
472-
} else {
473-
return Err(OperationError::UnknownHelpTopic(topic.unwrap()));
474-
}
467+
};
468+
469+
return match topic.as_str() {
470+
"config" => Ok(Operation::Help(HelpOp::Config)),
471+
"file-lines" if is_nightly() => Ok(Operation::Help(HelpOp::FileLines)),
472+
_ => Err(OperationError::UnknownHelpTopic(topic)),
473+
};
475474
}
476475
let mut free_matches = matches.free.iter();
477476

@@ -734,6 +733,25 @@ impl CliOptions for GetOptsOptions {
734733
fn config_path(&self) -> Option<&Path> {
735734
self.config_path.as_deref()
736735
}
736+
737+
fn edition(&self) -> Option<Edition> {
738+
self.inline_config
739+
.get("edition")
740+
.map_or(self.edition, |e| Edition::from_str(e).ok())
741+
}
742+
743+
fn style_edition(&self) -> Option<StyleEdition> {
744+
self.inline_config
745+
.get("style_edition")
746+
.map_or(self.style_edition, |se| StyleEdition::from_str(se).ok())
747+
}
748+
749+
fn version(&self) -> Option<Version> {
750+
self.inline_config
751+
.get("version")
752+
.map(|version| Version::from_str(version).ok())
753+
.flatten()
754+
}
737755
}
738756

739757
fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
@@ -802,6 +820,17 @@ mod test {
802820
options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]);
803821
let config = get_config(None, Some(options));
804822
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
823+
assert_eq!(config.overflow_delimited_expr(), true);
824+
}
825+
826+
#[nightly_only_test]
827+
#[test]
828+
fn version_config_file_sets_style_edition_override_correctly() {
829+
let options = GetOptsOptions::default();
830+
let config_file = Some(Path::new("tests/config/style-edition/just-version"));
831+
let config = get_config(config_file, Some(options));
832+
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
833+
assert_eq!(config.overflow_delimited_expr(), true);
805834
}
806835

807836
#[nightly_only_test]
@@ -846,6 +875,7 @@ mod test {
846875
]);
847876
let config = get_config(None, Some(options));
848877
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
878+
assert_eq!(config.overflow_delimited_expr(), true);
849879
}
850880

851881
#[nightly_only_test]
@@ -903,4 +933,36 @@ mod test {
903933
let config = get_config(config_file, Some(options));
904934
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
905935
}
936+
937+
#[nightly_only_test]
938+
#[test]
939+
fn correct_defaults_for_style_edition_loaded() {
940+
let mut options = GetOptsOptions::default();
941+
options.style_edition = Some(StyleEdition::Edition2024);
942+
let config = get_config(None, Some(options));
943+
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
944+
assert_eq!(config.overflow_delimited_expr(), true);
945+
}
946+
947+
#[nightly_only_test]
948+
#[test]
949+
fn style_edition_defaults_overridden_from_config() {
950+
let options = GetOptsOptions::default();
951+
let config_file = Some(Path::new("tests/config/style-edition/overrides"));
952+
let config = get_config(config_file, Some(options));
953+
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
954+
assert_eq!(config.overflow_delimited_expr(), false);
955+
}
956+
957+
#[nightly_only_test]
958+
#[test]
959+
fn style_edition_defaults_overridden_from_cli() {
960+
let mut options = GetOptsOptions::default();
961+
let config_file = Some(Path::new("tests/config/style-edition/just-style-edition"));
962+
options.inline_config =
963+
HashMap::from([("overflow_delimited_expr".to_owned(), "false".to_owned())]);
964+
let config = get_config(config_file, Some(options));
965+
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
966+
assert_eq!(config.overflow_delimited_expr(), false);
967+
}
906968
}

0 commit comments

Comments
 (0)