Skip to content

Commit 58353fa

Browse files
authoredDec 15, 2023
Rollup merge of #118727 - compiler-errors:lint-decorate, r=WaffleLapkin
Don't pass lint back out of lint decorator Change the decorator function in the signature of the `emit_lint`/`span_lint`/etc family of methods from `impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` to `impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>)`. I consider it easier to read this way, especially when there's control flow involved. r? nnethercote though feel free to reassign
2 parents 1d54949 + 252d99a commit 58353fa

38 files changed

+53
-153
lines changed
 

‎compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
578578
hir_id,
579579
no_sanitize_span,
580580
"`no_sanitize` will have no effect after inlining",
581-
|lint| lint.span_note(inline_span, "inlining requested here"),
581+
|lint| {
582+
lint.span_note(inline_span, "inlining requested here");
583+
},
582584
)
583585
}
584586
}

‎compiler/rustc_hir_analysis/src/astconv/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
661661
args.args[0].hir_id(),
662662
multispan,
663663
msg,
664-
|lint| lint,
664+
|_| {},
665665
);
666666
}
667667

‎compiler/rustc_hir_analysis/src/astconv/lint.rs

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
122122
Applicability::MachineApplicable,
123123
);
124124
self.maybe_lint_blanket_trait_impl(self_ty, lint);
125-
lint
126125
},
127126
);
128127
}

‎compiler/rustc_hir_analysis/src/astconv/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14341434
format!("<{} as {}>::{}", qself_ty, tcx.item_name(trait_did), assoc_ident),
14351435
Applicability::MachineApplicable,
14361436
);
1437-
1438-
lint
14391437
},
14401438
);
14411439
}

‎compiler/rustc_hir_analysis/src/check/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
5151
hir_id,
5252
span,
5353
"use of calling convention not supported on this target",
54-
|lint| lint,
54+
|_| {},
5555
);
5656
}
5757
}
@@ -190,7 +190,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
190190
"static of uninhabited type",
191191
|lint| {
192192
lint
193-
.note("uninhabited statics cannot be initialized, and any access would be an immediate error")
193+
.note("uninhabited statics cannot be initialized, and any access would be an immediate error");
194194
},
195195
);
196196
}
@@ -1093,7 +1093,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
10931093
"this {descr} contains `{field_ty}`, which {note}, \
10941094
and makes it not a breaking change to become \
10951095
non-zero-sized in the future."
1096-
))
1096+
));
10971097
},
10981098
)
10991099
} else {

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ fn emit_implied_wf_lint<'tcx>(
574574
Applicability::MaybeIncorrect,
575575
);
576576
}
577-
lint
578577
},
579578
);
580579
}

‎compiler/rustc_hir_analysis/src/check/intrinsicck.rs

-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
276276
lint.help(format!(
277277
"or use `{{{idx}:{default_modifier}}}` to keep the default formatting of `{default_result}`",
278278
));
279-
lint
280279
},
281280
);
282281
}

‎compiler/rustc_hir_analysis/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
4545
item.hir_id(),
4646
path.span,
4747
msg,
48-
|lint| lint,
48+
|_| {},
4949
);
5050
}
5151
}

‎compiler/rustc_hir_analysis/src/coherence/orphan.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ fn lint_auto_trait_impl<'tcx>(
522522
format!(
523523
"try using the same sequence of generic parameters as the {self_descr} definition",
524524
),
525-
)
525+
);
526526
},
527527
);
528528
}

‎compiler/rustc_hir_analysis/src/collect/generics_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
279279
param.hir_id,
280280
param.span,
281281
TYPE_DEFAULT_NOT_ALLOWED,
282-
|lint| lint,
282+
|_| {},
283283
);
284284
}
285285
Defaults::Deny => {

‎compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
925925
"you can use the `'static` lifetime directly, in place of `{}`",
926926
lifetime.ident,
927927
);
928-
lint.help(help)
928+
lint.help(help);
929929
},
930930
);
931931
}

