diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-03-11 09:06:08 +1100 | 
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-03-11 16:42:10 +1100 | 
| commit | 47b4b8e8c5189228015ee645dfc65e9b73d2c19c (patch) | |
| tree | 530a09d1e085323071f9ed5c75a8fe8255805a03 /compiler/rustc_lint/src/internal.rs | |
| parent | c69fda7dc664e62f8920a02a4e55d6207b212c24 (diff) | |
| download | rust-47b4b8e8c5189228015ee645dfc65e9b73d2c19c.tar.gz rust-47b4b8e8c5189228015ee645dfc65e9b73d2c19c.zip | |
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.
Diffstat (limited to 'compiler/rustc_lint/src/internal.rs')
| -rw-r--r-- | compiler/rustc_lint/src/internal.rs | 17 | 
1 files changed, 5 insertions, 12 deletions
| diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 0872a8a2095..153d91ce28c 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -409,9 +409,8 @@ impl LateLintPass<'_> for Diagnostics { } }; - // Does the callee have a `impl Into<{D,Subd}iagMessage>` parameter? (There should be at - // most one.) - let mut impl_into_diagnostic_message_param = None; + // Does the callee have one or more `impl Into<{D,Subd}iagMessage>` parameters? + let mut impl_into_diagnostic_message_params = vec![]; let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder(); let predicates = cx.tcx.predicates_of(def_id).instantiate_identity(cx.tcx).predicates; for (i, ¶m_ty) in fn_sig.inputs().iter().enumerate() { @@ -425,20 +424,14 @@ impl LateLintPass<'_> for Diagnostics { && let ty1 = trait_ref.args.type_at(1) && is_diag_message(ty1) { - if impl_into_diagnostic_message_param.is_some() { - cx.tcx.dcx().span_bug( - span, - "can't handle multiple `impl Into<{D,Sub}iagMessage>` params", - ); - } - impl_into_diagnostic_message_param = Some((i, p.name)); + impl_into_diagnostic_message_params.push((i, p.name)); } } } } // Is the callee interesting? - if !has_attr && impl_into_diagnostic_message_param.is_none() { + if !has_attr && impl_into_diagnostic_message_params.is_empty() { return; } @@ -481,7 +474,7 @@ impl LateLintPass<'_> for Diagnostics { // Calls to methods with an `impl Into<{D,Subd}iagMessage>` parameter must be passed an arg // with type `{D,Subd}iagMessage` or `impl Into<{D,Subd}iagMessage>`. Otherwise, emit an // `UNTRANSLATABLE_DIAGNOSTIC` lint. - if let Some((param_i, param_i_p_name)) = impl_into_diagnostic_message_param { + for (param_i, param_i_p_name) in impl_into_diagnostic_message_params { // Is the arg type `{Sub,D}iagMessage`or `impl Into<{Sub,D}iagMessage>`? let arg_ty = call_tys[param_i]; let is_translatable = is_diag_message(arg_ty) | 
