@@ -15,8 +15,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
15
15
use rustc_data_structures:: sync:: { AppendOnlyVec , Lock , Lrc } ;
16
16
use rustc_errors:: emitter:: { stderr_destination, HumanEmitter , SilentEmitter } ;
17
17
use rustc_errors:: {
18
- fallback_fluent_bundle, ColorConfig , Diag , DiagCtxt , DiagMessage , EmissionGuarantee , MultiSpan ,
19
- StashKey ,
18
+ fallback_fluent_bundle, ColorConfig , Diag , DiagCtxt , DiagMessage , MultiSpan , StashKey ,
20
19
} ;
21
20
use rustc_feature:: { find_feature_issue, GateIssue , UnstableFeatures } ;
22
21
use rustc_span:: edition:: Edition ;
@@ -111,9 +110,9 @@ pub fn feature_err_issue(
111
110
}
112
111
}
113
112
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 } )
117
116
}
118
117
119
118
/// Construct a future incompatibility diagnostic for a feature gate.
@@ -141,7 +140,10 @@ pub fn feature_warn_issue(
141
140
explain : & ' static str ,
142
141
) {
143
142
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
+ ) ;
145
147
146
148
// Decorate this as a future-incompatibility lint as in rustc_middle::lint::lint_level
147
149
let lint = UNSTABLE_SYNTAX_PRE_EXPANSION ;
@@ -154,29 +156,23 @@ pub fn feature_warn_issue(
154
156
err. stash ( span, StashKey :: EarlySyntaxWarning ) ;
155
157
}
156
158
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 )
164
162
}
165
163
166
- /// Adds the diagnostics for a feature to an existing error.
164
+ /// Returns the subdiagnostics for a feature gate error.
167
165
///
168
166
/// This variant allows you to control whether it is a library or language feature.
169
167
/// Almost always, you want to use this for a language feature. If so, prefer
170
168
/// `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 (
174
170
sess : & Session ,
175
171
feature : Symbol ,
176
172
issue : GateIssue ,
177
173
feature_from_cli : bool ,
178
174
inject_span : Option < Span > ,
179
- ) {
175
+ ) -> FeatureGateSubdiagnostic {
180
176
let issue = find_feature_issue ( feature, issue) . map ( |n| FeatureDiagnosticForIssue { n } ) ;
181
177
182
178
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
@@ -200,9 +196,7 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
200
196
( None , None )
201
197
} ;
202
198
203
- let subdiagnostic = FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature } ;
204
-
205
- err. subdiagnostic ( sess. dcx ( ) , subdiagnostic) ;
199
+ FeatureGateSubdiagnostic { issue, upgrade_compiler, enable_feature }
206
200
}
207
201
208
202
/// Info about a parsing session.
0 commit comments