‎compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7272
orig_span,
7373
custom_note
7474
.unwrap_or("any code following this expression is unreachable"),
75-
)
75+
);
7676
},
7777
)
7878
}

‎compiler/rustc_hir_typeck/src/method/prelude2021.rs

-6
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
122122
format!("disambiguate the method call with `({self_adjusted})`",),
123123
);
124124
}
125-
126-
lint
127125
},
128126
);
129127
} else {
@@ -187,8 +185,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
187185
),
188186
);
189187
}
190-
191-
lint
192188
},
193189
);
194190
}
@@ -307,8 +303,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
307303
format!("<{} as {}>::{}", self_ty_name, trait_name, method_name.name,),
308304
Applicability::MachineApplicable,
309305
);
310-
311-
lint
312306
},
313307
);
314308
}

‎compiler/rustc_hir_typeck/src/method/probe.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
445445
scope_expr_id,
446446
span,
447447
"type annotations needed",
448-
|lint| lint,
448+
|_| {},
449449
);
450450
}
451451
} else {
@@ -1427,8 +1427,6 @@ impl<'tcx> Pick<'tcx> {
14271427
));
14281428
}
14291429
}
1430-
1431-
lint
14321430
},
14331431
);
14341432
}

‎compiler/rustc_hir_typeck/src/pat.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1849,8 +1849,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18491849
lint.note(format!(
18501850
"the pattern is of type `{ty}` and the `non_exhaustive_omitted_patterns` attribute was found",
18511851
));
1852-
1853-
lint
18541852
});
18551853
}
18561854

‎compiler/rustc_hir_typeck/src/upvar.rs

-2
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
912912
Applicability::HasPlaceholders
913913
);
914914
}
915-
916-
lint
917915
},
918916
);
919917
}

