Skip to content

Commit b083786

Browse files
authored
Unrolled build for rust-lang#118727
Rollup merge of rust-lang#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 a96d57b + 252d99a commit b083786

38 files changed

+53
-153
lines changed

Diff for: 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
}

Diff for: 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

Diff for: 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
}

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
15091509
format!("<{} as {}>::{}", qself_ty, tcx.item_name(trait_did), assoc_ident),
15101510
Applicability::MachineApplicable,
15111511
);
1512-
1513-
lint
15141512
},
15151513
);
15161514
}

Diff for: 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 {

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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 => {

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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

Diff for: 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
}

Diff for: 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(),

Diff for: 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
}

Diff for: 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

Diff for: 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
}

Diff for: 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

0 commit comments

Comments
 (0)