diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-04-23 17:25:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 17:25:17 +0200 |
| commit | 6e423e1651e807ee3a07aa2f188fefadcb464071 (patch) | |
| tree | a47844ca41645b465d8bad4f5efc6c237be1d411 /compiler/rustc_errors/src/lib.rs | |
| parent | e15d6f9d8580b5f54376c2c48bd5ecf8ba0b5ce7 (diff) | |
| parent | 6974e9cf7012b0f3e2a58a8accde23007274f9a9 (diff) | |
| download | rust-6e423e1651e807ee3a07aa2f188fefadcb464071.tar.gz rust-6e423e1651e807ee3a07aa2f188fefadcb464071.zip | |
Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwco
Allow nesting subdiagnostics in #[derive(Subdiagnostic)]
Diffstat (limited to 'compiler/rustc_errors/src/lib.rs')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index e3363e89594..b3c1c6c8515 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -40,8 +40,8 @@ pub use diagnostic::{ SubdiagMessageOp, Subdiagnostic, }; pub use diagnostic_impls::{ - DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime, - SingleLabelManySpans, + DiagArgFromDisplay, DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter, + IndicateAnonymousLifetime, SingleLabelManySpans, }; pub use emitter::ColorConfig; pub use rustc_error_messages::{ @@ -1911,27 +1911,24 @@ impl Level { } // FIXME(eddyb) this doesn't belong here AFAICT, should be moved to callsite. -pub fn add_elided_lifetime_in_path_suggestion<G: EmissionGuarantee>( +pub fn elided_lifetime_in_path_suggestion( source_map: &SourceMap, - diag: &mut Diag<'_, G>, n: usize, path_span: Span, incl_angl_brckt: bool, insertion_span: Span, -) { - diag.subdiagnostic(diag.dcx, ExpectedLifetimeParameter { span: path_span, count: n }); - if !source_map.is_span_accessible(insertion_span) { - // Do not try to suggest anything if generated by a proc-macro. - return; - } - let anon_lts = vec!["'_"; n].join(", "); - let suggestion = - if incl_angl_brckt { format!("<{anon_lts}>") } else { format!("{anon_lts}, ") }; - - diag.subdiagnostic( - diag.dcx, - IndicateAnonymousLifetime { span: insertion_span.shrink_to_hi(), count: n, suggestion }, - ); +) -> ElidedLifetimeInPathSubdiag { + let expected = ExpectedLifetimeParameter { span: path_span, count: n }; + // Do not try to suggest anything if generated by a proc-macro. + let indicate = source_map.is_span_accessible(insertion_span).then(|| { + let anon_lts = vec!["'_"; n].join(", "); + let suggestion = + if incl_angl_brckt { format!("<{anon_lts}>") } else { format!("{anon_lts}, ") }; + + IndicateAnonymousLifetime { span: insertion_span.shrink_to_hi(), count: n, suggestion } + }); + + ElidedLifetimeInPathSubdiag { expected, indicate } } pub fn report_ambiguity_error<'a, G: EmissionGuarantee>( |
