@@ -15,8 +15,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
1515use rustc_data_structures:: sync:: { AppendOnlyVec , Lock , Lrc } ;
1616use rustc_errors:: emitter:: { stderr_destination, HumanEmitter , SilentEmitter } ;
1717use rustc_errors:: {
18- fallback_fluent_bundle, ColorConfig , Diag , DiagCtxt , DiagMessage , EmissionGuarantee , MultiSpan ,
19- StashKey ,
18+ fallback_fluent_bundle, ColorConfig , Diag , DiagCtxt , DiagMessage , MultiSpan , StashKey ,
2019} ;
2120use rustc_feature:: { find_feature_issue, GateIssue , UnstableFeatures } ;
2221use rustc_span:: edition:: Edition ;
@@ -111,9 +110,9 @@ pub fn feature_err_issue(
111110 }
112111 }
113112
114- let mut err = sess . psess . dcx . create_err ( FeatureGateError { span , explain : explain . into ( ) } ) ;
115- add_feature_diagnostics_for_issue ( & mut err , sess , feature , issue , false , None ) ;
116- err
113+ let subdiag = get_feature_diagnostics_for_issue ( sess , feature , issue , false , None ) ;
114+
115+ sess . psess . dcx . create_err ( FeatureGateError { span , explain : explain . into ( ) , subdiag } )
117116}
118117
119118/// Construct a future incompatibility diagnostic for a feature gate.
@@ -141,7 +140,10 @@ pub fn feature_warn_issue(
141140 explain : & ' static str ,
142141) {
143142 let mut err = sess. psess . dcx . struct_span_warn ( span, explain) ;
144- add_feature_diagnostics_for_issue ( & mut err, sess, feature, issue, false , None ) ;
143+ err. subdiagnostic (
144+ sess. dcx ( ) ,
145+ get_feature_diagnostics_for_issue ( sess, feature, issue, false , None ) ,
146+ ) ;
145147
146148 // Decorate this as a future-incompatibility lint as in rustc_middle::lint::lint_level
147149 let lint = UNSTABLE_SYNTAX_PRE_EXPANSION ;
@@ -154,29 +156,23 @@ pub fn feature_warn_issue(
154156 err. stash ( span, StashKey :: EarlySyntaxWarning ) ;
155157}
156158
157- /// Adds the diagnostics for a feature to an existing error.
158- pub fn add_feature_diagnostics < G : EmissionGuarantee > (
159- err : & mut Diag < ' _ , G > ,
160- sess : & Session ,
161- feature : Symbol ,
162- ) {
163- add_feature_diagnostics_for_issue ( err, sess, feature, GateIssue :: Language , false , None ) ;
159+ /// Returns the subdiagnostics for a feature gate error.
160+ pub fn get_feature_diagnostics ( sess : & Session , feature : Symbol ) -> FeatureGateSubdiagnostic {
161+ get_feature_diagnostics_for_issue ( sess, feature, GateIssue :: Language , false , None )
164162}
165163
166- /// Adds the diagnostics for a feature to an existing error.
164+ /// Returns the subdiagnostics for a feature gate error.
167165///
168166/// This variant allows you to control whether it is a library or language feature.
169167/// Almost always, you want to use this for a language feature. If so, prefer
170168/// `add_feature_diagnostics`.
171- #[ allow( rustc:: diagnostic_outside_of_impl) ] // FIXME
172- pub fn add_feature_diagnostics_for_issue < G : EmissionGuarantee > (
173- err : & mut Diag < ' _ , G > ,
169+ pub fn get_feature_diagnostics_for_issue (
174170 sess : & Session ,
175171 feature : Symbol ,
176172 issue : GateIssue ,
177173 feature_from_cli : bool ,
178174 inject_span : Option < Span > ,
179- ) {
175+ ) -> FeatureGateSubdiagnostic {
180176 let issue = find_feature_issue ( feature, issue) . map ( |n| FeatureDiagnosticForIssue { n } ) ;
181177
182178 // #23973: do not suggest `#![feature(...)]` if we are in beta/stable
@@ -200,9 +196,7 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
200196 ( None , None )
201197 } ;
202198
203- let subdiagnostic = FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature } ;
204-
205- err. subdiagnostic ( sess. dcx ( ) , subdiagnostic) ;
199+ FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature }
206200}
207201
208202/// Info about a parsing session.
0 commit comments