2
2
//! It also serves as an input to the parser itself.
3
3
4
4
use crate :: config:: CheckCfg ;
5
+ use crate :: errors:: { FeatureDiagnosticForIssue , FeatureDiagnosticHelp , FeatureGateError } ;
5
6
use crate :: lint:: {
6
7
builtin:: UNSTABLE_SYNTAX_PRE_EXPANSION , BufferedEarlyLint , BuiltinLintDiagnostics , Lint , LintId ,
7
8
} ;
@@ -11,7 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
11
12
use rustc_data_structures:: sync:: { Lock , Lrc } ;
12
13
use rustc_errors:: { emitter:: SilentEmitter , ColorConfig , Handler } ;
13
14
use rustc_errors:: {
14
- error_code , fallback_fluent_bundle, Applicability , Diagnostic , DiagnosticBuilder , DiagnosticId ,
15
+ fallback_fluent_bundle, Applicability , Diagnostic , DiagnosticBuilder , DiagnosticId ,
15
16
DiagnosticMessage , EmissionGuarantee , ErrorGuaranteed , MultiSpan , StashKey ,
16
17
} ;
17
18
use rustc_feature:: { find_feature_issue, GateIssue , UnstableFeatures } ;
@@ -112,7 +113,7 @@ pub fn feature_err_issue<'a>(
112
113
. map ( |err| err. cancel ( ) ) ;
113
114
}
114
115
115
- let mut err = sess. span_diagnostic . struct_span_err_with_code ( span, explain, error_code ! ( E0658 ) ) ;
116
+ let mut err = sess. create_err ( FeatureGateError { span, explain } ) ;
116
117
add_feature_diagnostics_for_issue ( & mut err, sess, feature, issue) ;
117
118
err
118
119
}
@@ -130,6 +131,8 @@ pub fn feature_warn<'a>(sess: &'a ParseSess, feature: Symbol, span: Span, explai
130
131
///
131
132
/// This variant allows you to control whether it is a library or language feature.
132
133
/// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`.
134
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
135
+ #[ allow( rustc:: untranslatable_diagnostic) ]
133
136
pub fn feature_warn_issue < ' a > (
134
137
sess : & ' a ParseSess ,
135
138
feature : Symbol ,
@@ -172,14 +175,12 @@ pub fn add_feature_diagnostics_for_issue<'a>(
172
175
issue : GateIssue ,
173
176
) {
174
177
if let Some ( n) = find_feature_issue ( feature, issue) {
175
- err. note ( & format ! (
176
- "see issue #{n} <https://github.com/rust-lang/rust/issues/{n}> for more information"
177
- ) ) ;
178
+ err. subdiagnostic ( FeatureDiagnosticForIssue { n } ) ;
178
179
}
179
180
180
181
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
181
182
if sess. unstable_features . is_nightly_build ( ) {
182
- err. help ( & format ! ( "add `#![feature({ feature})]` to the crate attributes to enable" ) ) ;
183
+ err. subdiagnostic ( FeatureDiagnosticHelp { feature } ) ;
183
184
}
184
185
}
185
186
@@ -372,6 +373,8 @@ impl ParseSess {
372
373
}
373
374
374
375
#[ rustc_lint_diagnostics]
376
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
377
+ #[ allow( rustc:: untranslatable_diagnostic) ]
375
378
pub fn struct_err (
376
379
& self ,
377
380
msg : impl Into < DiagnosticMessage > ,
@@ -380,16 +383,22 @@ impl ParseSess {
380
383
}
381
384
382
385
#[ rustc_lint_diagnostics]
386
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
387
+ #[ allow( rustc:: untranslatable_diagnostic) ]
383
388
pub fn struct_warn ( & self , msg : impl Into < DiagnosticMessage > ) -> DiagnosticBuilder < ' _ , ( ) > {
384
389
self . span_diagnostic . struct_warn ( msg)
385
390
}
386
391
387
392
#[ rustc_lint_diagnostics]
393
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
394
+ #[ allow( rustc:: untranslatable_diagnostic) ]
388
395
pub fn struct_fatal ( & self , msg : impl Into < DiagnosticMessage > ) -> DiagnosticBuilder < ' _ , !> {
389
396
self . span_diagnostic . struct_fatal ( msg)
390
397
}
391
398
392
399
#[ rustc_lint_diagnostics]
400
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
401
+ #[ allow( rustc:: untranslatable_diagnostic) ]
393
402
pub fn struct_diagnostic < G : EmissionGuarantee > (
394
403
& self ,
395
404
msg : impl Into < DiagnosticMessage > ,
0 commit comments