‎compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28002800
NAMED_ASM_LABELS,
28012801
Some(target_spans),
28022802
fluent::lint_builtin_asm_labels,
2803-
|lint| lint,
2803+
|_| {},
28042804
BuiltinLintDiagnostics::NamedAsmLabel(
28052805
"only local labels of the form `<number>:` should be used in inline asm"
28062806
.to_string(),

‎compiler/rustc_lint/src/context.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,14 @@ pub trait LintContext {
520520
/// Emit a lint at the appropriate level, with an optional associated span and an existing
521521
/// diagnostic.
522522
///
523-
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed
524-
/// explanation.
525-
///
526523
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
527524
#[rustc_lint_diagnostics]
528525
fn lookup_with_diagnostics(
529526
&self,
530527
lint: &'static Lint,
531528
span: Option<impl Into<MultiSpan>>,
532529
msg: impl Into<DiagnosticMessage>,
533-
decorate: impl for<'a, 'b> FnOnce(
534-
&'b mut DiagnosticBuilder<'a, ()>,
535-
) -> &'b mut DiagnosticBuilder<'a, ()>,
530+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
536531
diagnostic: BuiltinLintDiagnostics,
537532
) {
538533
// We first generate a blank diagnostic.
@@ -986,18 +981,14 @@ pub trait LintContext {
986981
// set the span in their `decorate` function (preferably using set_span).
987982
/// Emit a lint at the appropriate level, with an optional associated span.
988983
///
989-
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
990-
///
991984
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
992985
#[rustc_lint_diagnostics]
993986
fn lookup<S: Into<MultiSpan>>(
994987
&self,
995988
lint: &'static Lint,
996989
span: Option<S>,
997990
msg: impl Into<DiagnosticMessage>,
998-
decorate: impl for<'a, 'b> FnOnce(
999-
&'b mut DiagnosticBuilder<'a, ()>,
1000-
) -> &'b mut DiagnosticBuilder<'a, ()>,
991+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
1001992
);
1002993

1003994
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
@@ -1008,23 +999,21 @@ pub trait LintContext {
1008999
span: S,
10091000
decorator: impl for<'a> DecorateLint<'a, ()>,
10101001
) {
1011-
self.lookup(lint, Some(span), decorator.msg(), |diag| decorator.decorate_lint(diag));
1002+
self.lookup(lint, Some(span), decorator.msg(), |diag| {
1003+
decorator.decorate_lint(diag);
1004+
});
10121005
}
10131006

10141007
/// Emit a lint at the appropriate level, with an associated span.
10151008
///
1016-
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
1017-
///
10181009
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
10191010
#[rustc_lint_diagnostics]
10201011
fn struct_span_lint<S: Into<MultiSpan>>(
10211012
&self,
10221013
lint: &'static Lint,
10231014
span: S,
10241015
msg: impl Into<DiagnosticMessage>,
1025-
decorate: impl for<'a, 'b> FnOnce(
1026-
&'b mut DiagnosticBuilder<'a, ()>,
1027-
) -> &'b mut DiagnosticBuilder<'a, ()>,
1016+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
10281017
) {
10291018
self.lookup(lint, Some(span), msg, decorate);
10301019
}
@@ -1033,23 +1022,19 @@ pub trait LintContext {
10331022
/// generated by `#[derive(LintDiagnostic)]`).
10341023
fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> DecorateLint<'a, ()>) {
10351024
self.lookup(lint, None as Option<Span>, decorator.msg(), |diag| {
1036-
decorator.decorate_lint(diag)
1025+
decorator.decorate_lint(diag);
10371026
});
10381027
}
10391028

10401029
/// Emit a lint at the appropriate level, with no associated span.
10411030
///
1042-
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
1043-
///
10441031
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
10451032
#[rustc_lint_diagnostics]
10461033
fn lint(
10471034
&self,
10481035
lint: &'static Lint,
10491036
msg: impl Into<DiagnosticMessage>,
1050-
decorate: impl for<'a, 'b> FnOnce(
1051-
&'b mut DiagnosticBuilder<'a, ()>,
1052-
) -> &'b mut DiagnosticBuilder<'a, ()>,
1037+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
10531038
) {
10541039
self.lookup(lint, None as Option<Span>, msg, decorate);
10551040
}
@@ -1113,9 +1098,7 @@ impl<'tcx> LintContext for LateContext<'tcx> {
11131098
lint: &'static Lint,
11141099
span: Option<S>,
11151100
msg: impl Into<DiagnosticMessage>,
1116-
decorate: impl for<'a, 'b> FnOnce(
1117-
&'b mut DiagnosticBuilder<'a, ()>,
1118-
) -> &'b mut DiagnosticBuilder<'a, ()>,
1101+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
11191102
) {
11201103
let hir_id = self.last_node_with_lint_attrs;
11211104

@@ -1142,9 +1125,7 @@ impl LintContext for EarlyContext<'_> {
11421125
lint: &'static Lint,
11431126
span: Option<S>,
11441127
msg: impl Into<DiagnosticMessage>,
1145-
decorate: impl for<'a, 'b> FnOnce(
1146-
&'b mut DiagnosticBuilder<'a, ()>,
1147-
) -> &'b mut DiagnosticBuilder<'a, ()>,
1128+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
11481129
) {
11491130
self.builder.struct_lint(lint, span.map(|s| s.into()), msg, decorate)
11501131
}

‎compiler/rustc_lint/src/early.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
4545
fn inlined_check_id(&mut self, id: ast::NodeId) {
4646
for early_lint in self.context.buffered.take(id) {
4747
let BufferedEarlyLint { span, msg, node_id: _, lint_id, diagnostic } = early_lint;
48-
self.context.lookup_with_diagnostics(
49-
lint_id.lint,
50-
Some(span),
51-
msg,
52-
|lint| lint,
53-
diagnostic,
54-
);
48+
self.context.lookup_with_diagnostics(lint_id.lint, Some(span), msg, |_| {}, diagnostic);
5549
}
5650
}
5751

‎compiler/rustc_lint/src/levels.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10771077
GateIssue::Language,
10781078
lint_from_cli,
10791079
);
1080-
lint
10811080
},
10821081
);
10831082
return false;
@@ -1094,8 +1093,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10941093
/// Used to emit a lint-related diagnostic based on the current state of
10951094
/// this lint context.
10961095
///
1097-
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
1098-
///
10991096
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
11001097
#[rustc_lint_diagnostics]
11011098
#[track_caller]
@@ -1104,9 +1101,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
11041101
lint: &'static Lint,
11051102
span: Option<MultiSpan>,
11061103
msg: impl Into<DiagnosticMessage>,
1107-
decorate: impl for<'a, 'b> FnOnce(
1108-
&'b mut DiagnosticBuilder<'a, ()>,
1109-
) -> &'b mut DiagnosticBuilder<'a, ()>,
1104+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
11101105
) {
11111106
let (level, src) = self.lint_level(lint);
11121107
struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
@@ -1121,15 +1116,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
11211116
) {
11221117
let (level, src) = self.lint_level(lint);
11231118
struct_lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| {
1124-
decorate.decorate_lint(lint)
1119+
decorate.decorate_lint(lint);
11251120
});
11261121
}
11271122

