Skip to content

Commit a51ec18

Browse files
committed
Pass translation closure to add_to_diag_with() as reference
1 parent 13eb8c7 commit a51ec18

File tree

16 files changed

+39
-39
lines changed

16 files changed

+39
-39
lines changed

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Subdiagnostic for InvalidAbiReason {
4444
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
4545
self,
4646
diag: &mut Diag<'_, G>,
47-
_: F,
47+
_: &F,
4848
) {
4949
#[allow(rustc::untranslatable_diagnostic)]
5050
diag.note(self.0);

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl Subdiagnostic for EmptyLabelManySpans {
382382
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
383383
self,
384384
diag: &mut Diag<'_, G>,
385-
_: F,
385+
_: &F,
386386
) {
387387
diag.span_labels(self.0, "");
388388
}
@@ -751,7 +751,7 @@ impl Subdiagnostic for StableFeature {
751751
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
752752
self,
753753
diag: &mut Diag<'_, G>,
754-
_: F,
754+
_: &F,
755755
) {
756756
diag.arg("name", self.name);
757757
diag.arg("since", self.since);

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl Subdiagnostic for FormatUnusedArg {
601601
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
602602
self,
603603
diag: &mut Diag<'_, G>,
604-
f: F,
604+
f: &F,
605605
) {
606606
diag.arg("named", self.named);
607607
let msg = f(diag, crate::fluent_generated::builtin_macros_format_unused_arg.into());

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ where
177177
{
178178
/// Add a subdiagnostic to an existing diagnostic.
179179
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
180-
self.add_to_diag_with(diag, |_, m| m);
180+
self.add_to_diag_with(diag, &|_, m| m);
181181
}
182182

183183
/// Add a subdiagnostic to an existing diagnostic where `f` is invoked on every message used
184184
/// (to optionally perform eager translation).
185185
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
186186
self,
187187
diag: &mut Diag<'_, G>,
188-
f: F,
188+
f: &F,
189189
);
190190
}
191191

@@ -1197,7 +1197,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11971197
dcx: &crate::DiagCtxt,
11981198
subdiagnostic: impl Subdiagnostic,
11991199
) -> &mut Self {
1200-
subdiagnostic.add_to_diag_with(self, |diag, msg| {
1200+
subdiagnostic.add_to_diag_with(self, &|diag, msg| {
12011201
let args = diag.args.iter();
12021202
let msg = diag.subdiagnostic_message_to_diagnostic_message(msg);
12031203
dcx.eagerly_translate(msg, args)

compiler/rustc_errors/src/diagnostic_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl Subdiagnostic for SingleLabelManySpans {
302302
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
303303
self,
304304
diag: &mut Diag<'_, G>,
305-
_: F,
305+
_: &F,
306306
) {
307307
diag.span_labels(self.spans, self.label);
308308
}

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Subdiagnostic for TypeMismatchFruTypo {
191191
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
192192
self,
193193
diag: &mut Diag<'_, G>,
194-
_f: F,
194+
_f: &F,
195195
) {
196196
diag.arg("expr", self.expr.as_deref().unwrap_or("NONE"));
197197

@@ -370,7 +370,7 @@ impl Subdiagnostic for RemoveSemiForCoerce {
370370
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
371371
self,
372372
diag: &mut Diag<'_, G>,
373-
_f: F,
373+
_f: &F,
374374
) {
375375
let mut multispan: MultiSpan = self.semi.into();
376376
multispan.push_span_label(self.expr, fluent::hir_typeck_remove_semi_for_coerce_expr);
@@ -546,7 +546,7 @@ impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
546546
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
547547
self,
548548
diag: &mut Diag<'_, G>,
549-
f: F,
549+
f: &F,
550550
) {
551551
match self {
552552
CastUnknownPointerSub::To(span) => {

compiler/rustc_infer/src/errors/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Subdiagnostic for RegionOriginNote<'_> {
239239
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
240240
self,
241241
diag: &mut Diag<'_, G>,
242-
_f: F,
242+
_f: &F,
243243
) {
244244
let mut label_or_note = |span, msg: DiagMessage| {
245245
let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
@@ -304,7 +304,7 @@ impl Subdiagnostic for LifetimeMismatchLabels {
304304
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
305305
self,
306306
diag: &mut Diag<'_, G>,
307-
_f: F,
307+
_f: &F,
308308
) {
309309
match self {
310310
LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
@@ -352,7 +352,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
352352
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
353353
self,
354354
diag: &mut Diag<'_, G>,
355-
_f: F,
355+
_f: &F,
356356
) {
357357
let mut mk_suggestion = || {
358358
let (
@@ -454,7 +454,7 @@ impl Subdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
454454
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
455455
mut self,
456456
diag: &mut Diag<'_, G>,
457-
_f: F,
457+
_f: &F,
458458
) {
459459
self.unmet_requirements
460460
.push_span_label(self.binding_span, fluent::infer_msl_introduces_static);
@@ -773,7 +773,7 @@ impl Subdiagnostic for ConsiderBorrowingParamHelp {
773773
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
774774
self,
775775
diag: &mut Diag<'_, G>,
776-
f: F,
776+
f: &F,
777777
) {
778778
let mut type_param_span: MultiSpan = self.spans.clone().into();
779779
for &span in &self.spans {
@@ -818,7 +818,7 @@ impl Subdiagnostic for DynTraitConstraintSuggestion {
818818
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
819819
self,
820820
diag: &mut Diag<'_, G>,
821-
f: F,
821+
f: &F,
822822
) {
823823
let mut multi_span: MultiSpan = vec![self.span].into();
824824
multi_span.push_span_label(self.span, fluent::infer_dtcs_has_lifetime_req_label);
@@ -865,7 +865,7 @@ impl Subdiagnostic for ReqIntroducedLocations {
865865
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
866866
mut self,
867867
diag: &mut Diag<'_, G>,
868-
f: F,
868+
f: &F,
869869
) {
870870
for sp in self.spans {
871871
self.span.push_span_label(sp, fluent::infer_ril_introduced_here);
@@ -888,7 +888,7 @@ impl Subdiagnostic for MoreTargeted {
888888
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
889889
self,
890890
diag: &mut Diag<'_, G>,
891-
_f: F,
891+
_f: &F,
892892
) {
893893
diag.code(E0772);
894894
diag.primary_message(fluent::infer_more_targeted);
@@ -1293,7 +1293,7 @@ impl Subdiagnostic for SuggestTuplePatternMany {
12931293
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
12941294
self,
12951295
diag: &mut Diag<'_, G>,
1296-
f: F,
1296+
f: &F,
12971297
) {
12981298
diag.arg("path", self.path);
12991299
let message = f(diag, crate::fluent_generated::infer_stp_wrap_many.into());

compiler/rustc_infer/src/errors/note_and_explain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl Subdiagnostic for RegionExplanation<'_> {
163163
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
164164
self,
165165
diag: &mut Diag<'_, G>,
166-
f: F,
166+
f: &F,
167167
) {
168168
diag.arg("pref_kind", self.prefix);
169169
diag.arg("suff_kind", self.suffix);

compiler/rustc_lint/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Subdiagnostic for OverruledAttributeSub {
2727
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
2828
self,
2929
diag: &mut Diag<'_, G>,
30-
_f: F,
30+
_f: &F,
3131
) {
3232
match self {
3333
OverruledAttributeSub::DefaultSource { id } => {

compiler/rustc_lint/src/lints.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'a, 'b> Subdiagnostic for SuggestChangingAssocTypes<'a, 'b> {
274274
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
275275
self,
276276
diag: &mut Diag<'_, G>,
277-
_f: F,
277+
_f: &F,
278278
) {
279279
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
280280
// bound. Let's see if this type does that.
@@ -330,7 +330,7 @@ impl Subdiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
330330
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
331331
self,
332332
diag: &mut Diag<'_, G>,
333-
_f: F,
333+
_f: &F,
334334
) {
335335
diag.multipart_suggestion(
336336
fluent::lint_suggestion,
@@ -451,7 +451,7 @@ impl Subdiagnostic for BuiltinUnpermittedTypeInitSub {
451451
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
452452
self,
453453
diag: &mut Diag<'_, G>,
454-
_f: F,
454+
_f: &F,
455455
) {
456456
let mut err = self.err;
457457
loop {
@@ -506,7 +506,7 @@ impl Subdiagnostic for BuiltinClashingExternSub<'_> {
506506
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
507507
self,
508508
diag: &mut Diag<'_, G>,
509-
_f: F,
509+
_f: &F,
510510
) {
511511
let mut expected_str = DiagStyledString::new();
512512
expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
@@ -788,7 +788,7 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagLabels {
788788
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
789789
self,
790790
diag: &mut Diag<'_, G>,
791-
_f: F,
791+
_f: &F,
792792
) {
793793
for (c, span) in self.spans {
794794
diag.span_label(span, format!("{c:?}"));
@@ -806,7 +806,7 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
806806
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
807807
self,
808808
diag: &mut Diag<'_, G>,
809-
_f: F,
809+
_f: &F,
810810
) {
811811
match self {
812812
HiddenUnicodeCodepointsDiagSub::Escape { spans } => {
@@ -954,7 +954,7 @@ impl Subdiagnostic for NonBindingLetSub {
954954
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
955955
self,
956956
diag: &mut Diag<'_, G>,
957-
_f: F,
957+
_f: &F,
958958
) {
959959
let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
960960

@@ -1240,7 +1240,7 @@ impl Subdiagnostic for NonSnakeCaseDiagSub {
12401240
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
12411241
self,
12421242
diag: &mut Diag<'_, G>,
1243-
_f: F,
1243+
_f: &F,
12441244
) {
12451245
match self {
12461246
NonSnakeCaseDiagSub::Label { span } => {
@@ -1482,7 +1482,7 @@ impl Subdiagnostic for OverflowingBinHexSign {
14821482
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
14831483
self,
14841484
diag: &mut Diag<'_, G>,
1485-
_f: F,
1485+
_f: &F,
14861486
) {
14871487
match self {
14881488
OverflowingBinHexSign::Positive => {

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl SubdiagnosticDerive {
9090
fn add_to_diag_with<__G, __F>(
9191
self,
9292
#diag: &mut rustc_errors::Diag<'_, __G>,
93-
#f: __F
93+
#f: &__F
9494
) where
9595
__G: rustc_errors::EmissionGuarantee,
9696
__F: rustc_errors::SubdiagMessageOp<__G>,

compiler/rustc_mir_build/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl Subdiagnostic for UnsafeNotInheritedLintNote {
423423
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
424424
self,
425425
diag: &mut Diag<'_, G>,
426-
_f: F,
426+
_f: &F,
427427
) {
428428
diag.span_note(self.signature_span, fluent::mir_build_unsafe_fn_safe_body);
429429
let body_start = self.body_span.shrink_to_lo();
@@ -871,7 +871,7 @@ impl<'tcx> Subdiagnostic for AdtDefinedHere<'tcx> {
871871
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
872872
self,
873873
diag: &mut Diag<'_, G>,
874-
_f: F,
874+
_f: &F,
875875
) {
876876
diag.arg("ty", self.ty);
877877
let mut spans = MultiSpan::from(self.adt_def_span);

compiler/rustc_parse/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ impl Subdiagnostic for FnTraitMissingParen {
14631463
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
14641464
self,
14651465
diag: &mut Diag<'_, G>,
1466-
_: F,
1466+
_: &F,
14671467
) {
14681468
diag.span_label(self.span, crate::fluent_generated::parse_fn_trait_missing_paren);
14691469
let applicability = if self.machine_applicable {

compiler/rustc_passes/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ impl Subdiagnostic for UnusedVariableStringInterp {
17551755
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
17561756
self,
17571757
diag: &mut Diag<'_, G>,
1758-
_f: F,
1758+
_f: &F,
17591759
) {
17601760
diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
17611761
diag.multipart_suggestion(

compiler/rustc_pattern_analysis/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> Subdiagnostic for Overlap<'tcx> {
6565
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
6666
self,
6767
diag: &mut Diag<'_, G>,
68-
_: F,
68+
_: &F,
6969
) {
7070
let Overlap { span, range } = self;
7171

@@ -113,7 +113,7 @@ impl<'tcx> Subdiagnostic for GappedRange<'tcx> {
113113
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
114114
self,
115115
diag: &mut Diag<'_, G>,
116-
_: F,
116+
_: &F,
117117
) {
118118
let GappedRange { span, gap, first_range } = self;
119119

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Subdiagnostic for AdjustSignatureBorrow {
104104
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
105105
self,
106106
diag: &mut Diag<'_, G>,
107-
_f: F,
107+
_f: &F,
108108
) {
109109
match self {
110110
AdjustSignatureBorrow::Borrow { to_borrow } => {

0 commit comments

Comments
 (0)