Skip to content

Commit 47b4b8e

Browse files
committed
Allow multiple impl Into<{D,Subd}iagMessage> parameters in a function.
The internal diagnostic lint currently only allows one, because that was all that occurred in practice. But rust-lang/rust-clippy/pull/12453 wants to introduce functions with more than one, and this limitation is getting in the way.
1 parent c69fda7 commit 47b4b8e

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

compiler/rustc_lint/src/internal.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,8 @@ impl LateLintPass<'_> for Diagnostics {
409409
}
410410
};
411411

412-
// Does the callee have a `impl Into<{D,Subd}iagMessage>` parameter? (There should be at
413-
// most one.)
414-
let mut impl_into_diagnostic_message_param = None;
412+
// Does the callee have one or more `impl Into<{D,Subd}iagMessage>` parameters?
413+
let mut impl_into_diagnostic_message_params = vec![];
415414
let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder();
416415
let predicates = cx.tcx.predicates_of(def_id).instantiate_identity(cx.tcx).predicates;
417416
for (i, &param_ty) in fn_sig.inputs().iter().enumerate() {
@@ -425,20 +424,14 @@ impl LateLintPass<'_> for Diagnostics {
425424
&& let ty1 = trait_ref.args.type_at(1)
426425
&& is_diag_message(ty1)
427426
{
428-
if impl_into_diagnostic_message_param.is_some() {
429-
cx.tcx.dcx().span_bug(
430-
span,
431-
"can't handle multiple `impl Into<{D,Sub}iagMessage>` params",
432-
);
433-
}
434-
impl_into_diagnostic_message_param = Some((i, p.name));
427+
impl_into_diagnostic_message_params.push((i, p.name));
435428
}
436429
}
437430
}
438431
}
439432

440433
// Is the callee interesting?
441-
if !has_attr && impl_into_diagnostic_message_param.is_none() {
434+
if !has_attr && impl_into_diagnostic_message_params.is_empty() {
442435
return;
443436
}
444437

@@ -481,7 +474,7 @@ impl LateLintPass<'_> for Diagnostics {
481474
// Calls to methods with an `impl Into<{D,Subd}iagMessage>` parameter must be passed an arg
482475
// with type `{D,Subd}iagMessage` or `impl Into<{D,Subd}iagMessage>`. Otherwise, emit an
483476
// `UNTRANSLATABLE_DIAGNOSTIC` lint.
484-
if let Some((param_i, param_i_p_name)) = impl_into_diagnostic_message_param {
477+
for (param_i, param_i_p_name) in impl_into_diagnostic_message_params {
485478
// Is the arg type `{Sub,D}iagMessage`or `impl Into<{Sub,D}iagMessage>`?
486479
let arg_ty = call_tys[param_i];
487480
let is_translatable = is_diag_message(arg_ty)

tests/ui-fulldeps/internal-lints/diagnostics.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern crate rustc_span;
1515

1616
use rustc_errors::{
1717
Diag, DiagCtxt, DiagInner, DiagMessage, Diagnostic, EmissionGuarantee, Level, LintDiagnostic,
18-
SubdiagMessageOp, Subdiagnostic,
18+
SubdiagMessageOp, SubdiagMessage, Subdiagnostic,
1919
};
2020
use rustc_macros::{Diagnostic, Subdiagnostic};
2121
use rustc_span::Span;
@@ -114,9 +114,15 @@ pub fn make_diagnostics<'a>(dcx: &'a DiagCtxt) {
114114

115115
// Check that `rustc_lint_diagnostics`-annotated functions aren't themselves linted for
116116
// `diagnostic_outside_of_impl`.
117-
118117
#[rustc_lint_diagnostics]
119118
pub fn skipped_because_of_annotation<'a>(dcx: &'a DiagCtxt) {
120119
#[allow(rustc::untranslatable_diagnostic)]
121120
let _diag = dcx.struct_err("untranslatable diagnostic"); // okay!
122121
}
122+
123+
// Check that multiple translatable params are allowed in a single function (at one point they
124+
// weren't).
125+
fn f(_x: impl Into<DiagMessage>, _y: impl Into<SubdiagMessage>) {}
126+
fn g() {
127+
f(crate::fluent_generated::no_crate_example, crate::fluent_generated::no_crate_example);
128+
}

0 commit comments

Comments
 (0)