11281123
#[track_caller]
11291124
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
11301125
let (level, src) = self.lint_level(lint);
11311126
struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {
1132-
decorate.decorate_lint(lint)
1127+
decorate.decorate_lint(lint);
11331128
});
11341129
}
11351130
}

‎compiler/rustc_lint/src/non_fmt_panic.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
126126
lint.note(fluent::lint_more_info_note);
127127
if !is_arg_inside_call(arg_span, span) {
128128
// No clue where this argument is coming from.
129-
return lint;
129+
return;
130130
}
131131
if arg_macro.is_some_and(|id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) {
132132
// A case of `panic!(format!(..))`.
@@ -207,7 +207,6 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
207207
}
208208
}
209209
}
210-
lint
211210
});
212211
}
213212

‎compiler/rustc_middle/src/lint.rs

+5-31
Original file line numberDiff line numberDiff line change
@@ -253,29 +253,10 @@ pub fn explain_lint_level_source(
253253
/// - [`TyCtxt::struct_lint_node`]
254254
/// - `LintContext::lookup`
255255
///
256-
/// ## `decorate` signature
256+
/// ## `decorate`
257257
///
258-
/// The return value of `decorate` is ignored by this function. So what is the
259-
/// point of returning `&'b mut DiagnosticBuilder<'a, ()>`?
260-
///
261-
/// There are 2 reasons for this signature.
262-
///
263-
/// First of all, it prevents accidental use of `.emit()` -- it's clear that the
264-
/// builder will be later used and shouldn't be emitted right away (this is
265-
/// especially important because the old API expected you to call `.emit()` in
266-
/// the closure).
267-
///
268-
/// Second of all, it makes the most common case of adding just a single label
269-
/// /suggestion much nicer, since [`DiagnosticBuilder`] methods return
270-
/// `&mut DiagnosticBuilder`, you can just chain methods, without needed
271-
/// awkward `{ ...; }`:
272-
/// ```ignore pseudo-code
273-
/// struct_lint_level(
274-
/// ...,
275-
/// |lint| lint.span_label(sp, "lbl")
276-
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
277-
/// )
278-
/// ```
258+
/// It is not intended to call `emit`/`cancel` on the `DiagnosticBuilder` passed
259+
/// in the `decorate` callback.
279260
#[track_caller]
280261
pub fn struct_lint_level(
281262
sess: &Session,
@@ -284,9 +265,7 @@ pub fn struct_lint_level(
284265
src: LintLevelSource,
285266
span: Option<MultiSpan>,
286267
msg: impl Into<DiagnosticMessage>,
287-
decorate: impl for<'a, 'b> FnOnce(
288-
&'b mut DiagnosticBuilder<'a, ()>,
289-
) -> &'b mut DiagnosticBuilder<'a, ()>,
268+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
290269
) {
291270
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
292271
// the "real" work.
@@ -298,12 +277,7 @@ pub fn struct_lint_level(
298277
src: LintLevelSource,
299278
span: Option<MultiSpan>,
300279
msg: impl Into<DiagnosticMessage>,
301-
decorate: Box<
302-
dyn '_
303-
+ for<'a, 'b> FnOnce(
304-
&'b mut DiagnosticBuilder<'a, ()>,
305-
) -> &'b mut DiagnosticBuilder<'a, ()>,
306-
>,
280+
decorate: Box<dyn '_ + for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>)>,
307281
) {
308282
// Check for future incompatibility lints and issue a stronger warning.
309283
let future_incompatible = lint.future_incompatible;

‎compiler/rustc_middle/src/middle/stability.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ fn late_report_deprecation(
223223
let kind = tcx.def_descr(def_id);
224224
deprecation_suggestion(diag, kind, suggestion, method_span);
225225
}
226-
diag
227226
});
228227
}
229228

@@ -587,7 +586,7 @@ impl<'tcx> TyCtxt<'tcx> {
587586
unmarked: impl FnOnce(Span, DefId),
588587
) -> bool {
589588
let soft_handler = |lint, span, msg: String| {
590-
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg, |lint| lint)
589+
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg, |_| {})
591590
};
592591
let eval_result =
593592
self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable);

