@@ -20,8 +20,8 @@ use rustc_span::{Span, Symbol};
2020
2121use crate :: config:: { Cfg , CheckCfg } ;
2222use crate :: errors:: {
23- CliFeatureDiagnosticHelp , FeatureDiagnosticForIssue , FeatureDiagnosticHelp ,
24- FeatureDiagnosticSuggestion , FeatureGateError , SuggestUpgradeCompiler ,
23+ EnableFeatureSubdiagnostic , FeatureDiagnosticForIssue , FeatureGateError ,
24+ FeatureGateSubdiagnostic , SuggestUpgradeCompiler ,
2525} ;
2626use crate :: lint:: builtin:: UNSTABLE_SYNTAX_PRE_EXPANSION ;
2727use crate :: lint:: { BufferedEarlyLint , BuiltinLintDiag , Lint , LintId } ;
@@ -177,26 +177,32 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
177177 feature_from_cli : bool ,
178178 inject_span : Option < Span > ,
179179) {
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 } ) ;
183181
184182 // #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 }
188186 } else if let Some ( span) = inject_span {
189- err . subdiagnostic ( FeatureDiagnosticSuggestion { feature, span } ) ;
187+ EnableFeatureSubdiagnostic :: AddAttrSuggestion { feature, span }
190188 } else {
191- err . subdiagnostic ( FeatureDiagnosticHelp { feature } ) ;
192- }
189+ EnableFeatureSubdiagnostic :: AddAttrHelp { feature }
190+ } ;
193191
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 ( ) )
196194 } 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 } ) ;
200206}
201207
202208/// Info about a parsing session.
0 commit comments