From 3572c542c29facef5073ba801213fb160c376b4a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 24 Jan 2022 11:23:14 +0000 Subject: [PATCH 01/12] rustc_errors: only box the `diagnostic` field in `DiagnosticBuilder`. --- src/parse/session.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse/session.rs b/src/parse/session.rs index 624fed0d2de2..7fc3778376cd 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -315,7 +315,7 @@ mod tests { code: None, message: vec![], children: vec![], - suggestions: vec![], + suggestions: Ok(vec![]), span: span.unwrap_or_else(MultiSpan::new), sort_span: DUMMY_SP, is_lint: false, From 7592663e85fe82de5f346a77a22772230b1378a1 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 23 Jan 2022 23:11:37 +0000 Subject: [PATCH 02/12] rustc_errors: add `downgrade_to_delayed_bug` to `Diagnostic` itself. --- src/parse/session.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/parse/session.rs b/src/parse/session.rs index 7fc3778376cd..d26bb8c20255 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -60,7 +60,7 @@ impl Emitter for SilentOnIgnoredFilesEmitter { None } fn emit_diagnostic(&mut self, db: &Diagnostic) { - if db.level == DiagnosticLevel::Fatal { + if db.level() == DiagnosticLevel::Fatal { return self.handle_non_ignoreable_error(db); } if let Some(primary_span) = &db.span.primary_span() { @@ -292,7 +292,7 @@ mod tests { use super::*; use crate::config::IgnoreList; use crate::utils::mk_sp; - use rustc_span::{FileName as SourceMapFileName, MultiSpan, RealFileName, DUMMY_SP}; + use rustc_span::{FileName as SourceMapFileName, MultiSpan, RealFileName}; use std::path::PathBuf; use std::sync::atomic::AtomicU32; @@ -310,16 +310,12 @@ mod tests { } fn build_diagnostic(level: DiagnosticLevel, span: Option) -> Diagnostic { - Diagnostic { - level, - code: None, - message: vec![], - children: vec![], - suggestions: Ok(vec![]), - span: span.unwrap_or_else(MultiSpan::new), - sort_span: DUMMY_SP, - is_lint: false, + let mut diag = Diagnostic::new(level, ""); + diag.message.clear(); + if let Some(span) = span { + diag.span = span; } + diag } fn build_emitter( From 57239460813806d74f6e5404876a6f3fc8f9262b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 26 Jan 2022 03:39:14 +0000 Subject: [PATCH 03/12] rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`. --- src/modules.rs | 2 +- src/parse/macros/cfg_if.rs | 2 +- src/parse/macros/lazy_static.rs | 2 +- src/parse/macros/mod.rs | 2 +- src/parse/parser.rs | 2 +- src/parse/session.rs | 11 ----------- 6 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/modules.rs b/src/modules.rs index 9c964b274e08..d4bddd957858 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -439,7 +439,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { } } Err(mod_err) if !mods_outside_ast.is_empty() => { - if let ModError::ParserError(mut e) = mod_err { + if let ModError::ParserError(e) = mod_err { e.cancel(); } Ok(Some(SubModKind::MultiExternal(mods_outside_ast))) diff --git a/src/parse/macros/cfg_if.rs b/src/parse/macros/cfg_if.rs index e10fbe64bcdb..306b6bb745ee 100644 --- a/src/parse/macros/cfg_if.rs +++ b/src/parse/macros/cfg_if.rs @@ -57,7 +57,7 @@ fn parse_cfg_if_inner<'a>( let item = match parser.parse_item(ForceCollect::No) { Ok(Some(item_ptr)) => item_ptr.into_inner(), Ok(None) => continue, - Err(mut err) => { + Err(err) => { err.cancel(); parser.sess.span_diagnostic.reset_err_count(); return Err( diff --git a/src/parse/macros/lazy_static.rs b/src/parse/macros/lazy_static.rs index 9c8651aa3faf..4c541de04be0 100644 --- a/src/parse/macros/lazy_static.rs +++ b/src/parse/macros/lazy_static.rs @@ -23,7 +23,7 @@ pub(crate) fn parse_lazy_static( val } } - Err(mut err) => { + Err(err) => { err.cancel(); parser.sess.span_diagnostic.reset_err_count(); return None; diff --git a/src/parse/macros/mod.rs b/src/parse/macros/mod.rs index 2e9ce1d35f40..fd738908170f 100644 --- a/src/parse/macros/mod.rs +++ b/src/parse/macros/mod.rs @@ -36,7 +36,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { return Some(MacroArg::$macro_arg($f(x)?)); } } - Err(mut e) => { + Err(e) => { e.cancel(); parser.sess.span_diagnostic.reset_err_count(); } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 657217633f4a..f0944a88d2f2 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -115,7 +115,7 @@ impl<'a> Parser<'a> { match parser.parse_mod(&TokenKind::Eof) { Ok(result) => Some(result), Err(mut e) => { - sess.emit_or_cancel_diagnostic(&mut e); + e.emit(); if sess.can_reset_errors() { sess.reset_errors(); } diff --git a/src/parse/session.rs b/src/parse/session.rs index d26bb8c20255..40a6d708d8cc 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -230,17 +230,6 @@ impl ParseSess { } } - pub(crate) fn emit_or_cancel_diagnostic(&self, diagnostic: &mut Diagnostic) { - self.parse_sess.span_diagnostic.emit_diagnostic(diagnostic); - // The Handler will check whether the diagnostic should be emitted - // based on the user's rustfmt configuration and the originating file - // that caused the parser error. If the Handler determined it should skip - // emission then we need to ensure the diagnostic is cancelled. - if !diagnostic.cancelled() { - diagnostic.cancel(); - } - } - pub(super) fn can_reset_errors(&self) -> bool { self.can_reset_errors.load(Ordering::Acquire) } From de1ac375f079a9bf7f2aa81c47fa46ecdb32d074 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 23 Feb 2022 08:11:17 -0500 Subject: [PATCH 04/12] Enable rustc_pass_by_value for Span --- src/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index e1865c8afc2f..4f333cd27cef 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1533,7 +1533,7 @@ fn rewrite_struct_lit<'a>( enum StructLitField<'a> { Regular(&'a ast::ExprField), Base(&'a ast::Expr), - Rest(&'a Span), + Rest(Span), } // 2 = " {".len() @@ -1568,7 +1568,7 @@ fn rewrite_struct_lit<'a>( let field_iter = fields.iter().map(StructLitField::Regular).chain( match struct_rest { ast::StructRest::Base(expr) => Some(StructLitField::Base(&**expr)), - ast::StructRest::Rest(span) => Some(StructLitField::Rest(span)), + ast::StructRest::Rest(span) => Some(StructLitField::Rest(*span)), ast::StructRest::None => None, } .into_iter(), From 4edb7578261ae0cc547c4346f8c0a82e124ac524 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 20 Jan 2022 11:06:45 -0500 Subject: [PATCH 05/12] refactor: prepare to associate multiple spans with a module. --- src/parse/parser.rs | 2 +- src/visitor.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index f0944a88d2f2..3b4e762b6dd1 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -113,7 +113,7 @@ impl<'a> Parser<'a> { let result = catch_unwind(AssertUnwindSafe(|| { let mut parser = new_parser_from_file(sess.inner(), path, Some(span)); match parser.parse_mod(&TokenKind::Eof) { - Ok(result) => Some(result), + Ok((a, i, ast::ModSpans { inner_span })) => Some((a, i, inner_span)), Err(mut e) => { e.emit(); if sess.can_reset_errors() { diff --git a/src/visitor.rs b/src/visitor.rs index 0177689958aa..57a58c604846 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -915,7 +915,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let ident_str = rewrite_ident(&self.get_context(), ident).to_owned(); self.push_str(&ident_str); - if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, inner_span) = mod_kind { + if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ast::ModSpans{ inner_span }) = mod_kind { match self.config.brace_style() { BraceStyle::AlwaysNextLine => { let indent_str = self.block_indent.to_string_with_newline(self.config); From 74876ef4e9b29184787f6d8f3ba447e78def3a47 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 3 Mar 2022 18:45:25 -0500 Subject: [PATCH 06/12] Associate multiple with a crate too. --- src/modules.rs | 4 ++-- src/visitor.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules.rs b/src/modules.rs index d4bddd957858..64d96a5c6a6e 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -124,7 +124,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { mut self, krate: &'ast ast::Crate, ) -> Result, ModuleResolutionError> { - let root_filename = self.parse_sess.span_to_filename(krate.span); + let root_filename = self.parse_sess.span_to_filename(krate.spans.inner_span); self.directory.path = match root_filename { FileName::Real(ref p) => p.parent().unwrap_or(Path::new("")).to_path_buf(), _ => PathBuf::new(), @@ -135,7 +135,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { self.visit_mod_from_ast(&krate.items)?; } - let snippet_provider = self.parse_sess.snippet_provider(krate.span); + let snippet_provider = self.parse_sess.snippet_provider(krate.spans.inner_span); self.file_map.insert( root_filename, diff --git a/src/visitor.rs b/src/visitor.rs index 57a58c604846..c44b2fc6ae35 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -915,7 +915,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let ident_str = rewrite_ident(&self.get_context(), ident).to_owned(); self.push_str(&ident_str); - if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ast::ModSpans{ inner_span }) = mod_kind { + if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind { + let ast::ModSpans { inner_span } = *spans; match self.config.brace_style() { BraceStyle::AlwaysNextLine => { let indent_str = self.block_indent.to_string_with_newline(self.config); From 651f46376aa6bb259c58cbb3debad6e0edce31bf Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 20 Jan 2022 14:07:54 -0500 Subject: [PATCH 07/12] Adjusted diagnostic output so that if there is no `use` in a item sequence, then we just suggest the first legal position where you could inject a use. To do this, I added `inject_use_span` field to `ModSpans`, and populate it in parser (it is the span of the first token found after inner attributes, if any). Then I rewrote the use-suggestion code to utilize it, and threw out some stuff that is now unnecessary with this in place. (I think the result is easier to understand.) Then I added a test of issue 87613. --- src/parse/parser.rs | 2 +- src/visitor.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 3b4e762b6dd1..6983249c15d4 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -113,7 +113,7 @@ impl<'a> Parser<'a> { let result = catch_unwind(AssertUnwindSafe(|| { let mut parser = new_parser_from_file(sess.inner(), path, Some(span)); match parser.parse_mod(&TokenKind::Eof) { - Ok((a, i, ast::ModSpans { inner_span })) => Some((a, i, inner_span)), + Ok((a, i, ast::ModSpans { inner_span, inject_use_span: _ })) => Some((a, i, inner_span)), Err(mut e) => { e.emit(); if sess.can_reset_errors() { diff --git a/src/visitor.rs b/src/visitor.rs index c44b2fc6ae35..dec977e98caf 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -916,7 +916,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.push_str(&ident_str); if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind { - let ast::ModSpans { inner_span } = *spans; + let ast::ModSpans{ inner_span, inject_use_span: _ } = *spans; match self.config.brace_style() { BraceStyle::AlwaysNextLine => { let indent_str = self.block_indent.to_string_with_newline(self.config); From 0be893166b2ae94db8a10ea16c3d9465e378c27a Mon Sep 17 00:00:00 2001 From: pierwill Date: Fri, 4 Mar 2022 11:54:28 -0600 Subject: [PATCH 08/12] Update `itertools` Update to 0.10.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8d9c4a7fb20c..764714638a97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ rustfmt-format-diff = [] generic-simd = ["bytecount/generic-simd"] [dependencies] -itertools = "0.9" +itertools = "0.10.1" toml = "0.5" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" From ce301d92f12658edf6fe410d39de445270d1420e Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Mar 2022 17:05:30 -0500 Subject: [PATCH 09/12] Placate tidy in submodule. --- src/parse/parser.rs | 8 +++++++- src/visitor.rs | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 6983249c15d4..ec051d937101 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -113,7 +113,13 @@ impl<'a> Parser<'a> { let result = catch_unwind(AssertUnwindSafe(|| { let mut parser = new_parser_from_file(sess.inner(), path, Some(span)); match parser.parse_mod(&TokenKind::Eof) { - Ok((a, i, ast::ModSpans { inner_span, inject_use_span: _ })) => Some((a, i, inner_span)), + Ok((a, + i, + ast::ModSpans { + inner_span, + inject_use_span: _ + } + )) => Some((a, i, inner_span)), Err(mut e) => { e.emit(); if sess.can_reset_errors() { diff --git a/src/visitor.rs b/src/visitor.rs index dec977e98caf..dcf096294f14 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -916,7 +916,10 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.push_str(&ident_str); if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind { - let ast::ModSpans{ inner_span, inject_use_span: _ } = *spans; + let ast::ModSpans{ + inner_span, + inject_use_span: _ + } = *spans; match self.config.brace_style() { BraceStyle::AlwaysNextLine => { let indent_str = self.block_indent.to_string_with_newline(self.config); From 1212c9477c26335487ff1094a3d7d454c16365b5 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Tue, 19 Oct 2021 18:45:48 -0400 Subject: [PATCH 10/12] Change syntax for TyAlias where clauses --- src/items.rs | 108 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 34 deletions(-) diff --git a/src/items.rs b/src/items.rs index babc56f86edc..8498cb6addaa 100644 --- a/src/items.rs +++ b/src/items.rs @@ -694,7 +694,8 @@ pub(crate) fn format_impl( let where_span_end = context.snippet_provider.opt_span_before(missing_span, "{"); let where_clause_str = rewrite_where_clause( context, - &generics.where_clause, + &generics.where_clause.predicates, + generics.where_clause.span, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), false, @@ -1059,7 +1060,8 @@ pub(crate) fn format_trait( let option = WhereClauseOption::snuggled(&generics_str); let where_clause_str = rewrite_where_clause( context, - &generics.where_clause, + &generics.where_clause.predicates, + generics.where_clause.span, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), where_on_new_line, @@ -1178,7 +1180,8 @@ impl<'a> Rewrite for TraitAliasBounds<'a> { let where_str = rewrite_where_clause( context, - &self.generics.where_clause, + &self.generics.where_clause.predicates, + self.generics.where_clause.span, context.config.brace_style(), shape, false, @@ -1437,7 +1440,8 @@ fn format_tuple_struct( let option = WhereClauseOption::new(true, WhereClauseSpace::Newline); rewrite_where_clause( context, - &generics.where_clause, + &generics.where_clause.predicates, + generics.where_clause.span, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), false, @@ -1503,6 +1507,8 @@ struct TyAliasRewriteInfo<'c, 'g>( &'c RewriteContext<'c>, Indent, &'g ast::Generics, + (ast::TyAliasWhereClause, ast::TyAliasWhereClause), + usize, symbol::Ident, Span, ); @@ -1521,6 +1527,8 @@ pub(crate) fn rewrite_type_alias<'a, 'b>( ref generics, ref bounds, ref ty, + where_clauses, + where_predicates_split, } = *ty_alias_kind; let ty_opt = ty.as_ref(); let (ident, vis) = match visitor_kind { @@ -1528,7 +1536,15 @@ pub(crate) fn rewrite_type_alias<'a, 'b>( AssocTraitItem(i) | AssocImplItem(i) => (i.ident, &i.vis), ForeignItem(i) => (i.ident, &i.vis), }; - let rw_info = &TyAliasRewriteInfo(context, indent, generics, ident, span); + let rw_info = &TyAliasRewriteInfo( + context, + indent, + generics, + where_clauses, + where_predicates_split, + ident, + span, + ); let op_ty = opaque_ty(ty); // Type Aliases are formatted slightly differently depending on the context // in which they appear, whether they are opaque, and whether they are associated. @@ -1564,7 +1580,22 @@ fn rewrite_ty( vis: &ast::Visibility, ) -> Option { let mut result = String::with_capacity(128); - let TyAliasRewriteInfo(context, indent, generics, ident, span) = *rw_info; + let TyAliasRewriteInfo( + context, + indent, + generics, + where_clauses, + where_predicates_split, + ident, + span, + ) = *rw_info; + let (before_where_predicates, after_where_predicates) = generics + .where_clause + .predicates + .split_at(where_predicates_split); + if !after_where_predicates.is_empty() { + return None; + } result.push_str(&format!("{}type ", format_visibility(context, vis))); let ident_str = rewrite_ident(context, ident); @@ -1595,7 +1626,8 @@ fn rewrite_ty( } let where_clause_str = rewrite_where_clause( context, - &generics.where_clause, + before_where_predicates, + where_clauses.0.1, context.config.brace_style(), Shape::legacy(where_budget, indent), false, @@ -1609,7 +1641,7 @@ fn rewrite_ty( if let Some(ty) = rhs { // If there's a where clause, add a newline before the assignment. Otherwise just add a // space. - let has_where = !generics.where_clause.predicates.is_empty(); + let has_where = !before_where_predicates.is_empty(); if has_where { result.push_str(&indent.to_string_with_newline(context.config)); } else { @@ -1619,7 +1651,7 @@ fn rewrite_ty( let comment_span = context .snippet_provider .opt_span_before(span, "=") - .map(|op_lo| mk_sp(generics.where_clause.span.hi(), op_lo)); + .map(|op_lo| mk_sp(where_clauses.0.1.hi(), op_lo)); let lhs = match comment_span { Some(comment_span) @@ -2176,7 +2208,7 @@ fn rewrite_fn_base( let generics_str = rewrite_generics( context, rewrite_ident(context, ident), - fn_sig.generics, + &fn_sig.generics, shape, )?; result.push_str(&generics_str); @@ -2416,7 +2448,8 @@ fn rewrite_fn_base( } let where_clause_str = rewrite_where_clause( context, - where_clause, + &where_clause.predicates, + where_clause.span, context.config.brace_style(), Shape::indented(indent, context.config), true, @@ -2692,7 +2725,8 @@ fn generics_shape_from_config(config: &Config, shape: Shape, offset: usize) -> O fn rewrite_where_clause_rfc_style( context: &RewriteContext<'_>, - where_clause: &ast::WhereClause, + predicates: &[ast::WherePredicate], + where_span: Span, shape: Shape, terminator: &str, span_end: Option, @@ -2701,7 +2735,8 @@ fn rewrite_where_clause_rfc_style( ) -> Option { let (where_keyword, allow_single_line) = rewrite_where_keyword( context, - where_clause, + predicates, + where_span, shape, span_end_before_where, where_clause_option, @@ -2714,12 +2749,12 @@ fn rewrite_where_clause_rfc_style( .block_left(context.config.tab_spaces())? .sub_width(1)?; let force_single_line = context.config.where_single_line() - && where_clause.predicates.len() == 1 + && predicates.len() == 1 && !where_clause_option.veto_single_line; let preds_str = rewrite_bounds_on_where_clause( context, - where_clause, + predicates, clause_shape, terminator, span_end, @@ -2743,7 +2778,8 @@ fn rewrite_where_clause_rfc_style( /// Rewrite `where` and comment around it. fn rewrite_where_keyword( context: &RewriteContext<'_>, - where_clause: &ast::WhereClause, + predicates: &[ast::WherePredicate], + where_span: Span, shape: Shape, span_end_before_where: BytePos, where_clause_option: WhereClauseOption, @@ -2763,7 +2799,7 @@ fn rewrite_where_keyword( }; let (span_before, span_after) = - missing_span_before_after_where(span_end_before_where, where_clause); + missing_span_before_after_where(span_end_before_where, predicates, where_span); let (comment_before, comment_after) = rewrite_comments_before_after_where(context, span_before, span_after, shape)?; @@ -2789,22 +2825,22 @@ fn rewrite_where_keyword( /// Rewrite bounds on a where clause. fn rewrite_bounds_on_where_clause( context: &RewriteContext<'_>, - where_clause: &ast::WhereClause, + predicates: &[ast::WherePredicate], shape: Shape, terminator: &str, span_end: Option, where_clause_option: WhereClauseOption, force_single_line: bool, ) -> Option { - let span_start = where_clause.predicates[0].span().lo(); + let span_start = predicates[0].span().lo(); // If we don't have the start of the next span, then use the end of the // predicates, but that means we miss comments. - let len = where_clause.predicates.len(); - let end_of_preds = where_clause.predicates[len - 1].span().hi(); + let len = predicates.len(); + let end_of_preds = predicates[len - 1].span().hi(); let span_end = span_end.unwrap_or(end_of_preds); let items = itemize_list( context.snippet_provider, - where_clause.predicates.iter(), + predicates.iter(), terminator, ",", |pred| pred.span().lo(), @@ -2837,7 +2873,8 @@ fn rewrite_bounds_on_where_clause( fn rewrite_where_clause( context: &RewriteContext<'_>, - where_clause: &ast::WhereClause, + predicates: &[ast::WherePredicate], + where_span: Span, brace_style: BraceStyle, shape: Shape, on_new_line: bool, @@ -2846,14 +2883,15 @@ fn rewrite_where_clause( span_end_before_where: BytePos, where_clause_option: WhereClauseOption, ) -> Option { - if where_clause.predicates.is_empty() { + if predicates.is_empty() { return Some(String::new()); } if context.config.indent_style() == IndentStyle::Block { return rewrite_where_clause_rfc_style( context, - where_clause, + predicates, + where_span, shape, terminator, span_end, @@ -2873,15 +2911,15 @@ fn rewrite_where_clause( // be out by a char or two. let budget = context.config.max_width() - offset.width(); - let span_start = where_clause.predicates[0].span().lo(); + let span_start = predicates[0].span().lo(); // If we don't have the start of the next span, then use the end of the // predicates, but that means we miss comments. - let len = where_clause.predicates.len(); - let end_of_preds = where_clause.predicates[len - 1].span().hi(); + let len = predicates.len(); + let end_of_preds = predicates[len - 1].span().hi(); let span_end = span_end.unwrap_or(end_of_preds); let items = itemize_list( context.snippet_provider, - where_clause.predicates.iter(), + predicates.iter(), terminator, ",", |pred| pred.span().lo(), @@ -2936,12 +2974,13 @@ fn rewrite_where_clause( fn missing_span_before_after_where( before_item_span_end: BytePos, - where_clause: &ast::WhereClause, + predicates: &[ast::WherePredicate], + where_span: Span, ) -> (Span, Span) { - let missing_span_before = mk_sp(before_item_span_end, where_clause.span.lo()); + let missing_span_before = mk_sp(before_item_span_end, where_span.lo()); // 5 = `where` - let pos_after_where = where_clause.span.lo() + BytePos(5); - let missing_span_after = mk_sp(pos_after_where, where_clause.predicates[0].span().lo()); + let pos_after_where = where_span.lo() + BytePos(5); + let missing_span_after = mk_sp(pos_after_where, predicates[0].span().lo()); (missing_span_before, missing_span_after) } @@ -3030,7 +3069,8 @@ fn format_generics( } let where_clause_str = rewrite_where_clause( context, - &generics.where_clause, + &generics.where_clause.predicates, + generics.where_clause.span, brace_style, Shape::legacy(budget, offset.block_only()), true, From 003eaf8fe270cb8f6915ed03ad23f4af0212d607 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 7 Mar 2022 16:37:35 -0500 Subject: [PATCH 11/12] placate rustfmt in rustfmt. --- src/parse/parser.rs | 8 +------- src/visitor.rs | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index ec051d937101..268c72649a65 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -113,13 +113,7 @@ impl<'a> Parser<'a> { let result = catch_unwind(AssertUnwindSafe(|| { let mut parser = new_parser_from_file(sess.inner(), path, Some(span)); match parser.parse_mod(&TokenKind::Eof) { - Ok((a, - i, - ast::ModSpans { - inner_span, - inject_use_span: _ - } - )) => Some((a, i, inner_span)), + Ok((a, i, spans)) => Some((a, i, spans.inner_span)), Err(mut e) => { e.emit(); if sess.can_reset_errors() { diff --git a/src/visitor.rs b/src/visitor.rs index dcf096294f14..3ebfa551d1cb 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -916,9 +916,9 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.push_str(&ident_str); if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind { - let ast::ModSpans{ + let ast::ModSpans { inner_span, - inject_use_span: _ + inject_use_span: _, } = *spans; match self.config.brace_style() { BraceStyle::AlwaysNextLine => { From 432b8dea64b84cec3efc3205bdc9e6687d59812d Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Wed, 16 Mar 2022 22:26:15 -0500 Subject: [PATCH 12/12] chore: bump toolchain --- Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ef83ddd1ae6..b932e15ef746 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -275,9 +275,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.9.0" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" dependencies = [ "either", ] diff --git a/rust-toolchain b/rust-toolchain index d8bf02aec85e..0d407f11994b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-01-23" +channel = "nightly-2022-03-17" components = ["rustc-dev"]