‎compiler/rustc_middle/src/mir/interpret/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'tcx> TyCtxt<'tcx> {
113113
self.local_def_id_to_hir_id(local_def_id),
114114
self.def_span(ct.def),
115115
"cannot use constants which depend on generic parameters in types",
116-
|err| err,
116+
|_| {},
117117
)
118118
}
119119
}

‎compiler/rustc_middle/src/ty/context.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -2030,14 +2030,12 @@ impl<'tcx> TyCtxt<'tcx> {
20302030
let msg = decorator.msg();
20312031
let (level, src) = self.lint_level_at_node(lint, hir_id);
20322032
struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg, |diag| {
2033-
decorator.decorate_lint(diag)
2033+
decorator.decorate_lint(diag);
20342034
})
20352035
}
20362036

20372037
/// Emit a lint at the appropriate level for a hir node, with an associated span.
20382038
///
2039-
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
2040-
///
20412039
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
20422040
#[rustc_lint_diagnostics]
20432041
#[track_caller]
@@ -2047,9 +2045,7 @@ impl<'tcx> TyCtxt<'tcx> {
20472045
hir_id: HirId,
20482046
span: impl Into<MultiSpan>,
20492047
msg: impl Into<DiagnosticMessage>,
2050-
decorate: impl for<'a, 'b> FnOnce(
2051-
&'b mut DiagnosticBuilder<'a, ()>,
2052-
) -> &'b mut DiagnosticBuilder<'a, ()>,
2048+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
20532049
) {
20542050
let (level, src) = self.lint_level_at_node(lint, hir_id);
20552051
struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate);
@@ -2064,13 +2060,13 @@ impl<'tcx> TyCtxt<'tcx> {
20642060
id: HirId,
20652061
decorator: impl for<'a> DecorateLint<'a, ()>,
20662062
) {
2067-
self.struct_lint_node(lint, id, decorator.msg(), |diag| decorator.decorate_lint(diag))
2063+
self.struct_lint_node(lint, id, decorator.msg(), |diag| {
2064+
decorator.decorate_lint(diag);
2065+
})
20682066
}
20692067

