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