@@ -4,7 +4,7 @@ use rustc_ast::token;
4
4
use rustc_ast:: util:: literal:: LitError ;
5
5
use rustc_errors:: {
6
6
codes:: * , Diag , DiagCtxt , DiagMessage , Diagnostic , EmissionGuarantee , ErrorGuaranteed , Level ,
7
- MultiSpan ,
7
+ MultiSpan , Subdiagnostic ,
8
8
} ;
9
9
use rustc_macros:: Diagnostic ;
10
10
use rustc_span:: { Span , Symbol } ;
@@ -24,6 +24,30 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for FeatureGateError {
24
24
}
25
25
}
26
26
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
+
27
51
#[ derive( Subdiagnostic ) ]
28
52
#[ note( session_feature_diagnostic_for_issue) ]
29
53
pub ( crate ) struct FeatureDiagnosticForIssue {
@@ -49,27 +73,21 @@ impl SuggestUpgradeCompiler {
49
73
}
50
74
51
75
#[ 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 } ,
73
91
}
74
92
75
93
#[ derive( Diagnostic ) ]
0 commit comments