From cf312ae1f26e815dc1a898d634b001b8f315448e Mon Sep 17 00:00:00 2001 From: Steven Tang Date: Wed, 7 Dec 2022 21:45:49 +1100 Subject: [PATCH 1/8] Add tests for #41731 Closes #41731 --- .../issue-41731-infinite-macro-print.rs | 15 ++++++++ .../issue-41731-infinite-macro-print.stderr | 38 +++++++++++++++++++ .../issue-41731-infinite-macro-println.rs | 15 ++++++++ .../issue-41731-infinite-macro-println.stderr | 38 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 src/test/ui/infinite/issue-41731-infinite-macro-print.rs create mode 100644 src/test/ui/infinite/issue-41731-infinite-macro-print.stderr create mode 100644 src/test/ui/infinite/issue-41731-infinite-macro-println.rs create mode 100644 src/test/ui/infinite/issue-41731-infinite-macro-println.stderr diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-print.rs b/src/test/ui/infinite/issue-41731-infinite-macro-print.rs new file mode 100644 index 0000000000000..d52e6e7e9eb82 --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-print.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z trace-macros + +#![recursion_limit = "5"] + +fn main() { + macro_rules! stack { + ($overflow:expr) => { + print!(stack!($overflow)); + //~^ ERROR recursion limit reached while expanding + //~| ERROR format argument must be a string literal + }; + } + + stack!("overflow"); +} diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-print.stderr b/src/test/ui/infinite/issue-41731-infinite-macro-print.stderr new file mode 100644 index 0000000000000..e30b2039d69c9 --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-print.stderr @@ -0,0 +1,38 @@ +error: recursion limit reached while expanding `$crate::format_args!` + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_print`) + = note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: trace_macro + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: expanding `stack! { "overflow" }` + = note: to `print! (stack! ("overflow")) ;` + = note: expanding `print! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }` + = note: expanding `stack! { "overflow" }` + = note: to `print! (stack! ("overflow")) ;` + = note: expanding `print! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }` + +error: format argument must be a string literal + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you might be missing a string literal to format with + | +LL | print!("{}", stack!($overflow)); + | +++++ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-println.rs b/src/test/ui/infinite/issue-41731-infinite-macro-println.rs new file mode 100644 index 0000000000000..3c2b7ee023b5c --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-println.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z trace-macros + +#![recursion_limit = "5"] + +fn main() { + macro_rules! stack { + ($overflow:expr) => { + println!(stack!($overflow)); + //~^ ERROR recursion limit reached while expanding + //~| ERROR format argument must be a string literal + }; + } + + stack!("overflow"); +} diff --git a/src/test/ui/infinite/issue-41731-infinite-macro-println.stderr b/src/test/ui/infinite/issue-41731-infinite-macro-println.stderr new file mode 100644 index 0000000000000..66b466dafa0da --- /dev/null +++ b/src/test/ui/infinite/issue-41731-infinite-macro-println.stderr @@ -0,0 +1,38 @@ +error: recursion limit reached while expanding `$crate::format_args_nl!` + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_println`) + = note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: trace_macro + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: expanding `stack! { "overflow" }` + = note: to `println! (stack! ("overflow")) ;` + = note: expanding `println! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }` + = note: expanding `stack! { "overflow" }` + = note: to `println! (stack! ("overflow")) ;` + = note: expanding `println! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }` + +error: format argument must be a string literal + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you might be missing a string literal to format with + | +LL | println!("{}", stack!($overflow)); + | +++++ + +error: aborting due to 2 previous errors + From 2423ea2c5f430616f593fcffe43f17a3f669d881 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 8 Dec 2022 16:55:57 +0900 Subject: [PATCH 2/8] add a test for #103095 --- src/test/ui/borrowck/issue-103095.rs | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/ui/borrowck/issue-103095.rs diff --git a/src/test/ui/borrowck/issue-103095.rs b/src/test/ui/borrowck/issue-103095.rs new file mode 100644 index 0000000000000..0340f39243fa8 --- /dev/null +++ b/src/test/ui/borrowck/issue-103095.rs @@ -0,0 +1,30 @@ +// check-pass + +trait FnOnceForGenericRef: FnOnce(&T) -> Self::FnOutput { + type FnOutput; +} + +impl R> FnOnceForGenericRef for F { + type FnOutput = R; +} + +struct Data> { + value: Option, + output: Option, +} + +impl> Data { + fn new(value: T, f: D) -> Self { + let output = f(&value); + Self { + value: Some(value), + output: Some(output), + } + } +} + +fn test() { + Data::new(String::new(), |_| {}); +} + +fn main() {} From f034cb431d88a89984eb75bdea120e34fabfc798 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 17 Dec 2022 20:59:23 +0000 Subject: [PATCH 3/8] print argument name in arg mismatch if possible --- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 9 ++++++++- src/test/ui/argument-suggestions/basic.stderr | 4 ++-- src/test/ui/error-codes/E0057.stderr | 4 ++-- src/test/ui/higher-rank-trait-bounds/issue-58451.stderr | 4 ++-- src/test/ui/issues/issue-3044.stderr | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 8e520e563ff63..829697c4b9a6b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -28,7 +28,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeSuperVisitable, TypeVisitor}; use rustc_session::Session; -use rustc_span::symbol::Ident; +use rustc_span::symbol::{kw, Ident}; use rustc_span::{self, sym, Span}; use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext}; @@ -1141,6 +1141,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { "()".to_string() } else if expected_ty.is_suggestable(tcx, false) { format!("/* {} */", expected_ty) + } else if let Some(fn_def_id) = fn_def_id + && self.tcx.def_kind(fn_def_id).is_fn_like() + && let self_implicit = matches!(call_expr.kind, hir::ExprKind::MethodCall(..)) as usize + && let Some(arg) = self.tcx.fn_arg_names(fn_def_id).get(expected_idx.as_usize() + self_implicit) + && arg.name != kw::SelfLower + { + format!("/* {} */", arg.name) } else { "/* value */".to_string() } diff --git a/src/test/ui/argument-suggestions/basic.stderr b/src/test/ui/argument-suggestions/basic.stderr index b118ce1bd0ea9..062b3768858dd 100644 --- a/src/test/ui/argument-suggestions/basic.stderr +++ b/src/test/ui/argument-suggestions/basic.stderr @@ -94,8 +94,8 @@ LL | let closure = |x| x; | ^^^ help: provide the argument | -LL | closure(/* value */); - | ~~~~~~~~~~~~~ +LL | closure(/* x */); + | ~~~~~~~~~ error: aborting due to 6 previous errors diff --git a/src/test/ui/error-codes/E0057.stderr b/src/test/ui/error-codes/E0057.stderr index bea226f09dcb9..163737895fea2 100644 --- a/src/test/ui/error-codes/E0057.stderr +++ b/src/test/ui/error-codes/E0057.stderr @@ -11,8 +11,8 @@ LL | let f = |x| x * 3; | ^^^ help: provide the argument | -LL | let a = f(/* value */); - | ~~~~~~~~~~~~~ +LL | let a = f(/* x */); + | ~~~~~~~~~ error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/E0057.rs:5:13 diff --git a/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr b/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr index 09e25f4dc9668..0f051be2128b0 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr @@ -11,8 +11,8 @@ LL | fn f(i: I) | ^ ---- help: provide the argument | -LL | f(&[f(/* value */)]); - | ~~~~~~~~~~~~~ +LL | f(&[f(/* i */)]); + | ~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3044.stderr b/src/test/ui/issues/issue-3044.stderr index 2b142f688ecb9..1232b83c39171 100644 --- a/src/test/ui/issues/issue-3044.stderr +++ b/src/test/ui/issues/issue-3044.stderr @@ -13,7 +13,7 @@ help: provide the argument | LL ~ needlesArr.iter().fold(|x, y| { LL + -LL ~ }, /* value */); +LL ~ }, /* f */); | error: aborting due to previous error From fec9e9ecf1a34aa87bcae28c158a590f75e16a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 18 Dec 2022 14:25:55 +0100 Subject: [PATCH 4/8] don't clone Copy types --- compiler/rustc_borrowck/src/constraints/graph.rs | 2 +- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- compiler/rustc_hir_typeck/src/coercion.rs | 6 +++--- compiler/rustc_hir_typeck/src/demand.rs | 2 +- compiler/rustc_interface/src/queries.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 4 ++-- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_query_impl/src/on_disk_cache.rs | 2 +- compiler/rustc_resolve/src/lib.rs | 2 +- .../rustc_trait_selection/src/traits/error_reporting/mod.rs | 4 ++-- compiler/rustc_transmute/src/layout/nfa.rs | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_borrowck/src/constraints/graph.rs b/compiler/rustc_borrowck/src/constraints/graph.rs index 385f153174c3c..c780d047992cd 100644 --- a/compiler/rustc_borrowck/src/constraints/graph.rs +++ b/compiler/rustc_borrowck/src/constraints/graph.rs @@ -148,7 +148,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirecton> Iterator for Edges<'s, 'tcx, D> { if let Some(p) = self.pointer { self.pointer = self.graph.next_constraints[p]; - Some(self.constraints[p].clone()) + Some(self.constraints[p]) } else if let Some(next_static_idx) = self.next_static_idx { self.next_static_idx = if next_static_idx == (self.graph.first_constraints.len() - 1) { None diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 814bc275019ca..8d4a720f8ce9b 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -612,7 +612,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { let locations = location.to_locations(); for constraint in constraints.outlives().iter() { - let mut constraint = constraint.clone(); + let mut constraint = *constraint; constraint.locations = locations; if let ConstraintCategory::Return(_) | ConstraintCategory::UseAsConst diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 36cf4791492dd..8cdd12e4e347a 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1548,7 +1548,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { cause, expected, found, - coercion_error.clone(), + coercion_error, fcx, parent_id, expression, @@ -1567,7 +1567,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { cause, expected, found, - coercion_error.clone(), + coercion_error, fcx, id, expression, @@ -1583,7 +1583,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { cause, expected, found, - coercion_error.clone(), + coercion_error, ); } } diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 6763e06c0cfee..4ac24aca25a57 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -163,7 +163,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let expr = expr.peel_drop_temps(); let cause = self.misc(expr.span); let expr_ty = self.resolve_vars_with_obligations(checked_ty); - let mut err = self.err_ctxt().report_mismatched_types(&cause, expected, expr_ty, e.clone()); + let mut err = self.err_ctxt().report_mismatched_types(&cause, expected, expr_ty, e); let is_insufficiently_polymorphic = matches!(e, TypeError::RegionsInsufficientlyPolymorphic(..)); diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 39e1f2204b002..1d0c7f5b7a388 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -127,7 +127,7 @@ impl<'tcx> Queries<'tcx> { pub fn register_plugins(&self) -> Result<&Query<(ast::Crate, Lrc)>> { self.register_plugins.compute(|| { - let crate_name = self.crate_name()?.peek().clone(); + let crate_name = *self.crate_name()?.peek(); let krate = self.parse()?.take(); let empty: &(dyn Fn(&Session, &mut LintStore) + Sync + Send) = &|_, _| {}; diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 43862570e8095..cd19e65b6fc32 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -270,7 +270,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns { |lint| { let suggested_ident = format!("{}{}", binding_annot.prefix_str(), ident); - lint.set_arg("ident", ident.clone()).span_suggestion( + lint.set_arg("ident", ident).span_suggestion( fieldpat.span, fluent::suggestion, suggested_ident, @@ -2052,7 +2052,7 @@ impl KeywordIdents { ident.span, fluent::lint_builtin_keyword_idents, |lint| { - lint.set_arg("kw", ident.clone()).set_arg("next", next_edition).span_suggestion( + lint.set_arg("kw", ident).set_arg("next", next_edition).span_suggestion( ident.span, fluent::suggestion, format!("r#{}", ident), diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 856f5bc4645fd..219753dbd16bf 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> Encodable> for Symbol { s.emit_str(self.as_str()); } Entry::Occupied(o) => { - let x = o.get().clone(); + let x = *o.get(); s.emit_u8(SYMBOL_OFFSET); s.emit_usize(x); } diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index ac9653b90071c..c4e605c185217 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -965,7 +965,7 @@ impl<'a, 'tcx> Encodable> for Symbol { s.emit_str(self.as_str()); } Entry::Occupied(o) => { - let x = o.get().clone(); + let x = *o.get(); s.emit_u8(SYMBOL_OFFSET); s.emit_usize(x); } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 24e4b5bdd3f50..4861ee746aae3 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1491,7 +1491,7 @@ impl<'a> Resolver<'a> { label_res_map: self.label_res_map.clone(), lifetimes_res_map: self.lifetimes_res_map.clone(), extra_lifetime_params_map: self.extra_lifetime_params_map.clone(), - next_node_id: self.next_node_id.clone(), + next_node_id: self.next_node_id, node_id_to_def_id: self.node_id_to_def_id.clone(), def_id_to_node_id: self.def_id_to_node_id.clone(), trait_map: self.trait_map.clone(), diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 2dd2c568bab97..929d813bfc35d 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1574,7 +1574,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { &error.obligation.cause, expected_found.expected, expected_found.found, - err.clone(), + *err, ) .emit(); } @@ -1583,7 +1583,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { &error.obligation.cause, expected_found.expected, expected_found.found, - err.clone(), + *err, ); let code = error.obligation.cause.code().peel_derives().peel_match_impls(); if let ObligationCauseCode::BindingObligation(..) diff --git a/compiler/rustc_transmute/src/layout/nfa.rs b/compiler/rustc_transmute/src/layout/nfa.rs index c2bc47bc043a0..78fcceb5f2cb5 100644 --- a/compiler/rustc_transmute/src/layout/nfa.rs +++ b/compiler/rustc_transmute/src/layout/nfa.rs @@ -123,7 +123,7 @@ where let fix_state = |state| if state == other.start { self.accepting } else { state }; let entry = transitions.entry(fix_state(source)).or_default(); for (edge, destinations) in transition { - let entry = entry.entry(edge.clone()).or_default(); + let entry = entry.entry(edge).or_default(); for destination in destinations { entry.insert(fix_state(destination)); } @@ -147,7 +147,7 @@ where } let entry = transitions.entry(source).or_default(); for (edge, destinations) in transition { - let entry = entry.entry(edge.clone()).or_default(); + let entry = entry.entry(*edge).or_default(); for &(mut destination) in destinations { // if dest is accepting state of `other`, replace with accepting state of `self` if destination == other.accepting { From 6e52a0f42182b6f628329b32db951beb57bcb2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 18 Dec 2022 13:51:40 +0100 Subject: [PATCH 5/8] remove redundant fn params that were only "used" in recursion --- .../rustc_borrowck/src/region_infer/mod.rs | 29 ++----------------- .../rustc_hir_analysis/src/check/check.rs | 7 ++--- compiler/rustc_hir_typeck/src/pat.rs | 11 ++----- .../src/traits/auto_trait.rs | 7 +---- 4 files changed, 10 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index e9c98bdc51496..0d03346ef0a5e 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -831,7 +831,6 @@ impl<'tcx> RegionInferenceContext<'tcx> { if self.eval_verify_bound( infcx, param_env, - body, generic_ty, type_test.lower_bound, &type_test.verify_bound, @@ -962,14 +961,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // where `ur` is a local bound -- we are sometimes in a // position to prove things that our caller cannot. See // #53570 for an example. - if self.eval_verify_bound( - infcx, - param_env, - body, - generic_ty, - ur, - &type_test.verify_bound, - ) { + if self.eval_verify_bound(infcx, param_env, generic_ty, ur, &type_test.verify_bound) { continue; } @@ -1190,7 +1182,6 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, infcx: &InferCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - body: &Body<'tcx>, generic_ty: Ty<'tcx>, lower_bound: RegionVid, verify_bound: &VerifyBound<'tcx>, @@ -1213,25 +1204,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { } VerifyBound::AnyBound(verify_bounds) => verify_bounds.iter().any(|verify_bound| { - self.eval_verify_bound( - infcx, - param_env, - body, - generic_ty, - lower_bound, - verify_bound, - ) + self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound) }), VerifyBound::AllBounds(verify_bounds) => verify_bounds.iter().all(|verify_bound| { - self.eval_verify_bound( - infcx, - param_env, - body, - generic_ty, - lower_bound, - verify_bound, - ) + self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound) }), } } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index aa01feb3a1ea4..eee0ba2e5ed27 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -99,18 +99,17 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b ty: Ty<'tcx>, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - span: Span, ) -> bool { // We don't just accept all !needs_drop fields, due to semver concerns. match ty.kind() { ty::Ref(..) => true, // references never drop (even mutable refs, which are non-Copy and hence fail the later check) ty::Tuple(tys) => { // allow tuples of allowed types - tys.iter().all(|ty| allowed_union_field(ty, tcx, param_env, span)) + tys.iter().all(|ty| allowed_union_field(ty, tcx, param_env)) } ty::Array(elem, _len) => { // Like `Copy`, we do *not* special-case length 0. - allowed_union_field(*elem, tcx, param_env, span) + allowed_union_field(*elem, tcx, param_env) } _ => { // Fallback case: allow `ManuallyDrop` and things that are `Copy`. @@ -124,7 +123,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b for field in &def.non_enum_variant().fields { let field_ty = field.ty(tcx, substs); - if !allowed_union_field(field_ty, tcx, param_env, span) { + if !allowed_union_field(field_ty, tcx, param_env) { let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) { // We are currently checking the type this field came from, so it must be local. Some(Node::Field(field)) => (field.span, field.ty.span), diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 6810353f9e778..d3e88b1b80ae2 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -2130,7 +2130,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { let ty = self.resolve_vars_if_possible(ti.expected); - let is_slice_or_array_or_vector = self.is_slice_or_array_or_vector(&mut err, snippet.clone(), ty); + let is_slice_or_array_or_vector = self.is_slice_or_array_or_vector(ty); match is_slice_or_array_or_vector.1.kind() { ty::Adt(adt_def, _) if self.tcx.is_diagnostic_item(sym::Option, adt_def.did()) @@ -2159,17 +2159,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.emit(); } - fn is_slice_or_array_or_vector( - &self, - err: &mut Diagnostic, - snippet: String, - ty: Ty<'tcx>, - ) -> (bool, Ty<'tcx>) { + fn is_slice_or_array_or_vector(&self, ty: Ty<'tcx>) -> (bool, Ty<'tcx>) { match ty.kind() { ty::Adt(adt_def, _) if self.tcx.is_diagnostic_item(sym::Vec, adt_def.did()) => { (true, ty) } - ty::Ref(_, ty, _) => self.is_slice_or_array_or_vector(err, snippet, *ty), + ty::Ref(_, ty, _) => self.is_slice_or_array_or_vector(*ty), ty::Slice(..) | ty::Array(..) => (true, ty), _ => (false, ty), } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index aef2f8ff9911c..948632ccc6c40 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -159,13 +159,12 @@ impl<'tcx> AutoTraitFinder<'tcx> { orig_env, orig_env, &mut fresh_preds, - false, ) else { return AutoTraitResult::NegativeImpl; }; let (full_env, full_user_env) = self - .evaluate_predicates(&infcx, trait_did, ty, new_env, user_env, &mut fresh_preds, true) + .evaluate_predicates(&infcx, trait_did, ty, new_env, user_env, &mut fresh_preds) .unwrap_or_else(|| { panic!("Failed to fully process: {:?} {:?} {:?}", ty, trait_did, orig_env) }); @@ -247,7 +246,6 @@ impl<'tcx> AutoTraitFinder<'tcx> { param_env: ty::ParamEnv<'tcx>, user_env: ty::ParamEnv<'tcx>, fresh_preds: &mut FxHashSet>, - only_projections: bool, ) -> Option<(ty::ParamEnv<'tcx>, ty::ParamEnv<'tcx>)> { let tcx = infcx.tcx; @@ -322,7 +320,6 @@ impl<'tcx> AutoTraitFinder<'tcx> { fresh_preds, &mut predicates, &mut select, - only_projections, ) { return None; } @@ -600,7 +597,6 @@ impl<'tcx> AutoTraitFinder<'tcx> { fresh_preds: &mut FxHashSet>, predicates: &mut VecDeque>, selcx: &mut SelectionContext<'_, 'tcx>, - only_projections: bool, ) -> bool { let dummy_cause = ObligationCause::dummy(); @@ -744,7 +740,6 @@ impl<'tcx> AutoTraitFinder<'tcx> { fresh_preds, predicates, selcx, - only_projections, ) { return false; } From 3af7df91fcbe4c5197e55dc78838aeb5aa978d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 18 Dec 2022 16:17:46 +0100 Subject: [PATCH 6/8] use &str / String literals instead of format!() --- .../src/diagnostics/conflict_errors.rs | 2 +- .../src/diagnostics/explain_borrow.rs | 2 +- .../src/diagnostics/region_errors.rs | 2 +- compiler/rustc_codegen_llvm/src/asm.rs | 2 +- compiler/rustc_hir_analysis/src/astconv/mod.rs | 2 +- compiler/rustc_hir_typeck/src/demand.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 6 +----- compiler/rustc_hir_typeck/src/method/suggest.rs | 2 +- .../rustc_infer/src/infer/error_reporting/mod.rs | 4 ++-- .../nice_region_error/placeholder_relation.rs | 14 ++++---------- .../rustc_lint/src/for_loops_over_fallibles.rs | 6 +++--- .../rustc_macros/src/diagnostics/diagnostic.rs | 12 ++++-------- compiler/rustc_middle/src/mir/pretty.rs | 8 ++++---- .../src/build/custom/parse/instruction.rs | 2 +- compiler/rustc_resolve/src/late/diagnostics.rs | 8 ++------ .../src/traits/const_evaluatable.rs | 8 ++++---- .../src/traits/error_reporting/mod.rs | 4 ++-- .../src/traits/error_reporting/suggestions.rs | 4 ++-- 19 files changed, 37 insertions(+), 55 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 72c0257756ef2..8d5c5a7124f88 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -649,7 +649,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if !assign_value.is_empty() { err.span_suggestion_verbose( sugg_span.shrink_to_hi(), - format!("consider assigning a value"), + "consider assigning a value", format!(" = {}", assign_value), Applicability::MaybeIncorrect, ); diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 304683618d83e..00f5e8a83972f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -270,7 +270,7 @@ impl<'tcx> BorrowExplanation<'tcx> { for extra in extra_info { match extra { ExtraConstraintInfo::PlaceholderFromPredicate(span) => { - err.span_note(*span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime")); + err.span_note(*span, "due to current limitations in the borrow checker, this implies a `'static` lifetime"); } } } diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index f8ec5e5e79914..b5a0044e9e8cd 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -472,7 +472,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { for extra in extra_info { match extra { ExtraConstraintInfo::PlaceholderFromPredicate(span) => { - diag.span_note(span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime")); + diag.span_note(span, "due to current limitations in the borrow checker, this implies a `'static` lifetime"); } } } diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 219a4f8fa8959..606f710641fc0 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -144,7 +144,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { // We prefer the latter because it matches the behavior of // Clang. if late && matches!(reg, InlineAsmRegOrRegClass::Reg(_)) { - constraints.push(format!("{}", reg_to_llvm(reg, Some(&in_value.layout)))); + constraints.push(reg_to_llvm(reg, Some(&in_value.layout)).to_string()); } else { constraints.push(format!("{}", op_idx[&idx])); } diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 71f26eb60c962..e4c16ef9efa19 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2240,7 +2240,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ), "s", ), - [only] => (format!("{only}"), ""), + [only] => (only.to_string(), ""), [] => unreachable!(), }; let last_span = *arg_spans.last().unwrap(); diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 6763e06c0cfee..f02db43f73af6 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -406,7 +406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let note_about_variant_field_privacy = (field_is_local && !field_is_accessible) - .then(|| format!(" (its field is private, but it's local to this crate and its privacy can be changed)")); + .then(|| " (its field is private, but it's local to this crate and its privacy can be changed)".to_string()); let sole_field_ty = sole_field.ty(self.tcx, substs); if self.can_coerce(expr_ty, sole_field_ty) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 8e520e563ff63..240044fe92d28 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1013,7 +1013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { args_span }; - labels.push((span, format!("multiple arguments are missing"))); + labels.push((span, "multiple arguments are missing".to_string())); suggestion_text = match suggestion_text { SuggestionText::None | SuggestionText::Provide(_) => { SuggestionText::Provide(true) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 407d6ac8544c2..59c9d219d33d3 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -319,11 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - err.multipart_suggestion_verbose( - format!("use parentheses to call these"), - sugg, - applicability, - ); + err.multipart_suggestion_verbose("use parentheses to call these", sugg, applicability); true } else { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index d40a66715a2ea..7c5a9a333feba 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1007,7 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if def_kind == DefKind::AssocFn && lev_candidate.fn_has_self_parameter { err.span_suggestion( span, - &format!("there is a method with a similar name",), + "there is a method with a similar name", lev_candidate.name, Applicability::MaybeIncorrect, ); diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 397fa43175f73..269fc95420ade 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -184,7 +184,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>( let text = if br.has_name() { format!("the lifetime `{}` as defined here", br.name) } else { - format!("the anonymous lifetime as defined here") + "the anonymous lifetime as defined here".to_string() }; (text, sp) } @@ -203,7 +203,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>( sp = param.span; } let text = if name == kw::UnderscoreLifetime { - format!("the anonymous lifetime as defined here") + "the anonymous lifetime as defined here".to_string() } else { format!("the lifetime `{}` as defined here", name) }; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs index c42240f21724f..9534bce54ef0e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs @@ -44,7 +44,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { ); } (Some(sub_span), Some(sup_span), _, Some(sup_symbol)) => { - err.span_note(sub_span, format!("the lifetime defined here...")); + err.span_note(sub_span, "the lifetime defined here..."); err.span_note( sup_span, format!("...must outlive the lifetime `{sup_symbol}` defined here"), @@ -55,17 +55,11 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { sub_span, format!("the lifetime `{sub_symbol}` defined here..."), ); - err.span_note( - sup_span, - format!("...must outlive the lifetime defined here"), - ); + err.span_note(sup_span, "...must outlive the lifetime defined here"); } (Some(sub_span), Some(sup_span), _, _) => { - err.span_note(sub_span, format!("the lifetime defined here...")); - err.span_note( - sup_span, - format!("...must outlive the lifetime defined here"), - ); + err.span_note(sub_span, "the lifetime defined here..."); + err.span_note(sup_span, "...must outlive the lifetime defined here"); } _ => {} } diff --git a/compiler/rustc_lint/src/for_loops_over_fallibles.rs b/compiler/rustc_lint/src/for_loops_over_fallibles.rs index 4187850153ccd..182734fa9fc8f 100644 --- a/compiler/rustc_lint/src/for_loops_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loops_over_fallibles.rs @@ -71,11 +71,11 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles { ); } else { lint.multipart_suggestion_verbose( - format!("to check pattern in a loop use `while let`"), + "to check pattern in a loop use `while let`", vec![ // NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts (expr.span.with_hi(pat.span.lo()), format!("while let {var}(")), - (pat.span.between(arg.span), format!(") = ")), + (pat.span.between(arg.span), ") = ".to_string()), ], Applicability::MaybeIncorrect ); @@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles { vec![ // NB can't use `until` here because `expr.span` and `pat.span` have different syntax contexts (expr.span.with_hi(pat.span.lo()), format!("if let {var}(")), - (pat.span.between(arg.span), format!(") = ")), + (pat.span.between(arg.span), ") = ".to_string()), ], Applicability::MaybeIncorrect, ) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index 13f06fe747349..9ff9448640477 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -39,10 +39,8 @@ impl<'a> DiagnosticDerive<'a> { let init = match builder.slug.value_ref() { None => { span_err(builder.span, "diagnostic slug not specified") - .help(format!( - "specify the slug as the first argument to the `#[diag(...)]` \ - attribute, such as `#[diag(hir_analysis_example_error)]`", - )) + .help("specify the slug as the first argument to the `#[diag(...)]` \ + attribute, such as `#[diag(hir_analysis_example_error)]`") .emit(); return DiagnosticDeriveError::ErrorHandled.to_compile_error(); } @@ -133,10 +131,8 @@ impl<'a> LintDiagnosticDerive<'a> { match builder.slug.value_ref() { None => { span_err(builder.span, "diagnostic slug not specified") - .help(format!( - "specify the slug as the first argument to the attribute, such as \ - `#[diag(compiletest_example)]`", - )) + .help("specify the slug as the first argument to the attribute, such as \ + `#[diag(compiletest_example)]`") .emit(); DiagnosticDeriveError::ErrorHandled.to_compile_error() } diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 2a4ff4b8810db..1ebfdbbd6ef00 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -448,15 +448,15 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { // FIXME: this is a poor version of `pretty_print_const_value`. let fmt_val = |val: &ConstValue<'tcx>| match val { - ConstValue::ZeroSized => format!(""), + ConstValue::ZeroSized => "".to_string(), ConstValue::Scalar(s) => format!("Scalar({:?})", s), - ConstValue::Slice { .. } => format!("Slice(..)"), - ConstValue::ByRef { .. } => format!("ByRef(..)"), + ConstValue::Slice { .. } => "Slice(..)".to_string(), + ConstValue::ByRef { .. } => "ByRef(..)".to_string(), }; let fmt_valtree = |valtree: &ty::ValTree<'tcx>| match valtree { ty::ValTree::Leaf(leaf) => format!("ValTree::Leaf({:?})", leaf), - ty::ValTree::Branch(_) => format!("ValTree::Branch(..)"), + ty::ValTree::Branch(_) => "ValTree::Branch(..)".to_string(), }; let val = match literal { diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs index ecc3e4de8d1da..7c39a93a8eb9e 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs @@ -76,7 +76,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { let Some((otherwise, rest)) = arms.split_last() else { return Err(ParseError { span, - item_description: format!("no arms"), + item_description: "no arms".to_string(), expected: "at least one arm".to_string(), }) }; diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 49bbe37ee4328..600308b6508db 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -277,11 +277,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { let override_suggestion = if ["true", "false"].contains(&item_str.to_string().to_lowercase().as_str()) { let item_typo = item_str.to_string().to_lowercase(); - Some(( - item_span, - "you may want to use a bool value instead", - format!("{}", item_typo), - )) + Some((item_span, "you may want to use a bool value instead", item_typo)) // FIXME(vincenzopalazzo): make the check smarter, // and maybe expand with levenshtein distance checks } else if item_str.as_str() == "printf" { @@ -2324,7 +2320,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { let message = format!("consider introducing lifetime `{}` here", name); should_continue = suggest(err, false, span, &message, sugg); } else { - let message = format!("consider introducing a named lifetime parameter"); + let message = "consider introducing a named lifetime parameter"; should_continue = suggest(err, false, span, &message, sugg); } } diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 7c9fde27420bc..f8efe9bfa9f82 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -138,10 +138,10 @@ pub fn is_const_evaluatable<'tcx>( } else if uv.has_non_region_param() { NotConstEvaluatable::MentionsParam } else { - let guar = infcx.tcx.sess.delay_span_bug( - span, - format!("Missing value for constant, but no error reported?"), - ); + let guar = infcx + .tcx + .sess + .delay_span_bug(span, "Missing value for constant, but no error reported?"); NotConstEvaluatable::Error(guar) }; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 2dd2c568bab97..11eac0528134f 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2332,9 +2332,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // get rid of :: between Trait and // must be '::' between them, otherwise the parser won't accept the code suggestions.push((between_span, "".to_string(),)); - suggestions.push((generic_arg.span_ext.shrink_to_hi(), format!(">"))); + suggestions.push((generic_arg.span_ext.shrink_to_hi(), ">".to_string())); } else { - suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), format!(">"))); + suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), ">".to_string())); } err.multipart_suggestion( message, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index d47a5ea3e3706..5a4c87c56d5da 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2740,7 +2740,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } ty::Closure(def_id, _) => err.span_note( self.tcx.def_span(def_id), - &format!("required because it's used within this closure"), + "required because it's used within this closure", ), _ => err.note(&msg), }; @@ -3386,7 +3386,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } err.span_note( multi_span, - format!("the method call chain might not have had the expected associated types"), + "the method call chain might not have had the expected associated types", ); } } From 0c029ab07ced737730da1e6274ea9b3a2e4d0b41 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 18 Dec 2022 11:42:30 +0100 Subject: [PATCH 7/8] Update browser-ui-test version to reduce GUI tests flakyness --- .../docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version index 3f8dcd03d2db1..475434e5aef86 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version @@ -1 +1 @@ -0.13.2 \ No newline at end of file +0.13.4 \ No newline at end of file From d59a2ac2bc42fb76d208da256ec0ed4887633319 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 18 Dec 2022 20:28:59 +0100 Subject: [PATCH 8/8] Revert "Introduce lowering_arena to avoid creating AST nodes on the fly" This reverts commit d9a1faaa9cff6eab069ea8e5cd7862d0ae48e231. This was originally part of a larger PR that has now been closed as a different approach is taken now. --- compiler/rustc_ast_lowering/src/item.rs | 4 +- compiler/rustc_ast_lowering/src/lib.rs | 55 +++++++++---------------- 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 73065ab516350..9d4c2900eaf41 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1,6 +1,6 @@ use super::errors::{InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound}; use super::ResolverAstLoweringExt; -use super::{Arena, AstOwner, ImplTraitContext, ImplTraitPosition}; +use super::{AstOwner, ImplTraitContext, ImplTraitPosition}; use super::{FnDeclKind, LoweringContext, ParamMode}; use rustc_ast::ptr::P; @@ -24,7 +24,6 @@ use thin_vec::ThinVec; pub(super) struct ItemLowerer<'a, 'hir> { pub(super) tcx: TyCtxt<'hir>, pub(super) resolver: &'a mut ResolverAstLowering, - pub(super) ast_arena: &'a Arena<'static>, pub(super) ast_index: &'a IndexVec>, pub(super) owners: &'a mut IndexVec>>, } @@ -60,7 +59,6 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { tcx: self.tcx, resolver: self.resolver, arena: self.tcx.hir_arena, - ast_arena: self.ast_arena, // HirId handling. bodies: Vec::new(), diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index d67ede6e1302e..fe0d0747be60c 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -42,7 +42,6 @@ extern crate tracing; use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait, TraitFnAsync}; -use rustc_arena::declare_arena; use rustc_ast::ptr::P; use rustc_ast::visit; use rustc_ast::{self as ast, *}; @@ -94,13 +93,6 @@ struct LoweringContext<'a, 'hir> { /// Used to allocate HIR nodes. arena: &'hir hir::Arena<'hir>, - /// Used to allocate temporary AST nodes for use during lowering. - /// This allows us to create "fake" AST -- these nodes can sometimes - /// be allocated on the stack, but other times we need them to live longer - /// than the current stack frame, so they can be collected into vectors - /// and things like that. - ast_arena: &'a Arena<'static>, - /// Bodies inside the owner being lowered. bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>, /// Attributes inside the owner being lowered. @@ -146,15 +138,6 @@ struct LoweringContext<'a, 'hir> { generics_def_id_map: Vec>, } -declare_arena!([ - [] tys: rustc_ast::Ty, - [] aba: rustc_ast::AngleBracketedArgs, - [] ptr: rustc_ast::PolyTraitRef, - // This _marker field is needed because `declare_arena` creates `Arena<'tcx>` and we need to - // use `'tcx`. If we don't have this we get a compile error. - [] _marker: std::marker::PhantomData<&'tcx ()>, -]); - trait ResolverAstLoweringExt { fn legacy_const_generic_args(&self, expr: &Expr) -> Option>; fn get_partial_res(&self, id: NodeId) -> Option; @@ -442,13 +425,10 @@ pub fn lower_to_hir<'hir>(tcx: TyCtxt<'hir>, (): ()) -> hir::Crate<'hir> { tcx.definitions_untracked().def_index_count(), ); - let ast_arena = Arena::default(); - for def_id in ast_index.indices() { item::ItemLowerer { tcx, resolver: &mut resolver, - ast_arena: &ast_arena, ast_index: &ast_index, owners: &mut owners, } @@ -1001,8 +981,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } GenericArgs::Parenthesized(data) => { self.emit_bad_parenthesized_trait_in_assoc_ty(data); - let aba = self.ast_arena.aba.alloc(data.as_angle_bracketed_args()); - self.lower_angle_bracketed_parameter_data(aba, ParamMode::Explicit, itctx).0 + self.lower_angle_bracketed_parameter_data( + &data.as_angle_bracketed_args(), + ParamMode::Explicit, + itctx, + ) + .0 } }; gen_args_ctor.into_generic_args(self) @@ -1067,13 +1051,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.with_dyn_type_scope(false, |this| { let node_id = this.next_node_id(); - let ty = this.ast_arena.tys.alloc(Ty { - id: node_id, - kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()), - span: this.lower_span(constraint.span), - tokens: None, - }); - let ty = this.lower_ty(ty, itctx); + let ty = this.lower_ty( + &Ty { + id: node_id, + kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()), + span: this.lower_span(constraint.span), + tokens: None, + }, + itctx, + ); hir::TypeBindingKind::Equality { term: ty.into() } }) @@ -1217,13 +1203,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res() { let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| { - let poly_trait_ref = this.ast_arena.ptr.alloc(PolyTraitRef { - bound_generic_params: vec![], - trait_ref: TraitRef { path: path.clone(), ref_id: t.id }, - span: t.span - }); let bound = this.lower_poly_trait_ref( - poly_trait_ref, + &PolyTraitRef { + bound_generic_params: vec![], + trait_ref: TraitRef { path: path.clone(), ref_id: t.id }, + span: t.span + }, itctx, ); let bounds = this.arena.alloc_from_iter([bound]);