20702068
/// Emit a lint at the appropriate level for a hir node.
20712069
///
2072-
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
2073-
///
20742070
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
20752071
#[rustc_lint_diagnostics]
20762072
#[track_caller]
@@ -2079,9 +2075,7 @@ impl<'tcx> TyCtxt<'tcx> {
20792075
lint: &'static Lint,
20802076
id: HirId,
20812077
msg: impl Into<DiagnosticMessage>,
2082-
decorate: impl for<'a, 'b> FnOnce(
2083-
&'b mut DiagnosticBuilder<'a, ()>,
2084-
) -> &'b mut DiagnosticBuilder<'a, ()>,
2078+
decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
20852079
) {
20862080
let (level, src) = self.lint_level_at_node(lint, id);
20872081
struct_lint_level(self.sess, lint, level, src, None, msg, decorate);

‎compiler/rustc_trait_selection/src/traits/coherence.rs

-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ fn overlap<'tcx>(
273273
causing the impls to overlap",
274274
infcx.resolve_vars_if_possible(failing_obligation.predicate)
275275
));
276-
lint
277276
},
278277
);
279278
}

‎compiler/rustc_trait_selection/src/traits/object_safety.rs

-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ fn lint_object_unsafe_trait(
194194
// Only provide the help if its a local trait, otherwise it's not
195195
violation.solution().add_to(err);
196196
}
197-
err
198197
},
199198
);
200199
}

‎compiler/rustc_trait_selection/src/traits/specialize/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ fn report_conflicting_impls<'tcx>(
450450
msg,
451451
|err| {
452452
decorate(tcx, &overlap, impl_span, err);
453-
err
454453
},
455454
);
456455
}

‎src/librustdoc/core.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ pub(crate) fn run_global_ctxt(
380380
crate::lint::MISSING_CRATE_LEVEL_DOCS,
381381
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
382382
"no documentation found for this crate's top-level module",
383-
|lint| lint.help(help),
383+
|lint| {
384+
lint.help(help);
385+
},
384386
);
385387
}
386388

‎src/librustdoc/html/markdown.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -835,17 +835,15 @@ impl<'tcx> ExtraInfo<'tcx> {
835835
self.tcx.local_def_id_to_hir_id(def_id),
836836
self.sp,
837837
msg,
838-
|l| l,
838+
|_| {},
839839
);
840840
}
841841
}
842842

843843
fn error_invalid_codeblock_attr_with_help(
844844
&self,
845845
msg: impl Into<DiagnosticMessage>,
846-
f: impl for<'a, 'b> FnOnce(
847-
&'b mut DiagnosticBuilder<'a, ()>,
848-
) -> &'b mut DiagnosticBuilder<'a, ()>,
846+
f: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>),
849847
) {
850848
if let Some(def_id) = self.def_id.as_local() {
851849
self.tcx.struct_span_lint_hir(
@@ -1296,7 +1294,7 @@ impl LangString {
12961294
lint.help(format!(
12971295
"there is an attribute with a similar name: `edition{}`",
12981296
&x[4..],
1299-
))
1297+
));
13001298
},
13011299
);
13021300
}
@@ -1350,7 +1348,7 @@ impl LangString {
13501348
lint.help(format!(
13511349
"there is an attribute with a similar name: `{flag}`"
13521350
))
1353-
.help(help)
1351+
.help(help);
13541352
},
13551353
);
13561354
}

‎src/librustdoc/passes/check_doc_test_visibility.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item
131131
hir_id,
132132
sp,
133133
"missing code example in this documentation",
134-
|lint| lint,
134+
|_| {},
135135
);
136136
}
137137
} else if tests.found_tests > 0
@@ -142,7 +142,7 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item
142142
hir_id,
143143
item.attr_span(cx.tcx),
144144
"documentation test in private item",
145-
|lint| lint,
145+
|_| {},
146146
);
147147
}
148148
}

‎src/librustdoc/passes/collect_intra_doc_links.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1755,8 +1755,6 @@ fn report_diagnostic(
17551755
}
17561756

17571757
decorate(lint, span, link_range);
1758-
1759-
lint
17601758
});
17611759
}
17621760

