From 76be14b5cadd56e18af721c830c5592621b19cb7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 7 Aug 2022 15:21:11 +0200 Subject: [PATCH 01/28] Do not consider method call receiver as an argument in AST. --- src/chains.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index e26e24ec55a..fcc02eca429 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -145,7 +145,7 @@ impl ChainItemKind { fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) { let (kind, span) = match expr.kind { - ast::ExprKind::MethodCall(ref segment, ref expressions, _) => { + ast::ExprKind::MethodCall(ref segment, ref receiver, ref expressions, _) => { let types = if let Some(ref generic_args) = segment.args { if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args { data.args @@ -163,7 +163,7 @@ impl ChainItemKind { } else { vec![] }; - let span = mk_sp(expressions[0].span.hi(), expr.span.hi()); + let span = mk_sp(receiver.span.hi(), expr.span.hi()); let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone()); (kind, span) } @@ -253,7 +253,7 @@ impl ChainItem { format!("::<{}>", type_list.join(", ")) }; let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str); - rewrite_call(context, &callee_str, &args[1..], span, shape) + rewrite_call(context, &callee_str, &args, span, shape) } } @@ -400,8 +400,8 @@ impl Chain { // is a try! macro, we'll convert it to shorthand when the option is set. fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option { match expr.kind { - ast::ExprKind::MethodCall(_, ref expressions, _) => { - Some(Self::convert_try(&expressions[0], context)) + ast::ExprKind::MethodCall(_, ref receiver, _, _) => { + Some(Self::convert_try(&receiver, context)) } ast::ExprKind::Field(ref subexpr, _) | ast::ExprKind::Try(ref subexpr) From edb616df3372e75bb501b871906901b834821106 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 10 Aug 2022 17:30:47 +0100 Subject: [PATCH 02/28] errors: move translation logic into module Just moving code around so that triagebot can ping relevant parties when translation logic is modified. Signed-off-by: David Wood --- src/parse/session.rs | 54 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/parse/session.rs b/src/parse/session.rs index 23db5421910..6efeee98fea 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use rustc_data_structures::sync::{Lrc, Send}; use rustc_errors::emitter::{Emitter, EmitterWriter}; +use rustc_errors::translation::Translate; use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel}; use rustc_session::parse::ParseSess as RawParseSess; use rustc_span::{ @@ -28,17 +29,22 @@ pub(crate) struct ParseSess { /// Emitter which discards every error. struct SilentEmitter; +impl Translate for SilentEmitter { + fn fluent_bundle(&self) -> Option<&Lrc> { + None + } + + fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { + panic!("silent emitter attempted to translate a diagnostic"); + } +} + impl Emitter for SilentEmitter { fn source_map(&self) -> Option<&Lrc> { None } + fn emit_diagnostic(&mut self, _db: &Diagnostic) {} - fn fluent_bundle(&self) -> Option<&Lrc> { - None - } - fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { - panic!("silent emitter attempted to translate a diagnostic"); - } } fn silent_emitter() -> Box { @@ -62,10 +68,21 @@ impl SilentOnIgnoredFilesEmitter { } } +impl Translate for SilentOnIgnoredFilesEmitter { + fn fluent_bundle(&self) -> Option<&Lrc> { + self.emitter.fluent_bundle() + } + + fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { + self.emitter.fallback_fluent_bundle() + } +} + impl Emitter for SilentOnIgnoredFilesEmitter { fn source_map(&self) -> Option<&Lrc> { None } + fn emit_diagnostic(&mut self, db: &Diagnostic) { if db.level() == DiagnosticLevel::Fatal { return self.handle_non_ignoreable_error(db); @@ -88,14 +105,6 @@ impl Emitter for SilentOnIgnoredFilesEmitter { } self.handle_non_ignoreable_error(db); } - - fn fluent_bundle(&self) -> Option<&Lrc> { - self.emitter.fluent_bundle() - } - - fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { - self.emitter.fallback_fluent_bundle() - } } fn default_handler( @@ -340,19 +349,24 @@ mod tests { num_emitted_errors: Lrc, } + impl Translate for TestEmitter { + fn fluent_bundle(&self) -> Option<&Lrc> { + None + } + + fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { + panic!("test emitter attempted to translate a diagnostic"); + } + } + impl Emitter for TestEmitter { fn source_map(&self) -> Option<&Lrc> { None } + fn emit_diagnostic(&mut self, _db: &Diagnostic) { self.num_emitted_errors.fetch_add(1, Ordering::Release); } - fn fluent_bundle(&self) -> Option<&Lrc> { - None - } - fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { - panic!("test emitter attempted to translate a diagnostic"); - } } fn build_diagnostic(level: DiagnosticLevel, span: Option) -> Diagnostic { From e97825ed5ef3975ff6b138e16147802979df4ef3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Aug 2022 21:06:11 +1000 Subject: [PATCH 03/28] Shrink `ast::Attribute`. --- src/skip.rs | 4 ++-- src/visitor.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/skip.rs b/src/skip.rs index 0fdc097efc2..032922d421d 100644 --- a/src/skip.rs +++ b/src/skip.rs @@ -58,8 +58,8 @@ fn get_skip_names(kind: &str, attrs: &[ast::Attribute]) -> Vec { for attr in attrs { // rustc_ast::ast::Path is implemented partialEq // but it is designed for segments.len() == 1 - if let ast::AttrKind::Normal(attr_item, _) = &attr.kind { - if pprust::path_to_string(&attr_item.path) != path { + if let ast::AttrKind::Normal(normal) = &attr.kind { + if pprust::path_to_string(&normal.item.path) != path { continue; } } diff --git a/src/visitor.rs b/src/visitor.rs index 9a0e0752c12..7bb745eeb8b 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -811,8 +811,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ); } else { match &attr.kind { - ast::AttrKind::Normal(ref attribute_item, _) - if self.is_unknown_rustfmt_attr(&attribute_item.path.segments) => + ast::AttrKind::Normal(ref normal) + if self.is_unknown_rustfmt_attr(&normal.item.path.segments) => { let file_name = self.parse_sess.span_to_filename(attr.span); self.report.append( From e5b5f56d4329159961095bdaca3f608fc097f930 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 1 Aug 2022 16:46:08 +1000 Subject: [PATCH 04/28] Rename some things related to literals. - Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is `token::Lit`, which is not a token. (This has been confusing me for a long time.) reasonable because we have an `ast::token::Lit` inside an `ast::Lit`. - Rename `LitKind::{from,to}_lit_token` as `LitKind::{from,to}_token_lit`, to match the above change and `token::Lit`. --- src/expr.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index a7b73ba78c5..3105882e2d3 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -79,7 +79,7 @@ pub(crate) fn format_expr( if let Some(expr_rw) = rewrite_literal(context, l, shape) { Some(expr_rw) } else { - if let LitKind::StrRaw(_) = l.token.kind { + if let LitKind::StrRaw(_) = l.token_lit.kind { Some(context.snippet(l.span).trim().into()) } else { None @@ -1226,7 +1226,7 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) -> fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -> Option { let span = lit.span; - let symbol = lit.token.symbol.as_str(); + let symbol = lit.token_lit.symbol.as_str(); if let Some(symbol_stripped) = symbol.strip_prefix("0x") { let hex_lit = match context.config.hex_literal_case() { @@ -1239,7 +1239,9 @@ fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) - format!( "0x{}{}", hex_lit, - lit.token.suffix.map_or(String::new(), |s| s.to_string()) + lit.token_lit + .suffix + .map_or(String::new(), |s| s.to_string()) ), context.config.max_width(), shape, From 05a0dfe8cd4db51a08d11ab24cc1586c833e2df1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 17 Aug 2022 12:34:33 +1000 Subject: [PATCH 05/28] Use `AttrVec` in more places. In some places we use `Vec` and some places we use `ThinVec` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently. --- src/attr.rs | 5 +---- src/imports.rs | 4 ++-- src/modules.rs | 8 ++++---- src/parse/parser.rs | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index 41ba9a847e6..f5c1ee5fdd1 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -49,10 +49,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span { } /// Returns attributes that are within `outer_span`. -pub(crate) fn filter_inline_attrs( - attrs: &[ast::Attribute], - outer_span: Span, -) -> Vec { +pub(crate) fn filter_inline_attrs(attrs: &[ast::Attribute], outer_span: Span) -> ast::AttrVec { attrs .iter() .filter(|a| outer_span.lo() <= a.span.lo() && a.span.hi() <= outer_span.hi()) diff --git a/src/imports.rs b/src/imports.rs index 8d41c881589..b6530c69243 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -116,7 +116,7 @@ pub(crate) struct UseTree { // Additional fields for top level use items. // Should we have another struct for top-level use items rather than reusing this? visibility: Option, - attrs: Option>, + attrs: Option, } impl PartialEq for UseTree { @@ -417,7 +417,7 @@ impl UseTree { list_item: Option, visibility: Option, opt_lo: Option, - attrs: Option>, + attrs: Option, ) -> UseTree { let span = if let Some(lo) = opt_lo { mk_sp(lo, a.span.hi()) diff --git a/src/modules.rs b/src/modules.rs index 81da724329f..7a0d1736c59 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -26,7 +26,7 @@ type FileModMap<'ast> = BTreeMap>; pub(crate) struct Module<'a> { ast_mod_kind: Option>, pub(crate) items: Cow<'a, Vec>>, - inner_attr: Vec, + inner_attr: ast::AttrVec, pub(crate) span: Span, } @@ -35,7 +35,7 @@ impl<'a> Module<'a> { mod_span: Span, ast_mod_kind: Option>, mod_items: Cow<'a, Vec>>, - mod_attrs: Cow<'a, Vec>, + mod_attrs: Cow<'a, ast::AttrVec>, ) -> Self { let inner_attr = mod_attrs .iter() @@ -158,7 +158,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { module_item.item.span, Some(Cow::Owned(sub_mod_kind.clone())), Cow::Owned(vec![]), - Cow::Owned(vec![]), + Cow::Owned(ast::AttrVec::new()), ), )?; } @@ -185,7 +185,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { span, Some(Cow::Owned(sub_mod_kind.clone())), Cow::Owned(vec![]), - Cow::Owned(vec![]), + Cow::Owned(ast::AttrVec::new()), ), )?; } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 268c72649a6..e0bd065518b 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -109,7 +109,7 @@ impl<'a> Parser<'a> { sess: &'a ParseSess, path: &Path, span: Span, - ) -> Result<(Vec, Vec>, Span), ParserError> { + ) -> Result<(ast::AttrVec, Vec>, Span), ParserError> { let result = catch_unwind(AssertUnwindSafe(|| { let mut parser = new_parser_from_file(sess.inner(), path, Some(span)); match parser.parse_mod(&TokenKind::Eof) { From 7852b8808b1691f956d8928b3f9ca140cf93feb8 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 14 Jul 2022 08:30:38 -0500 Subject: [PATCH 06/28] Stabilize `#![feature(label_break_value)]` # Stabilization proposal The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now). There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`. There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed). 1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234 2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176 3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630 Many different examples of code that's simpler using this feature have been provided: - A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014 - A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize). - Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395 - Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733 - An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569 - Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006 Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249 nrc later resolved their concern, mostly because of the aforementioned macro problems. joshtriplett suggested that macros could be able to generate IR directly (https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs, and the design space seems rather speculative. joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804 withoutboats has regrettably left the language team. joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353 [issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+ ## Report + Feature gate: - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/src/test/ui/feature-gates/feature-gate-label_break_value.rs + Diagnostics: - https://github.com/rust-lang/rust/blob/6b2d3d5f3cd1e553d87b5496632132565b6779d3/compiler/rustc_parse/src/parser/diagnostics.rs#L2629 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L749 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L1001 - https://github.com/rust-lang/rust/blob/111df9e6eda1d752233482c1309d00d20a4bbf98/compiler/rustc_passes/src/loops.rs#L254 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L2079 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L1569 + Tests: - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs ## Interactions with other features Labels follow the hygiene of local variables. label-break-value is permitted within `try` blocks: ```rust let _: Result<(), ()> = try { 'foo: { Err(())?; break 'foo; } }; ``` label-break-value is disallowed within closures, generators, and async blocks: ```rust 'a: { || break 'a //~^ ERROR use of unreachable label `'a` //~| ERROR `break` inside of a closure } ``` label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]: ```rust fn labeled_match() { match false 'b: { //~ ERROR block label not supported here _ => {} } } macro_rules! m { ($b:block) => { 'lab: $b; //~ ERROR cannot use a `block` macro fragment here unsafe $b; //~ ERROR cannot use a `block` macro fragment here |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here } } fn foo() { m!({}); } ``` [_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html [_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html --- tests/source/issue-3217.rs | 2 -- tests/target/issue-3217.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/tests/source/issue-3217.rs b/tests/source/issue-3217.rs index 176c702002a..e68ca2c5907 100644 --- a/tests/source/issue-3217.rs +++ b/tests/source/issue-3217.rs @@ -1,5 +1,3 @@ -#![feature(label_break_value)] - fn main() { let mut res = 0; 's_39: { if res == 0i32 { println!("Hello, world!"); } } diff --git a/tests/target/issue-3217.rs b/tests/target/issue-3217.rs index 5121320a097..403bf4c340a 100644 --- a/tests/target/issue-3217.rs +++ b/tests/target/issue-3217.rs @@ -1,5 +1,3 @@ -#![feature(label_break_value)] - fn main() { let mut res = 0; 's_39: { From ddda7bbe5dfc3884857a90efe9dfd4dfc3eb85e1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 20 Aug 2022 21:19:43 -0700 Subject: [PATCH 07/28] Sunset RLS --- Processes.md | 4 ---- README.md | 2 +- atom.md | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Processes.md b/Processes.md index 9d86d52b122..f763b5714ce 100644 --- a/Processes.md +++ b/Processes.md @@ -51,7 +51,3 @@ git tag -s v1.2.3 -m "Release 1.2.3" `cargo publish` ## 5. Create a PR to rust-lang/rust to update the rustfmt submodule - -Note that if you are updating `rustc-ap-*` crates, then you need to update **every** submodules in the rust-lang/rust repository that depend on the crates to use the same version of those. - -As of 2019/05, there are two such crates: `rls` and `racer` (`racer` depends on `rustc-ap-syntax` and `rls` depends on `racer`, and `rls` is one of submodules of the rust-lang/rust repository). diff --git a/README.md b/README.md index b3a968f0c04..0f9652aecf9 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ completed without error (whether or not changes were made). * [Emacs](https://github.com/rust-lang/rust-mode) * [Sublime Text 3](https://packagecontrol.io/packages/RustFmt) * [Atom](atom.md) -* Visual Studio Code using [vscode-rust](https://github.com/editor-rs/vscode-rust), [vsc-rustfmt](https://github.com/Connorcpu/vsc-rustfmt) or [rls_vscode](https://github.com/jonathandturner/rls_vscode) through RLS. +* [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) * [IntelliJ or CLion](intellij.md) diff --git a/atom.md b/atom.md index f77ac149072..c7e3a991a5f 100644 --- a/atom.md +++ b/atom.md @@ -1,8 +1,8 @@ # Running Rustfmt from Atom -## RLS +## rust-analyzer -Rustfmt is included with the Rust Language Server, itself provided by [ide-rust](https://atom.io/packages/ide-rust). +Rustfmt can be utilized from [rust-analyzer](https://rust-analyzer.github.io/) which is provided by [ide-rust](https://atom.io/packages/ide-rust). `apm install ide-rust` From 748b031056f109b0e2e58ab1e2f0189b83c32f3e Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Wed, 4 May 2022 10:22:19 -0400 Subject: [PATCH 08/28] Stabilize GATs --- tests/source/issue_4257.rs | 3 --- tests/source/issue_4911.rs | 1 - tests/source/issue_4943.rs | 2 -- tests/target/issue_4257.rs | 3 --- tests/target/issue_4911.rs | 1 - tests/target/issue_4943.rs | 2 -- 6 files changed, 12 deletions(-) diff --git a/tests/source/issue_4257.rs b/tests/source/issue_4257.rs index 2b887fadb62..9482512efca 100644 --- a/tests/source/issue_4257.rs +++ b/tests/source/issue_4257.rs @@ -1,6 +1,3 @@ -#![feature(generic_associated_types)] -#![allow(incomplete_features)] - trait Trait { type Type<'a> where T: 'a; fn foo(x: &T) -> Self::Type<'_>; diff --git a/tests/source/issue_4911.rs b/tests/source/issue_4911.rs index 21ef6c6c491..c254db7b509 100644 --- a/tests/source/issue_4911.rs +++ b/tests/source/issue_4911.rs @@ -1,4 +1,3 @@ -#![feature(generic_associated_types)] #![feature(min_type_alias_impl_trait)] impl SomeTrait for SomeType { diff --git a/tests/source/issue_4943.rs b/tests/source/issue_4943.rs index 0793b7b4fe1..307d9a4a1ab 100644 --- a/tests/source/issue_4943.rs +++ b/tests/source/issue_4943.rs @@ -1,5 +1,3 @@ -#![feature(generic_associated_types)] - impl SomeStruct { fn process(v: T) -> ::R where Self: GAT = T> diff --git a/tests/target/issue_4257.rs b/tests/target/issue_4257.rs index 1ebaaf2b600..309a66c8dc3 100644 --- a/tests/target/issue_4257.rs +++ b/tests/target/issue_4257.rs @@ -1,6 +1,3 @@ -#![feature(generic_associated_types)] -#![allow(incomplete_features)] - trait Trait { type Type<'a> where diff --git a/tests/target/issue_4911.rs b/tests/target/issue_4911.rs index 890a62267ce..0f64aa7f766 100644 --- a/tests/target/issue_4911.rs +++ b/tests/target/issue_4911.rs @@ -1,4 +1,3 @@ -#![feature(generic_associated_types)] #![feature(min_type_alias_impl_trait)] impl SomeTrait for SomeType { diff --git a/tests/target/issue_4943.rs b/tests/target/issue_4943.rs index 318f7ebed6e..bc8f1a366da 100644 --- a/tests/target/issue_4943.rs +++ b/tests/target/issue_4943.rs @@ -1,5 +1,3 @@ -#![feature(generic_associated_types)] - impl SomeStruct { fn process(v: T) -> ::R where From e40972ebf86040de884d5b5b54e3345af504c140 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 30 Aug 2022 17:39:36 -0500 Subject: [PATCH 09/28] rustfmt: BindingAnnotation change --- src/patterns.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/patterns.rs b/src/patterns.rs index 9b74b35f314..e2fe92b28f2 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -1,4 +1,6 @@ -use rustc_ast::ast::{self, BindingMode, Pat, PatField, PatKind, RangeEnd, RangeSyntax}; +use rustc_ast::ast::{ + self, BindingAnnotation, ByRef, Pat, PatField, PatKind, RangeEnd, RangeSyntax, +}; use rustc_ast::ptr; use rustc_span::{BytePos, Span}; @@ -99,10 +101,10 @@ impl Rewrite for Pat { write_list(&items, &fmt) } PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape), - PatKind::Ident(binding_mode, ident, ref sub_pat) => { - let (prefix, mutability) = match binding_mode { - BindingMode::ByRef(mutability) => ("ref", mutability), - BindingMode::ByValue(mutability) => ("", mutability), + PatKind::Ident(BindingAnnotation(by_ref, mutability), ident, ref sub_pat) => { + let prefix = match by_ref { + ByRef::Yes => "ref", + ByRef::No => "", }; let mut_infix = format_mutability(mutability).trim(); let id_str = rewrite_ident(context, ident); From d71413cbfae7a8c7fb7d2534f7240915161ce46a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 10 Oct 2022 02:05:24 +0000 Subject: [PATCH 10/28] Rename AssocItemKind::TyAlias to AssocItemKind::Type --- src/items.rs | 12 ++++++------ src/visitor.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/items.rs b/src/items.rs index 8f35068e35f..a2a73f0a5fb 100644 --- a/src/items.rs +++ b/src/items.rs @@ -594,7 +594,7 @@ impl<'a> FmtVisitor<'a> { let both_type = |l: &TyOpt, r: &TyOpt| is_type(l) && is_type(r); let both_opaque = |l: &TyOpt, r: &TyOpt| is_opaque(l) && is_opaque(r); let need_empty_line = |a: &ast::AssocItemKind, b: &ast::AssocItemKind| match (a, b) { - (TyAlias(lty), TyAlias(rty)) + (Type(lty), Type(rty)) if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) => { false @@ -612,7 +612,7 @@ impl<'a> FmtVisitor<'a> { } buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) { - (TyAlias(lty), TyAlias(rty)) + (Type(lty), Type(rty)) if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) => { a.ident.as_str().cmp(b.ident.as_str()) @@ -621,10 +621,10 @@ impl<'a> FmtVisitor<'a> { a.ident.as_str().cmp(b.ident.as_str()) } (Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()), - (TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less, - (_, TyAlias(ty)) if is_type(&ty.ty) => Ordering::Greater, - (TyAlias(..), _) => Ordering::Less, - (_, TyAlias(..)) => Ordering::Greater, + (Type(ty), _) if is_type(&ty.ty) => Ordering::Less, + (_, Type(ty)) if is_type(&ty.ty) => Ordering::Greater, + (Type(..), _) => Ordering::Less, + (_, Type(..)) => Ordering::Greater, (Const(..), _) => Ordering::Less, (_, Const(..)) => Ordering::Greater, (MacCall(..), _) => Ordering::Less, diff --git a/src/visitor.rs b/src/visitor.rs index 7bb745eeb8b..9c3cc7820d2 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -660,7 +660,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.push_rewrite(ai.span, rewrite); } } - (ast::AssocItemKind::TyAlias(ref ty_alias), _) => { + (ast::AssocItemKind::Type(ref ty_alias), _) => { self.visit_ty_alias_kind(ty_alias, visitor_kind, ai.span); } (ast::AssocItemKind::MacCall(ref mac), _) => { From 7cc303fbf62f6a058064fc07026231a8a5ee533f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 10 Oct 2022 18:29:17 +0200 Subject: [PATCH 11/28] Fix unclosed HTML tag in rustfmt doc --- src/config/config_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/config_type.rs b/src/config/config_type.rs index e37ed798cb5..c5e61658ad1 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -4,7 +4,7 @@ use crate::config::options::{IgnoreList, WidthHeuristics}; /// Trait for types that can be used in `Config`. pub(crate) trait ConfigType: Sized { /// Returns hint text for use in `Config::print_docs()`. For enum types, this is a - /// pipe-separated list of variants; for other types it returns "". + /// pipe-separated list of variants; for other types it returns ``. fn doc_hint() -> String; } From 657dcf21d8e13265513451f354511a53ea2c3b04 Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Wed, 19 Oct 2022 00:08:20 +0200 Subject: [PATCH 12/28] Implement -Ztrack-diagnostics --- src/parse/session.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/parse/session.rs b/src/parse/session.rs index 6efeee98fea..6bfec79cd70 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -134,6 +134,7 @@ fn default_handler( false, None, false, + false, )) }; Handler::with_emitter( From 660e53512f1c25f03f6cf34fb620a7c0ed11d120 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 31 Oct 2022 18:30:09 +0000 Subject: [PATCH 13/28] Introduce `ExprKind::IncludedBytes` --- src/expr.rs | 1 + src/utils.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/expr.rs b/src/expr.rs index 3105882e2d3..7750df0fff3 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -399,6 +399,7 @@ pub(crate) fn format_expr( } } ast::ExprKind::Underscore => Some("_".to_owned()), + ast::ExprKind::IncludedBytes(..) => unreachable!(), ast::ExprKind::Err => None, }; diff --git a/src/utils.rs b/src/utils.rs index cd852855602..c47b3b314dd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -496,6 +496,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::Continue(..) | ast::ExprKind::Err | ast::ExprKind::Field(..) + | ast::ExprKind::IncludedBytes(..) | ast::ExprKind::InlineAsm(..) | ast::ExprKind::Let(..) | ast::ExprKind::Path(..) From 826fb78bebc757acf138e86bd755e1d81c1d08bc Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 10 Oct 2022 13:40:56 +1100 Subject: [PATCH 14/28] Use `token::Lit` in `ast::ExprKind::Lit`. Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773 --- src/attr.rs | 6 ++++-- src/expr.rs | 41 ++++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index f5c1ee5fdd1..ccc2fd0d5f5 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -260,7 +260,9 @@ impl Rewrite for ast::NestedMetaItem { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self { ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape), - ast::NestedMetaItem::Literal(ref l) => rewrite_literal(context, l, shape), + ast::NestedMetaItem::Literal(ref l) => { + rewrite_literal(context, l.token_lit, l.span, shape) + } } } } @@ -318,7 +320,7 @@ impl Rewrite for ast::MetaItem { // we might be better off ignoring the fact that the attribute // is longer than the max width and continue on formatting. // See #2479 for example. - let value = rewrite_literal(context, literal, lit_shape) + let value = rewrite_literal(context, literal.token_lit, literal.span, lit_shape) .unwrap_or_else(|| context.snippet(literal.span).to_owned()); format!("{} = {}", path, value) } diff --git a/src/expr.rs b/src/expr.rs index 7750df0fff3..b4f1a178dbf 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -3,7 +3,7 @@ use std::cmp::min; use itertools::Itertools; use rustc_ast::token::{Delimiter, LitKind}; -use rustc_ast::{ast, ptr}; +use rustc_ast::{ast, ptr, token}; use rustc_span::{BytePos, Span}; use crate::chains::rewrite_chain; @@ -75,12 +75,12 @@ pub(crate) fn format_expr( choose_separator_tactic(context, expr.span), None, ), - ast::ExprKind::Lit(ref l) => { - if let Some(expr_rw) = rewrite_literal(context, l, shape) { + ast::ExprKind::Lit(token_lit) => { + if let Some(expr_rw) = rewrite_literal(context, token_lit, expr.span, shape) { Some(expr_rw) } else { - if let LitKind::StrRaw(_) = l.token_lit.kind { - Some(context.snippet(l.span).trim().into()) + if let LitKind::StrRaw(_) = token_lit.kind { + Some(context.snippet(expr.span).trim().into()) } else { None } @@ -274,9 +274,9 @@ pub(crate) fn format_expr( fn needs_space_before_range(context: &RewriteContext<'_>, lhs: &ast::Expr) -> bool { match lhs.kind { - ast::ExprKind::Lit(ref lit) => match lit.kind { - ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => { - context.snippet(lit.span).ends_with('.') + ast::ExprKind::Lit(token_lit) => match token_lit.kind { + token::LitKind::Float if token_lit.suffix.is_none() => { + context.snippet(lhs.span).ends_with('.') } _ => false, }, @@ -1185,14 +1185,15 @@ pub(crate) fn is_unsafe_block(block: &ast::Block) -> bool { pub(crate) fn rewrite_literal( context: &RewriteContext<'_>, - l: &ast::Lit, + token_lit: token::Lit, + span: Span, shape: Shape, ) -> Option { - match l.kind { - ast::LitKind::Str(_, ast::StrStyle::Cooked) => rewrite_string_lit(context, l.span, shape), - ast::LitKind::Int(..) => rewrite_int_lit(context, l, shape), + match token_lit.kind { + token::LitKind::Str => rewrite_string_lit(context, span, shape), + token::LitKind::Integer => rewrite_int_lit(context, token_lit, span, shape), _ => wrap_str( - context.snippet(l.span).to_owned(), + context.snippet(span).to_owned(), context.config.max_width(), shape, ), @@ -1225,9 +1226,13 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) -> ) } -fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -> Option { - let span = lit.span; - let symbol = lit.token_lit.symbol.as_str(); +fn rewrite_int_lit( + context: &RewriteContext<'_>, + token_lit: token::Lit, + span: Span, + shape: Shape, +) -> Option { + let symbol = token_lit.symbol.as_str(); if let Some(symbol_stripped) = symbol.strip_prefix("0x") { let hex_lit = match context.config.hex_literal_case() { @@ -1240,9 +1245,7 @@ fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) - format!( "0x{}{}", hex_lit, - lit.token_lit - .suffix - .map_or(String::new(), |s| s.to_string()) + token_lit.suffix.map_or(String::new(), |s| s.to_string()) ), context.config.max_width(), shape, From 4a4addc5980e95e4f7883f2d56aedcd08626ba73 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 8 Sep 2022 10:52:51 +1000 Subject: [PATCH 15/28] Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns. --- src/attr.rs | 6 +++--- src/chains.rs | 12 +++++------- src/closures.rs | 30 +++++++++++++++++++----------- src/expr.rs | 26 +++++++++++++------------- src/patterns.rs | 9 ++++----- src/types.rs | 8 ++++---- src/utils.rs | 2 +- 7 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index ccc2fd0d5f5..23f55db773e 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -290,10 +290,10 @@ impl Rewrite for ast::MetaItem { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { Some(match self.kind { ast::MetaItemKind::Word => { - rewrite_path(context, PathContext::Type, None, &self.path, shape)? + rewrite_path(context, PathContext::Type, &None, &self.path, shape)? } ast::MetaItemKind::List(ref list) => { - let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?; + let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?; let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span); overflow::rewrite_with_parens( context, @@ -311,7 +311,7 @@ impl Rewrite for ast::MetaItem { )? } ast::MetaItemKind::NameValue(ref literal) => { - let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?; + let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?; // 3 = ` = ` let lit_shape = shape.shrink_left(path.len() + 3)?; // `rewrite_literal` returns `None` when `literal` exceeds max diff --git a/src/chains.rs b/src/chains.rs index fcc02eca429..a1a73cf4bd5 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -145,8 +145,8 @@ impl ChainItemKind { fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) { let (kind, span) = match expr.kind { - ast::ExprKind::MethodCall(ref segment, ref receiver, ref expressions, _) => { - let types = if let Some(ref generic_args) = segment.args { + ast::ExprKind::MethodCall(ref call) => { + let types = if let Some(ref generic_args) = call.seg.args { if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args { data.args .iter() @@ -163,8 +163,8 @@ impl ChainItemKind { } else { vec![] }; - let span = mk_sp(receiver.span.hi(), expr.span.hi()); - let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone()); + let span = mk_sp(call.receiver.span.hi(), expr.span.hi()); + let kind = ChainItemKind::MethodCall(call.seg.clone(), types, call.args.clone()); (kind, span) } ast::ExprKind::Field(ref nested, field) => { @@ -400,9 +400,7 @@ impl Chain { // is a try! macro, we'll convert it to shorthand when the option is set. fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option { match expr.kind { - ast::ExprKind::MethodCall(_, ref receiver, _, _) => { - Some(Self::convert_try(&receiver, context)) - } + ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)), ast::ExprKind::Field(ref subexpr, _) | ast::ExprKind::Try(ref subexpr) | ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)), diff --git a/src/closures.rs b/src/closures.rs index 88a6bebb68c..423c3a997f5 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -326,16 +326,16 @@ pub(crate) fn rewrite_last_closure( expr: &ast::Expr, shape: Shape, ) -> Option { - if let ast::ExprKind::Closure( - ref binder, - capture, - ref is_async, - movability, - ref fn_decl, - ref body, - _, - ) = expr.kind - { + if let ast::ExprKind::Closure(ref closure) = expr.kind { + let ast::Closure { + ref binder, + capture_clause, + ref asyncness, + movability, + ref fn_decl, + ref body, + fn_decl_span: _, + } = **closure; let body = match body.kind { ast::ExprKind::Block(ref block, _) if !is_unsafe_block(block) @@ -347,7 +347,15 @@ pub(crate) fn rewrite_last_closure( _ => body, }; let (prefix, extra_offset) = rewrite_closure_fn_decl( - binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape, + binder, + capture_clause, + asyncness, + movability, + fn_decl, + body, + expr.span, + context, + shape, )?; // If the closure goes multi line before its body, do not overflow the closure. if prefix.contains('\n') { diff --git a/src/expr.rs b/src/expr.rs index b4f1a178dbf..aba1c484bf1 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -116,7 +116,7 @@ pub(crate) fn format_expr( rewrite_struct_lit( context, path, - qself.as_ref(), + qself, fields, rest, &expr.attrs, @@ -169,7 +169,7 @@ pub(crate) fn format_expr( rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs) } ast::ExprKind::Path(ref qself, ref path) => { - rewrite_path(context, PathContext::Expr, qself.as_ref(), path, shape) + rewrite_path(context, PathContext::Expr, qself, path, shape) } ast::ExprKind::Assign(ref lhs, ref rhs, _) => { rewrite_assignment(context, lhs, rhs, None, shape) @@ -203,16 +203,16 @@ pub(crate) fn format_expr( Some("yield".to_string()) } } - ast::ExprKind::Closure( - ref binder, - capture, - ref is_async, - movability, - ref fn_decl, - ref body, - _, - ) => closures::rewrite_closure( - binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape, + ast::ExprKind::Closure(ref cl) => closures::rewrite_closure( + &cl.binder, + cl.capture_clause, + &cl.asyncness, + cl.movability, + &cl.fn_decl, + &cl.body, + expr.span, + context, + shape, ), ast::ExprKind::Try(..) | ast::ExprKind::Field(..) @@ -1537,7 +1537,7 @@ fn struct_lit_can_be_aligned(fields: &[ast::ExprField], has_base: bool) -> bool fn rewrite_struct_lit<'a>( context: &RewriteContext<'_>, path: &ast::Path, - qself: Option<&ast::QSelf>, + qself: &Option>, fields: &'a [ast::ExprField], struct_rest: &ast::StructRest, attrs: &[ast::Attribute], diff --git a/src/patterns.rs b/src/patterns.rs index e2fe92b28f2..3f335172590 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -227,11 +227,10 @@ impl Rewrite for Pat { } PatKind::Tuple(ref items) => rewrite_tuple_pat(items, None, self.span, context, shape), PatKind::Path(ref q_self, ref path) => { - rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape) + rewrite_path(context, PathContext::Expr, q_self, path, shape) } PatKind::TupleStruct(ref q_self, ref path, ref pat_vec) => { - let path_str = - rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)?; + let path_str = rewrite_path(context, PathContext::Expr, q_self, path, shape)?; rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape) } PatKind::Lit(ref expr) => expr.rewrite(context, shape), @@ -271,7 +270,7 @@ impl Rewrite for Pat { } fn rewrite_struct_pat( - qself: &Option, + qself: &Option>, path: &ast::Path, fields: &[ast::PatField], ellipsis: bool, @@ -281,7 +280,7 @@ fn rewrite_struct_pat( ) -> Option { // 2 = ` {` let path_shape = shape.sub_width(2)?; - let path_str = rewrite_path(context, PathContext::Expr, qself.as_ref(), path, path_shape)?; + let path_str = rewrite_path(context, PathContext::Expr, qself, path, path_shape)?; if fields.is_empty() && !ellipsis { return Some(format!("{} {{}}", path_str)); diff --git a/src/types.rs b/src/types.rs index 2627886db10..d5177a2057b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -38,11 +38,11 @@ pub(crate) enum PathContext { pub(crate) fn rewrite_path( context: &RewriteContext<'_>, path_context: PathContext, - qself: Option<&ast::QSelf>, + qself: &Option>, path: &ast::Path, shape: Shape, ) -> Option { - let skip_count = qself.map_or(0, |x| x.position); + let skip_count = qself.as_ref().map_or(0, |x| x.position); let mut result = if path.is_global() && qself.is_none() && path_context != PathContext::Import { "::".to_owned() @@ -655,7 +655,7 @@ impl Rewrite for ast::PolyTraitRef { impl Rewrite for ast::TraitRef { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { - rewrite_path(context, PathContext::Type, None, &self.path, shape) + rewrite_path(context, PathContext::Type, &None, &self.path, shape) } } @@ -800,7 +800,7 @@ impl Rewrite for ast::Ty { rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1) } ast::TyKind::Path(ref q_self, ref path) => { - rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape) + rewrite_path(context, PathContext::Type, q_self, path, shape) } ast::TyKind::Array(ref ty, ref repeats) => rewrite_pair( &**ty, diff --git a/src/utils.rs b/src/utils.rs index c47b3b314dd..136a2c7fce2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -479,9 +479,9 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::Binary(_, _, ref expr) | ast::ExprKind::Index(_, ref expr) | ast::ExprKind::Unary(_, ref expr) - | ast::ExprKind::Closure(_, _, _, _, _, ref expr, _) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Yield(Some(ref expr)) => is_block_expr(context, expr, repr), + ast::ExprKind::Closure(ref closure) => is_block_expr(context, &closure.body, repr), // This can only be a string lit ast::ExprKind::Lit(_) => { repr.contains('\n') && trimmed_last_line_width(repr) <= context.config.tab_spaces() From 1343ffd564fbaed96e800a125e3d2b43de09beea Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 18 Nov 2022 11:24:21 +1100 Subject: [PATCH 16/28] Split `MacArgs` in two. `MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values. --- src/expr.rs | 2 +- src/macros.rs | 6 +++--- src/parse/macros/asm.rs | 2 +- src/parse/macros/cfg_if.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index aba1c484bf1..d5611082f01 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1341,7 +1341,7 @@ pub(crate) fn can_be_overflowed_expr( } ast::ExprKind::MacCall(ref mac) => { match ( - rustc_ast::ast::MacDelimiter::from_token(mac.args.delim().unwrap()), + rustc_ast::ast::MacDelimiter::from_token(mac.args.delim.to_token()), context.config.overflow_delimited_expr(), ) { (Some(ast::MacDelimiter::Bracket), true) diff --git a/src/macros.rs b/src/macros.rs index 3a641fab5d6..df949388037 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -208,7 +208,7 @@ fn rewrite_macro_inner( original_style }; - let ts = mac.args.inner_tokens(); + let ts = mac.args.tokens.clone(); let has_comment = contains_comment(context.snippet(mac.span())); if ts.is_empty() && !has_comment { return match style { @@ -392,7 +392,7 @@ pub(crate) fn rewrite_macro_def( return snippet; } - let ts = def.body.inner_tokens(); + let ts = def.body.tokens.clone(); let mut parser = MacroParser::new(ts.into_trees()); let parsed_def = match parser.parse() { Some(def) => def, @@ -1087,7 +1087,7 @@ pub(crate) fn convert_try_mac( ) -> Option { let path = &pprust::path_to_string(&mac.path); if path == "try" || path == "r#try" { - let ts = mac.args.inner_tokens(); + let ts = mac.args.tokens.clone(); Some(ast::Expr { id: ast::NodeId::root(), // dummy value diff --git a/src/parse/macros/asm.rs b/src/parse/macros/asm.rs index cc9fb5072ce..01edfab3654 100644 --- a/src/parse/macros/asm.rs +++ b/src/parse/macros/asm.rs @@ -5,7 +5,7 @@ use crate::rewrite::RewriteContext; #[allow(dead_code)] pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option { - let ts = mac.args.inner_tokens(); + let ts = mac.args.tokens.clone(); let mut parser = super::build_parser(context, ts); parse_asm_args(&mut parser, context.parse_sess.inner(), mac.span(), false).ok() } diff --git a/src/parse/macros/cfg_if.rs b/src/parse/macros/cfg_if.rs index 09b3e32df31..ace1a76b3fe 100644 --- a/src/parse/macros/cfg_if.rs +++ b/src/parse/macros/cfg_if.rs @@ -23,7 +23,7 @@ fn parse_cfg_if_inner<'a>( sess: &'a ParseSess, mac: &'a ast::MacCall, ) -> Result, &'static str> { - let ts = mac.args.inner_tokens(); + let ts = mac.args.tokens.clone(); let mut parser = build_stream_parser(sess.inner(), ts); let mut items = vec![]; From 3d44530eb081d6ffb45124bb25feb2738f6f09ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 3 Nov 2022 14:22:35 -0700 Subject: [PATCH 17/28] Fix rustfmt --- src/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index d5611082f01..414e767690b 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -660,7 +660,7 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option { Some(ControlFlow::new_for(pat, cond, block, label, expr.span)) } - ast::ExprKind::Loop(ref block, label) => { + ast::ExprKind::Loop(ref block, label, _) => { Some(ControlFlow::new_loop(block, label, expr.span)) } ast::ExprKind::While(ref cond, ref block, label) => { From cdff11ce94a6d70873920a4347de41adc5763d03 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 23 Nov 2022 15:39:42 +1100 Subject: [PATCH 18/28] Rename `ast::Lit` as `ast::MetaItemLit`. --- src/attr.rs | 11 ++++++++--- src/modules/visitor.rs | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index 23f55db773e..8cba2a850e5 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -527,14 +527,19 @@ pub(crate) trait MetaVisitor<'ast> { fn visit_meta_word(&mut self, _meta_item: &'ast ast::MetaItem) {} - fn visit_meta_name_value(&mut self, _meta_item: &'ast ast::MetaItem, _lit: &'ast ast::Lit) {} + fn visit_meta_name_value( + &mut self, + _meta_item: &'ast ast::MetaItem, + _lit: &'ast ast::MetaItemLit, + ) { + } fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) { match nm { ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item), - ast::NestedMetaItem::Literal(ref lit) => self.visit_literal(lit), + ast::NestedMetaItem::Literal(ref lit) => self.visit_meta_item_lit(lit), } } - fn visit_literal(&mut self, _lit: &'ast ast::Lit) {} + fn visit_meta_item_lit(&mut self, _lit: &'ast ast::MetaItemLit) {} } diff --git a/src/modules/visitor.rs b/src/modules/visitor.rs index ea67977c17a..48431693332 100644 --- a/src/modules/visitor.rs +++ b/src/modules/visitor.rs @@ -84,15 +84,19 @@ impl PathVisitor { } impl<'ast> MetaVisitor<'ast> for PathVisitor { - fn visit_meta_name_value(&mut self, meta_item: &'ast ast::MetaItem, lit: &'ast ast::Lit) { + fn visit_meta_name_value( + &mut self, + meta_item: &'ast ast::MetaItem, + lit: &'ast ast::MetaItemLit, + ) { if meta_item.has_name(Symbol::intern("path")) && lit.kind.is_str() { - self.paths.push(lit_to_str(lit)); + self.paths.push(meta_item_lit_to_str(lit)); } } } #[cfg(not(windows))] -fn lit_to_str(lit: &ast::Lit) -> String { +fn meta_item_lit_to_str(lit: &ast::MetaItemLit) -> String { match lit.kind { ast::LitKind::Str(symbol, ..) => symbol.to_string(), _ => unreachable!(), @@ -100,7 +104,7 @@ fn lit_to_str(lit: &ast::Lit) -> String { } #[cfg(windows)] -fn lit_to_str(lit: &ast::Lit) -> String { +fn meta_item_lit_to_str(lit: &ast::MetaItemLit) -> String { match lit.kind { ast::LitKind::Str(symbol, ..) => symbol.as_str().replace("/", "\\"), _ => unreachable!(), From c7e4abd44469d20fad3033608d7ece501609ed34 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 24 Nov 2022 15:00:09 +1100 Subject: [PATCH 19/28] Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`. We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity. --- src/attr.rs | 6 ++---- src/overflow.rs | 4 ++-- src/utils.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index 8cba2a850e5..2ac703b957b 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -260,9 +260,7 @@ impl Rewrite for ast::NestedMetaItem { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self { ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape), - ast::NestedMetaItem::Literal(ref l) => { - rewrite_literal(context, l.token_lit, l.span, shape) - } + ast::NestedMetaItem::Lit(ref l) => rewrite_literal(context, l.token_lit, l.span, shape), } } } @@ -537,7 +535,7 @@ pub(crate) trait MetaVisitor<'ast> { fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) { match nm { ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item), - ast::NestedMetaItem::Literal(ref lit) => self.visit_meta_item_lit(lit), + ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit), } } diff --git a/src/overflow.rs b/src/overflow.rs index 6bf8cd0c70b..af0b95430a1 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -125,7 +125,7 @@ impl<'a> OverflowableItem<'a> { OverflowableItem::MacroArg(MacroArg::Keyword(..)) => true, OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr), OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item { - ast::NestedMetaItem::Literal(..) => true, + ast::NestedMetaItem::Lit(..) => true, ast::NestedMetaItem::MetaItem(ref meta_item) => { matches!(meta_item.kind, ast::MetaItemKind::Word) } @@ -169,7 +169,7 @@ impl<'a> OverflowableItem<'a> { }, OverflowableItem::NestedMetaItem(nested_meta_item) if len == 1 => { match nested_meta_item { - ast::NestedMetaItem::Literal(..) => false, + ast::NestedMetaItem::Lit(..) => false, ast::NestedMetaItem::MetaItem(..) => true, } } diff --git a/src/utils.rs b/src/utils.rs index 136a2c7fce2..3e884419f1a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -263,7 +263,7 @@ fn is_skip(meta_item: &MetaItem) -> bool { fn is_skip_nested(meta_item: &NestedMetaItem) -> bool { match meta_item { NestedMetaItem::MetaItem(ref mi) => is_skip(mi), - NestedMetaItem::Literal(_) => false, + NestedMetaItem::Lit(_) => false, } } From 749c816faec774e7e7cae8ebad01d7ca0464b541 Mon Sep 17 00:00:00 2001 From: Sarthak Singh Date: Wed, 9 Nov 2022 20:39:28 +0530 Subject: [PATCH 20/28] Keep track of the start of the argument block of a closure --- src/closures.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/closures.rs b/src/closures.rs index 423c3a997f5..244d4427c56 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -335,6 +335,7 @@ pub(crate) fn rewrite_last_closure( ref fn_decl, ref body, fn_decl_span: _, + fn_arg_span: _, } = **closure; let body = match body.kind { ast::ExprKind::Block(ref block, _) From 46f0b38eb5f4965bd3230ceeba4a3ed7d0e5f68e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 1 Dec 2022 18:51:20 +0300 Subject: [PATCH 21/28] rustc_ast_lowering: Stop lowering imports into multiple items Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items. --- src/imports.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imports.rs b/src/imports.rs index b6530c69243..d9dc8d004af 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -490,7 +490,7 @@ impl UseTree { ); result.path.push(UseSegment { kind, version }); } - UseTreeKind::Simple(ref rename, ..) => { + UseTreeKind::Simple(ref rename) => { // If the path has leading double colons and is composed of only 2 segments, then we // bypass the call to path_to_imported_ident which would get only the ident and // lose the path root, e.g., `that` in `::that`. From c91dd22870d40315c3e0e5b45077516286e918fd Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 29 Nov 2022 13:36:00 +1100 Subject: [PATCH 22/28] Remove `token::Lit` from `ast::MetaItemLit`. `token::Lit` contains a `kind` field that indicates what kind of literal it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has its own `kind` field. This means that `ast::MetaItemLit` encodes the literal kind in two different ways. This commit changes `ast::MetaItemLit` so it no longer wraps `token::Lit`. It now contains the `symbol` and `suffix` fields from `token::Lit`, but not the `kind` field, eliminating the redundancy. --- src/attr.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index 2ac703b957b..c503eeeb9b3 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -260,7 +260,9 @@ impl Rewrite for ast::NestedMetaItem { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self { ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape), - ast::NestedMetaItem::Lit(ref l) => rewrite_literal(context, l.token_lit, l.span, shape), + ast::NestedMetaItem::Lit(ref l) => { + rewrite_literal(context, l.as_token_lit(), l.span, shape) + } } } } @@ -308,18 +310,18 @@ impl Rewrite for ast::MetaItem { }), )? } - ast::MetaItemKind::NameValue(ref literal) => { + ast::MetaItemKind::NameValue(ref lit) => { let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?; // 3 = ` = ` let lit_shape = shape.shrink_left(path.len() + 3)?; - // `rewrite_literal` returns `None` when `literal` exceeds max + // `rewrite_literal` returns `None` when `lit` exceeds max // width. Since a literal is basically unformattable unless it // is a string literal (and only if `format_strings` is set), // we might be better off ignoring the fact that the attribute // is longer than the max width and continue on formatting. // See #2479 for example. - let value = rewrite_literal(context, literal.token_lit, literal.span, lit_shape) - .unwrap_or_else(|| context.snippet(literal.span).to_owned()); + let value = rewrite_literal(context, lit.as_token_lit(), lit.span, lit_shape) + .unwrap_or_else(|| context.snippet(lit.span).to_owned()); format!("{} = {}", path, value) } }) From ac8eaa1ba7a5e6887b45bbd84d9a583fac6e39c9 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 28 Dec 2022 18:06:11 +0100 Subject: [PATCH 23/28] Rename `Rptr` to `Ref` in AST and HIR The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well. --- src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types.rs b/src/types.rs index d5177a2057b..c1991e8d2c8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -688,7 +688,7 @@ impl Rewrite for ast::Ty { rewrite_unary_prefix(context, prefix, &*mt.ty, shape) } - ast::TyKind::Rptr(ref lifetime, ref mt) => { + ast::TyKind::Ref(ref lifetime, ref mt) => { let mut_str = format_mutability(mt.mutbl); let mut_len = mut_str.len(); let mut result = String::with_capacity(128); @@ -1059,7 +1059,7 @@ pub(crate) fn can_be_overflowed_type( ) -> bool { match ty.kind { ast::TyKind::Tup(..) => context.use_block_indent() && len == 1, - ast::TyKind::Rptr(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => { + ast::TyKind::Ref(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => { can_be_overflowed_type(context, &*mutty.ty, len) } _ => false, From d7fa2ee3e6eae1a7fe4526249ce61caaa3d448d4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 12 Dec 2022 19:37:28 +0000 Subject: [PATCH 24/28] Add missing extern crate rustc_driver --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1d1ef525f23..0c27bcacfb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,11 @@ extern crate rustc_parse; extern crate rustc_session; extern crate rustc_span; +// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta +// files. +#[allow(unused_extern_crates)] +extern crate rustc_driver; + use std::cell::RefCell; use std::collections::HashMap; use std::fmt; From 664c60a18eb594ef22a31b7fa3a0dfb367cdd442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 5 Jan 2023 21:29:36 +0000 Subject: [PATCH 25/28] Detect closures assigned to binding in block Fix #58497. --- tests/target/issue_4110.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/target/issue_4110.rs b/tests/target/issue_4110.rs index 4a58c3946e1..d3734e90b7f 100644 --- a/tests/target/issue_4110.rs +++ b/tests/target/issue_4110.rs @@ -20,6 +20,7 @@ fn bindings() { category, span, &format!("`{}`", name), + "function", ), ( ref name, From 8c8aa3873f1c7177d532a6093da5e9836611ed4c Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:45:44 +0100 Subject: [PATCH 26/28] Change `src/test` to `tests` in source files, fix tidy and tests --- tests/source/issue-2445.rs | 4 ++-- tests/target/issue-2445.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/source/issue-2445.rs b/tests/source/issue-2445.rs index 84ce6e647b8..deef429dbee 100644 --- a/tests/source/issue-2445.rs +++ b/tests/source/issue-2445.rs @@ -1,6 +1,6 @@ test!(RunPassPretty { // comment - path: "src/test/run-pass/pretty", + path: "tests/run-pass/pretty", mode: "pretty", suite: "run-pass", default: false, @@ -9,7 +9,7 @@ test!(RunPassPretty { test!(RunPassPretty { // comment - path: "src/test/run-pass/pretty", + path: "tests/run-pass/pretty", mode: "pretty", suite: "run-pass", default: false, diff --git a/tests/target/issue-2445.rs b/tests/target/issue-2445.rs index 1bc7752fd16..463c5d49576 100644 --- a/tests/target/issue-2445.rs +++ b/tests/target/issue-2445.rs @@ -1,6 +1,6 @@ test!(RunPassPretty { // comment - path: "src/test/run-pass/pretty", + path: "tests/run-pass/pretty", mode: "pretty", suite: "run-pass", default: false, @@ -9,7 +9,7 @@ test!(RunPassPretty { test!(RunPassPretty { // comment - path: "src/test/run-pass/pretty", + path: "tests/run-pass/pretty", mode: "pretty", suite: "run-pass", default: false, From 19c2286d5c0fe45765cb6bd182b32722173b0942 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 20 Dec 2022 16:15:55 +0000 Subject: [PATCH 27/28] parse const closures --- src/closures.rs | 19 ++++++++++++++++--- src/expr.rs | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/closures.rs b/src/closures.rs index 244d4427c56..8fd0fcf8f5c 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -26,6 +26,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt}; pub(crate) fn rewrite_closure( binder: &ast::ClosureBinder, + constness: ast::Const, capture: ast::CaptureBy, is_async: &ast::Async, movability: ast::Movability, @@ -38,7 +39,7 @@ pub(crate) fn rewrite_closure( debug!("rewrite_closure {:?}", body); let (prefix, extra_offset) = rewrite_closure_fn_decl( - binder, capture, is_async, movability, fn_decl, body, span, context, shape, + binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape, )?; // 1 = space between `|...|` and body. let body_shape = shape.offset_left(extra_offset)?; @@ -230,6 +231,7 @@ fn rewrite_closure_block( // Return type is (prefix, extra_offset) fn rewrite_closure_fn_decl( binder: &ast::ClosureBinder, + constness: ast::Const, capture: ast::CaptureBy, asyncness: &ast::Async, movability: ast::Movability, @@ -250,6 +252,12 @@ fn rewrite_closure_fn_decl( ast::ClosureBinder::NotPresent => "".to_owned(), }; + let const_ = if matches!(constness, ast::Const::Yes(_)) { + "const " + } else { + "" + }; + let immovable = if movability == ast::Movability::Static { "static " } else { @@ -264,7 +272,7 @@ fn rewrite_closure_fn_decl( // 4 = "|| {".len(), which is overconservative when the closure consists of // a single expression. let nested_shape = shape - .shrink_left(binder.len() + immovable.len() + is_async.len() + mover.len())? + .shrink_left(binder.len() + const_.len() + immovable.len() + is_async.len() + mover.len())? .sub_width(4)?; // 1 = | @@ -302,7 +310,10 @@ fn rewrite_closure_fn_decl( .tactic(tactic) .preserve_newline(true); let list_str = write_list(&item_vec, &fmt)?; - let mut prefix = format!("{}{}{}{}|{}|", binder, immovable, is_async, mover, list_str); + let mut prefix = format!( + "{}{}{}{}{}|{}|", + binder, const_, immovable, is_async, mover, list_str + ); if !ret_str.is_empty() { if prefix.contains('\n') { @@ -329,6 +340,7 @@ pub(crate) fn rewrite_last_closure( if let ast::ExprKind::Closure(ref closure) = expr.kind { let ast::Closure { ref binder, + constness, capture_clause, ref asyncness, movability, @@ -349,6 +361,7 @@ pub(crate) fn rewrite_last_closure( }; let (prefix, extra_offset) = rewrite_closure_fn_decl( binder, + constness, capture_clause, asyncness, movability, diff --git a/src/expr.rs b/src/expr.rs index 414e767690b..868ff045ab7 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -205,6 +205,7 @@ pub(crate) fn format_expr( } ast::ExprKind::Closure(ref cl) => closures::rewrite_closure( &cl.binder, + cl.constness, cl.capture_clause, &cl.asyncness, cl.movability, From 18dd0757dbef84611fc0f1f522b15913248b8541 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Mon, 23 Jan 2023 21:44:03 -0600 Subject: [PATCH 28/28] chore: bump toolchain --- rust-toolchain | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index f8ed76d2e6f..22283b3d620 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-08-06" -components = ["rustc-dev"] +channel = "nightly-2023-01-24" +components = ["llvm-tools", "rustc-dev"]