@@ -20,8 +20,8 @@ use rustc_span::{Span, Symbol};
20
20
21
21
use crate :: config:: { Cfg , CheckCfg } ;
22
22
use crate :: errors:: {
23
- CliFeatureDiagnosticHelp , FeatureDiagnosticForIssue , FeatureDiagnosticHelp ,
24
- FeatureDiagnosticSuggestion , FeatureGateError , SuggestUpgradeCompiler ,
23
+ EnableFeatureSubdiagnostic , FeatureDiagnosticForIssue , FeatureGateError ,
24
+ FeatureGateSubdiagnostic , SuggestUpgradeCompiler ,
25
25
} ;
26
26
use crate :: lint:: builtin:: UNSTABLE_SYNTAX_PRE_EXPANSION ;
27
27
use crate :: lint:: { BufferedEarlyLint , BuiltinLintDiag , Lint , LintId } ;
@@ -177,26 +177,32 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
177
177
feature_from_cli : bool ,
178
178
inject_span : Option < Span > ,
179
179
) {
180
- if let Some ( n) = find_feature_issue ( feature, issue) {
181
- err. subdiagnostic ( FeatureDiagnosticForIssue { n } ) ;
182
- }
180
+ let issue = find_feature_issue ( feature, issue) . map ( |n| FeatureDiagnosticForIssue { n } ) ;
183
181
184
182
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
185
- if sess. psess . unstable_features . is_nightly_build ( ) {
186
- if feature_from_cli {
187
- err . subdiagnostic ( CliFeatureDiagnosticHelp { feature } ) ;
183
+ let ( enable_feature , upgrade_compiler ) = if sess. psess . unstable_features . is_nightly_build ( ) {
184
+ let enable_feature = if feature_from_cli {
185
+ EnableFeatureSubdiagnostic :: AddCliHelp { feature }
188
186
} else if let Some ( span) = inject_span {
189
- err . subdiagnostic ( FeatureDiagnosticSuggestion { feature, span } ) ;
187
+ EnableFeatureSubdiagnostic :: AddAttrSuggestion { feature, span }
190
188
} else {
191
- err . subdiagnostic ( FeatureDiagnosticHelp { feature } ) ;
192
- }
189
+ EnableFeatureSubdiagnostic :: AddAttrHelp { feature }
190
+ } ;
193
191
194
- if sess. opts . unstable_opts . ui_testing {
195
- err . subdiagnostic ( SuggestUpgradeCompiler :: ui_testing ( ) ) ;
192
+ let upgrade_compiler = if sess. opts . unstable_opts . ui_testing {
193
+ Some ( SuggestUpgradeCompiler :: ui_testing ( ) )
196
194
} else if let Some ( suggestion) = SuggestUpgradeCompiler :: new ( ) {
197
- err. subdiagnostic ( suggestion) ;
198
- }
199
- }
195
+ Some ( suggestion)
196
+ } else {
197
+ None
198
+ } ;
199
+
200
+ ( Some ( enable_feature) , upgrade_compiler)
201
+ } else {
202
+ ( None , None )
203
+ } ;
204
+
205
+ err. subdiagnostic ( FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature } ) ;
200
206
}
201
207
202
208
/// Info about a parsing session.
0 commit comments