‎src/librustdoc/passes/lint/bare_urls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) fn visit_item(cx: &DocContext<'_>, item: &Item) {
3131
"use an automatic link instead",
3232
format!("<{url}>"),
3333
Applicability::MachineApplicable,
34-
)
34+
);
3535
});
3636
};
3737

‎src/librustdoc/passes/lint/check_code_block_syntax.rs

-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ fn check_rust_syntax(
131131
for message in buffer.messages.iter() {
132132
lint.note(message.clone());
133133
}
134-
135-
lint
136134
});
137135
}
138136

‎src/librustdoc/passes/lint/html_tags.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
8989
if (generics_start > 0 && dox.as_bytes()[generics_start - 1] == b'<')
9090
|| (generics_end < dox.len() && dox.as_bytes()[generics_end] == b'>')
9191
{
92-
return lint;
92+
return;
9393
}
9494
// multipart form is chosen here because ``Vec<i32>`` would be confusing.
9595
lint.multipart_suggestion(
@@ -101,8 +101,6 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
101101
Applicability::MaybeIncorrect,
102102
);
103103
}
104-
105-
lint
106104
});
107105
};
108106

‎src/librustdoc/passes/lint/redundant_explicit_links.rs

-4
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ fn check_inline_or_reference_unknown_redundancy(
181181
.span_label(display_span, "because label contains path that resolves to same destination")
182182
.note("when a link's destination is not specified,\nthe label is used to resolve intra-doc links")
183183
.span_suggestion_with_style(link_span, "remove explicit link target", format!("[{}]", link_data.display_link), Applicability::MaybeIncorrect, SuggestionStyle::ShowAlways);
184-
185-
lint
186184
});
187185
}
188186

@@ -234,8 +232,6 @@ fn check_reference_redundancy(
234232
.span_note(def_span, "referenced explicit link target defined here")
235233
.note("when a link's destination is not specified,\nthe label is used to resolve intra-doc links")
236234
.span_suggestion_with_style(link_span, "remove explicit link target", format!("[{}]", link_data.display_link), Applicability::MaybeIncorrect, SuggestionStyle::ShowAlways);
237-
238-
lint
239235
});
240236
}
241237

‎src/librustdoc/passes/lint/unescaped_backticks.rs

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
111111
}
112112

113113
suggest_insertion(cx, item, &dox, lint, backtick_index, '\\', "if you meant to use a literal backtick, escape it");
114-
115-
lint
116114
});
117115
}
118116
Event::Code(_) => {

‎src/tools/clippy/clippy_utils/src/diagnostics.rs

-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<Mult
4949
#[expect(clippy::disallowed_methods)]
5050
cx.struct_span_lint(lint, sp, msg.to_string(), |diag| {
5151
docs_link(diag, lint);
52-
diag
5352
});
5453
}
5554

@@ -90,7 +89,6 @@ pub fn span_lint_and_help<T: LintContext>(
9089
diag.help(help.to_string());
9190
}
9291
docs_link(diag, lint);
93-
diag
9492
});
9593
}
9694

@@ -134,7 +132,6 @@ pub fn span_lint_and_note<T: LintContext>(
134132
diag.note(note);
135133
}
136134
docs_link(diag, lint);
137-
diag
138135
});
139136
}
140137

@@ -152,15 +149,13 @@ where
152149
cx.struct_span_lint(lint, sp, msg.to_string(), |diag| {
153150
f(diag);
154151
docs_link(diag, lint);
155-
diag
156152
});
157153
}
158154

159155
pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
160156
#[expect(clippy::disallowed_methods)]
161157
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| {
162158
docs_link(diag, lint);
163-
diag
164159
});
165160
}
166161

@@ -176,7 +171,6 @@ pub fn span_lint_hir_and_then(
176171
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| {
177172
f(diag);
178173
docs_link(diag, lint);
179-
diag
180174
});
181175
}
182176

0 commit comments

Comments
 (0)
Please sign in to comment.