@@ -9,8 +9,8 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
99use rustc_data_structures:: sync:: { AppendOnlyVec , Lock , Lrc } ;
1010use rustc_errors:: emitter:: { stderr_destination, HumanEmitter , SilentEmitter } ;
1111use rustc_errors:: {
12- fallback_fluent_bundle, ColorConfig , Diag , DiagCtxt , DiagCtxtHandle , DiagMessage ,
13- EmissionGuarantee , MultiSpan , StashKey ,
12+ fallback_fluent_bundle, ColorConfig , Diag , DiagCtxt , DiagCtxtHandle , DiagMessage , MultiSpan ,
13+ StashKey ,
1414} ;
1515use rustc_feature:: { find_feature_issue, GateIssue , UnstableFeatures } ;
1616use rustc_span:: edition:: Edition ;
@@ -111,9 +111,9 @@ pub fn feature_err_issue(
111111 }
112112 }
113113
114- let mut err = sess . dcx ( ) . create_err ( FeatureGateError { span , explain : explain . into ( ) } ) ;
115- add_feature_diagnostics_for_issue ( & mut err , sess , feature , issue , false , None ) ;
116- err
114+ let subdiag = get_feature_diagnostics_for_issue ( sess , feature , issue , false , None ) ;
115+
116+ sess . dcx ( ) . create_err ( FeatureGateError { span , explain : explain . into ( ) , subdiag } )
117117}
118118
119119/// Construct a future incompatibility diagnostic for a feature gate.
@@ -141,7 +141,7 @@ pub fn feature_warn_issue(
141141 explain : & ' static str ,
142142) {
143143 let mut err = sess. dcx ( ) . struct_span_warn ( span, explain) ;
144- add_feature_diagnostics_for_issue ( & mut err, sess, feature, issue, false , None ) ;
144+ err. subdiagnostic ( get_feature_diagnostics_for_issue ( sess, feature, issue, false , None ) ) ;
145145
146146 // Decorate this as a future-incompatibility lint as in rustc_middle::lint::lint_level
147147 let lint = UNSTABLE_SYNTAX_PRE_EXPANSION ;
@@ -154,29 +154,23 @@ pub fn feature_warn_issue(
154154 err. stash ( span, StashKey :: EarlySyntaxWarning ) ;
155155}
156156
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 ) ;
157+ /// Returns the subdiagnostics for a feature gate error.
158+ pub fn get_feature_diagnostics ( sess : & Session , feature : Symbol ) -> FeatureGateSubdiagnostic {
159+ get_feature_diagnostics_for_issue ( sess, feature, GateIssue :: Language , false , None )
164160}
165161
166- /// Adds the diagnostics for a feature to an existing error.
162+ /// Returns the subdiagnostics for a feature gate error.
167163///
168164/// This variant allows you to control whether it is a library or language feature.
169165/// Almost always, you want to use this for a language feature. If so, prefer
170- /// `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 > ,
166+ /// [`get_feature_diagnostics`].
167+ pub fn get_feature_diagnostics_for_issue (
174168 sess : & Session ,
175169 feature : Symbol ,
176170 issue : GateIssue ,
177171 feature_from_cli : bool ,
178172 inject_span : Option < Span > ,
179- ) {
173+ ) -> FeatureGateSubdiagnostic {
180174 let issue = find_feature_issue ( feature, issue) . map ( |n| FeatureDiagnosticForIssue { n } ) ;
181175
182176 // #23973: do not suggest `#![feature(...)]` if we are in beta/stable
@@ -202,7 +196,7 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
202196 ( None , None )
203197 } ;
204198
205- err . subdiagnostic ( FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature } ) ;
199+ FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature }
206200}
207201
208202/// Info about a parsing session.
0 commit comments