@@ -4,7 +4,7 @@ use rustc_ast::token;
44use rustc_ast:: util:: literal:: LitError ;
55use rustc_errors:: {
66 codes:: * , Diag , DiagCtxt , DiagMessage , Diagnostic , EmissionGuarantee , ErrorGuaranteed , Level ,
7- MultiSpan ,
7+ MultiSpan , Subdiagnostic ,
88} ;
99use rustc_macros:: Diagnostic ;
1010use rustc_span:: { Span , Symbol } ;
@@ -24,6 +24,30 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for FeatureGateError {
2424 }
2525}
2626
27+ pub struct FeatureGateSubdiagnostic {
28+ pub ( crate ) issue : Option < FeatureDiagnosticForIssue > ,
29+ pub ( crate ) enable_feature : Option < EnableFeatureSubdiagnostic > ,
30+ pub ( crate ) upgrade_compiler : Option < SuggestUpgradeCompiler > ,
31+ }
32+
33+ impl Subdiagnostic for FeatureGateSubdiagnostic {
34+ fn add_to_diag_with < G : EmissionGuarantee , F : rustc_errors:: SubdiagMessageOp < G > > (
35+ self ,
36+ diag : & mut Diag < ' _ , G > ,
37+ f : F ,
38+ ) {
39+ if let Some ( issue) = self . issue {
40+ issue. add_to_diag_with ( diag, |diag, msg| f ( diag, msg) ) ;
41+ }
42+ if let Some ( enable_feature) = self . enable_feature {
43+ enable_feature. add_to_diag_with ( diag, |diag, msg| f ( diag, msg) ) ;
44+ }
45+ if let Some ( upgrade_compiler) = self . upgrade_compiler {
46+ upgrade_compiler. add_to_diag_with ( diag, |diag, msg| f ( diag, msg) ) ;
47+ }
48+ }
49+ }
50+
2751#[ derive( Subdiagnostic ) ]
2852#[ note( session_feature_diagnostic_for_issue) ]
2953pub ( crate ) struct FeatureDiagnosticForIssue {
@@ -49,27 +73,21 @@ impl SuggestUpgradeCompiler {
4973}
5074
5175#[ derive( Subdiagnostic ) ]
52- #[ help( session_feature_diagnostic_help) ]
53- pub ( crate ) struct FeatureDiagnosticHelp {
54- pub ( crate ) feature : Symbol ,
55- }
56-
57- #[ derive( Subdiagnostic ) ]
58- #[ suggestion(
59- session_feature_diagnostic_suggestion,
60- applicability = "maybe-incorrect" ,
61- code = "#![feature({feature})]\n "
62- ) ]
63- pub struct FeatureDiagnosticSuggestion {
64- pub feature : Symbol ,
65- #[ primary_span]
66- pub span : Span ,
67- }
68-
69- #[ derive( Subdiagnostic ) ]
70- #[ help( session_cli_feature_diagnostic_help) ]
71- pub ( crate ) struct CliFeatureDiagnosticHelp {
72- pub ( crate ) feature : Symbol ,
76+ pub ( crate ) enum EnableFeatureSubdiagnostic {
77+ #[ help( session_feature_diagnostic_help) ]
78+ AddAttrHelp { feature : Symbol } ,
79+ #[ suggestion(
80+ session_feature_diagnostic_suggestion,
81+ applicability = "maybe-incorrect" ,
82+ code = "#![feature({feature})]\n "
83+ ) ]
84+ AddAttrSuggestion {
85+ feature : Symbol ,
86+ #[ primary_span]
87+ span : Span ,
88+ } ,
89+ #[ help( session_cli_feature_diagnostic_help) ]
90+ AddCliHelp { feature : Symbol } ,
7391}
7492
7593#[ derive( Diagnostic ) ]
0 commit comments