Skip to content

subtree-push nightly-2024-04-08 #6140

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

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ae760e6
Address unused tuple struct fields in rustfmt
shepmaster Nov 29, 2023
4a1b418
Rename `unused_tuple_struct_fields` in rustfmt
shepmaster Nov 30, 2023
840824f
Rename `EmitterWriter` as `HumanEmitter`.
nnethercote Jan 4, 2024
250d7e7
Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obk
compiler-errors Jan 5, 2024
141b31a
Make `DiagnosticBuilder::emit` consuming.
nnethercote Jan 3, 2024
192c4a0
Change how `force-warn` lint diagnostics are recorded.
nnethercote Jan 9, 2024
381ef81
Stop using `DiagnosticBuilder::buffer` in the parser.
nnethercote Jan 11, 2024
6078b96
Delegation implementation: step 1
Bryanskiy Nov 26, 2023
255d2cf
Add `PatKind::Err`
ShE3py Jan 17, 2024
b92320c
Check that a token can begin a nonterminal kind before parsing it as …
compiler-errors Jan 22, 2024
f8847ff
Do not eagerly recover malformed AST in rustfmt
compiler-errors Jan 22, 2024
a095808
Actually, just use nonterminal_may_begin_with
compiler-errors Jan 22, 2024
18f51f7
Make `Emitter::emit_diagnostic` consuming.
nnethercote Feb 2, 2024
88c5838
Lower anonymous structs or unions to HIR
frank-king Jan 4, 2024
16250ea
Add rustfmt test from #117942
frank-king Jan 6, 2024
bed3883
Format async bounds in rustfmt
compiler-errors Feb 13, 2024
e504c64
Rollup merge of #121035 - compiler-errors:rustfmt-asyncness, r=calebc…
GuillaumeGomez Feb 14, 2024
6674be9
Add an `ErrorGuaranteed` to `ast::TyKind::Err`.
nnethercote Feb 14, 2024
aba5f54
errors: only eagerly translate subdiagnostics
davidtwco Feb 14, 2024
2639101
Allow newly added non_local_definitions in rustfmt
Urgau Jan 27, 2024
163c3eb
Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nneth…
matthiaskrgr Feb 17, 2024
ce71137
Explicitly call `emit_stashed_diagnostics`.
nnethercote Feb 23, 2024
8c33745
Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
bors Feb 25, 2024
7d82dd0
Add `ast::ExprKind::Dummy`
ShE3py Feb 25, 2024
1bbfb76
Add `ErrorGuaranteed` to `ast::ExprKind::Err`
ShE3py Feb 25, 2024
90af751
Move `emit_stashed_diagnostic` call in rustfmt.
nnethercote Feb 25, 2024
50987bb
Auto merge of #120586 - ShE3py:exprkind-err, r=fmease
bors Feb 26, 2024
c18226d
Rollup merge of #121615 - nnethercote:fix-121517, r=oli-obk
matthiaskrgr Feb 26, 2024
f9dba39
Auto merge of #121636 - matthiaskrgr:rollup-1tt2o5n, r=matthiaskrgr
bors Feb 26, 2024
d84567c
Rename `Diagnostic` as `DiagInner`.
nnethercote Feb 22, 2024
4026fd7
Rename `DiagnosticBuilder` as `Diag`.
nnethercote Feb 22, 2024
45aad17
Reinstate `emit_stashed_diagnostics` in `DiagCtxtInner::drop`.
nnethercote Feb 28, 2024
0811e8f
Rename `DiagCtxt::with_emitter` as `DiagCtxt::new`.
nnethercote Feb 29, 2024
9c85ae8
Inline and remove `HumanEmitter::stderr`.
nnethercote Feb 29, 2024
6f2722b
Rollup merge of #121783 - nnethercote:emitter-cleanups, r=oli-obk
GuillaumeGomez Feb 29, 2024
fc64cbd
AST: Refactor type alias where clauses
fmease Feb 19, 2024
050610e
Rollup merge of #121326 - fmease:detect-empty-leading-where-clauses-o…
matthiaskrgr Feb 29, 2024
0b56261
Tweak `parse_asm_args`.
nnethercote Dec 20, 2023
78c99eb
Rename all `ParseSess` variables/fields/lifetimes as `psess`.
nnethercote Mar 4, 2024
fe9ceab
Rename `DiagnosticMessage` as `DiagMessage`.
nnethercote Feb 29, 2024
124808b
errors: share `SilentEmitter` between rustc and rustfmt
davidtwco Feb 19, 2024
677c1d8
Rewrite the `untranslatable_diagnostic` lint.
nnethercote Feb 20, 2024
f3892a0
Add MatchKind member to the Match expr for pretty printing & fmt
RossSmyth Feb 17, 2024
1709dd5
Add basic rustfmt implementation & test
RossSmyth Feb 17, 2024
5f8d353
Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnosti…
matthiaskrgr Mar 6, 2024
fe0415e
Rename `ast::StmtKind::Local` into `ast::StmtKind::Let`
GuillaumeGomez Mar 14, 2024
911f6a4
conditionally ignore fatal diagnostic in the SilentEmitter
ytmimi Mar 19, 2024
8f62a2d
step cfgs
Mark-Simulacrum Mar 19, 2024
f670f3b
Implement macro-based deref!() syntax for deref patterns
compiler-errors Mar 20, 2024
0aa66d1
Rollup merge of #121619 - RossSmyth:pfix_match, r=petrochenkov
matthiaskrgr Mar 22, 2024
5e141e0
Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnosti…
matthiaskrgr Mar 24, 2024
645b94c
Implement `mut ref`/`mut ref mut`
Jules-Bertholet Mar 24, 2024
31a4eae
Add rustfmt test for mut ref mut
Jules-Bertholet Mar 27, 2024
1ed0da9
Merge remote-tracking branch 'upstream/master' into subtree-push-nigh…
ytmimi Apr 8, 2024
6e4105f
fix dead code and redundant import warnings
ytmimi Apr 8, 2024
9ede626
bump rust toolchain to nightly-2024-04-08
ytmimi Apr 8, 2024
732855d
Bumped bytecount `0.6.4` -> `0.6.8`
ytmimi Apr 20, 2024
919fb28
remove archived `error-chain` crate from integration tests
ytmimi Apr 20, 2024
35ad744
don't apply formatting to builtin type ascription syntax
ytmimi May 6, 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
1 change: 0 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
matrix:
integration: [
bitflags,
error-chain,
log,
mdbook,
packed_simd,
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
## [Unreleased]

- Updating `dirs 4.0.0 -> 5.0.1` and `cargo_metadata 0.15.4 -> 0.18.0` [#6033] (https://github.com/rust-lang/rustfmt/issues/6033)
- Bumped bytecount `0.6.4` -> `0.6.8` to fix compilation issues with the `generic-simd` feature. See [bytecount#92] and [bytecount#93]

[bytecount#92]: https://github.com/llogiq/bytecount/pull/92
[bytecount#93]: https://github.com/llogiq/bytecount/pull/93

- Output correct syntax for type ascription builtin [#6159](https://github.com/rust-lang/rustfmt/issues/6159)
```rust
fn main() {
builtin # type_ascribe(10, usize)
}
```

## [1.7.0] 2023-10-22

Expand Down
33 changes: 2 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ generic-simd = ["bytecount/generic-simd"]
[dependencies]
annotate-snippets = { version = "0.9", features = ["color"] }
anyhow = "1.0"
bytecount = "0.6.4"
bytecount = "0.6.8"
cargo_metadata = "0.18"
clap = { version = "4.4.2", features = ["derive"] }
clap-cargo = "0.12.0"
Expand Down
2 changes: 1 addition & 1 deletion ci/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ case ${INTEGRATION} in
check_fmt_with_all_tests
cd -
;;
error-chain | tempdir)
tempdir)
git clone --depth=1 https://github.com/rust-lang-deprecated/${INTEGRATION}.git
cd ${INTEGRATION}
show_head
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-12-28"
channel = "nightly-2024-04-08"
components = ["llvm-tools", "rustc-dev"]
2 changes: 1 addition & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {

pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
match stmt.kind {
ast::StmtKind::Local(ref local) => local.span,
ast::StmtKind::Let(ref local) => local.span,
ast::StmtKind::Item(ref item) => item.span,
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span,
ast::StmtKind::MacCall(ref mac_stmt) => mac_stmt.mac.span(),
Expand Down
4 changes: 2 additions & 2 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,10 +1718,10 @@ pub(crate) fn recover_comment_removed(
// We missed some comments. Warn and keep the original text.
if context.config.error_on_unformatted() {
context.report.append(
context.parse_sess.span_to_filename(span),
context.psess.span_to_filename(span),
vec![FormattingError::from_span(
span,
context.parse_sess,
context.psess,
ErrorKind::LostComment,
)],
);
Expand Down
2 changes: 1 addition & 1 deletion src/config/style_edition.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::config::StyleEdition;

/// Defines the default value for the given style edition
#[allow(dead_code)]
pub(crate) trait StyleEditionDefault {
type ConfigType;
fn style_edition_default(style_edition: StyleEdition) -> Self::ConfigType;
Expand Down Expand Up @@ -39,7 +40,6 @@ macro_rules! style_edition_default {
#[cfg(test)]
mod test {
use super::*;
use crate::config::StyleEdition;

#[test]
fn test_impl_default_style_edition_struct_for_all_editions() {
Expand Down
21 changes: 7 additions & 14 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::min;

use itertools::Itertools;
use rustc_ast::token::{Delimiter, Lit, LitKind};
use rustc_ast::{ast, ptr, token, ForLoopKind};
use rustc_ast::{ast, ptr, token, ForLoopKind, MatchKind};
use rustc_span::{BytePos, Span};

use crate::chains::rewrite_chain;
Expand Down Expand Up @@ -170,8 +170,8 @@ pub(crate) fn format_expr(
}
}
}
ast::ExprKind::Match(ref cond, ref arms) => {
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs)
ast::ExprKind::Match(ref cond, ref arms, kind) => {
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs, kind)
}
ast::ExprKind::Path(ref qself, ref path) => {
rewrite_path(context, PathContext::Expr, qself, path, shape)
Expand Down Expand Up @@ -253,14 +253,6 @@ pub(crate) fn format_expr(
shape,
SeparatorPlace::Front,
),
ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair(
&**expr,
&**ty,
PairParts::infix(": "),
context,
shape,
SeparatorPlace::Back,
),
ast::ExprKind::Index(ref expr, ref index, _) => {
rewrite_index(&**expr, &**index, context, shape)
}
Expand Down Expand Up @@ -402,6 +394,7 @@ pub(crate) fn format_expr(
}
ast::ExprKind::Underscore => Some("_".to_owned()),
ast::ExprKind::FormatArgs(..)
| ast::ExprKind::Type(..)
| ast::ExprKind::IncludedBytes(..)
| ast::ExprKind::OffsetOf(..) => {
// These don't normally occur in the AST because macros aren't expanded. However,
Expand All @@ -410,7 +403,7 @@ pub(crate) fn format_expr(
// Also, rustfmt might get passed the output from `-Zunpretty=expanded`.
None
}
ast::ExprKind::Err => None,
ast::ExprKind::Err(_) | ast::ExprKind::Dummy => None,
};

expr_rw
Expand Down Expand Up @@ -631,7 +624,7 @@ pub(crate) fn rewrite_cond(
shape: Shape,
) -> Option<String> {
match expr.kind {
ast::ExprKind::Match(ref cond, _) => {
ast::ExprKind::Match(ref cond, _, MatchKind::Prefix) => {
// `match `cond` {`
let cond_shape = match context.config.indent_style() {
IndentStyle::Visual => shape.shrink_left(6).and_then(|s| s.sub_width(2))?,
Expand Down Expand Up @@ -1953,7 +1946,7 @@ fn rewrite_unary_op(
}

pub(crate) enum RhsAssignKind<'ast> {
Expr(&'ast ast::ExprKind, Span),
Expr(&'ast ast::ExprKind, #[allow(dead_code)] Span),
Bounds,
Ty,
}
Expand Down
54 changes: 23 additions & 31 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn should_skip_module<T: FormatHandler>(
// FIXME(calebcartwright) - we need to determine how we'll handle the
// `format_generated_files` option with stdin based input.
if !input_is_stdin && !config.format_generated_files() {
let source_file = context.parse_session.span_to_file_contents(module.span);
let source_file = context.psess.span_to_file_contents(module.span);
let src = source_file.src.as_ref().expect("SourceFile without src");

if is_generated_file(src, config) {
Expand Down Expand Up @@ -109,15 +109,16 @@ fn format_project<T: FormatHandler>(
let main_file = input.file_name();
let input_is_stdin = main_file == FileName::Stdin;

let parse_session = ParseSess::new(config)?;
if config.skip_children() && parse_session.ignore_file(&main_file) {
let psess = ParseSess::new(config)?;
if config.skip_children() && psess.ignore_file(&main_file) {
return Ok(FormatReport::new());
}

// Parse the crate.
let mut report = FormatReport::new();
let directory_ownership = input.to_directory_ownership();
let krate = match Parser::parse_crate(input, &parse_session) {

let krate = match Parser::parse_crate(input, &psess) {
Ok(krate) => krate,
// Surface parse error via Session (errors are merged there from report)
Err(e) => {
Expand All @@ -130,9 +131,9 @@ fn format_project<T: FormatHandler>(
}
};

let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
let mut context = FormatContext::new(&krate, report, psess, config, handler);
let files = modules::ModResolver::new(
&context.parse_session,
&context.psess,
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaBlock),
!input_is_stdin && !config.skip_children(),
)
Expand All @@ -147,16 +148,11 @@ fn format_project<T: FormatHandler>(
timer = timer.done_parsing();

// Suppress error output if we have to do any further parsing.
context.parse_session.set_silent_emitter();
context.psess.set_silent_emitter();

for (path, module) in files {
if input_is_stdin && contains_skip(module.attrs()) {
return echo_back_stdin(
context
.parse_session
.snippet_provider(module.span)
.entire_snippet(),
);
return echo_back_stdin(context.psess.snippet_provider(module.span).entire_snippet());
}
should_emit_verbose(input_is_stdin, config, || println!("Formatting {}", path));
context.format_file(path, &module, is_macro_def)?;
Expand All @@ -178,7 +174,7 @@ fn format_project<T: FormatHandler>(
struct FormatContext<'a, T: FormatHandler> {
krate: &'a ast::Crate,
report: FormatReport,
parse_session: ParseSess,
psess: ParseSess,
config: &'a Config,
handler: &'a mut T,
}
Expand All @@ -187,21 +183,21 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
fn new(
krate: &'a ast::Crate,
report: FormatReport,
parse_session: ParseSess,
psess: ParseSess,
config: &'a Config,
handler: &'a mut T,
) -> Self {
FormatContext {
krate,
report,
parse_session,
psess,
config,
handler,
}
}

fn ignore_file(&self, path: &FileName) -> bool {
self.parse_session.ignore_file(path)
self.psess.ignore_file(path)
}

// Formats a single file/module.
Expand All @@ -211,9 +207,9 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
module: &Module<'_>,
is_macro_def: bool,
) -> Result<(), ErrorKind> {
let snippet_provider = self.parse_session.snippet_provider(module.span);
let mut visitor = FmtVisitor::from_parse_sess(
&self.parse_session,
let snippet_provider = self.psess.snippet_provider(module.span);
let mut visitor = FmtVisitor::from_psess(
&self.psess,
self.config,
&snippet_provider,
self.report.clone(),
Expand Down Expand Up @@ -256,7 +252,7 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
.add_non_formatted_ranges(visitor.skipped_range.borrow().clone());

self.handler.handle_formatted_file(
&self.parse_session,
&self.psess,
path,
visitor.buffer.to_owned(),
&mut self.report,
Expand All @@ -268,7 +264,7 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
trait FormatHandler {
fn handle_formatted_file(
&mut self,
parse_session: &ParseSess,
psess: &ParseSess,
path: FileName,
result: String,
report: &mut FormatReport,
Expand All @@ -279,14 +275,14 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> {
// Called for each formatted file.
fn handle_formatted_file(
&mut self,
parse_session: &ParseSess,
psess: &ParseSess,
path: FileName,
result: String,
report: &mut FormatReport,
) -> Result<(), ErrorKind> {
if let Some(ref mut out) = self.out {
match source_file::write_file(
Some(parse_session),
Some(psess),
&path,
&result,
out,
Expand Down Expand Up @@ -317,17 +313,13 @@ pub(crate) struct FormattingError {
}

impl FormattingError {
pub(crate) fn from_span(
span: Span,
parse_sess: &ParseSess,
kind: ErrorKind,
) -> FormattingError {
pub(crate) fn from_span(span: Span, psess: &ParseSess, kind: ErrorKind) -> FormattingError {
FormattingError {
line: parse_sess.line_of_byte_pos(span.lo()),
line: psess.line_of_byte_pos(span.lo()),
is_comment: kind.is_comment(),
kind,
is_string: false,
line_buffer: parse_sess.span_to_first_line_string(span),
line_buffer: psess.span_to_first_line_string(span),
}
}

Expand Down
Loading
Loading