@@ -17,12 +17,13 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
17
17
use rustc_session:: Session ;
18
18
use rustc_session:: lint:: builtin:: { DEPRECATED , DEPRECATED_IN_FUTURE , SOFT_UNSTABLE } ;
19
19
use rustc_session:: lint:: { BuiltinLintDiag , DeprecatedSinceKind , Level , Lint , LintBuffer } ;
20
- use rustc_session:: parse:: feature_err_issues ;
20
+ use rustc_session:: parse:: add_feature_diagnostics_for_issues ;
21
21
use rustc_span:: Span ;
22
22
use rustc_span:: symbol:: { Symbol , sym} ;
23
23
use tracing:: debug;
24
24
25
25
pub use self :: StabilityLevel :: * ;
26
+ use crate :: error:: { SoftUnstableLibraryFeature , UnstableLibraryFeatureError } ;
26
27
use crate :: ty:: TyCtxt ;
27
28
28
29
#[ derive( PartialEq , Clone , Copy , Debug ) ]
@@ -106,25 +107,23 @@ pub fn report_unstable(
106
107
reason : Option < Symbol > ,
107
108
issue : Option < NonZero < u32 > > ,
108
109
suggestion : Option < ( Span , String , String , Applicability ) > ,
109
- is_soft : bool ,
110
110
span : Span ,
111
- soft_handler : impl FnOnce ( & ' static Lint , Span , String ) ,
112
111
) {
113
- let msg = match reason {
114
- Some ( r) => format ! ( "use of unstable library feature `{feature}`: {r}" ) ,
115
- None => format ! ( "use of unstable library feature `{feature}`" ) ,
116
- } ;
117
-
118
- if is_soft {
119
- soft_handler ( SOFT_UNSTABLE , span, msg)
120
- } else {
121
- let issues = Vec :: from_iter ( issue) ;
122
- let mut err = feature_err_issues ( sess, & [ feature] , span, GateIssues :: Library ( issues) , msg) ;
123
- if let Some ( ( inner_types, msg, sugg, applicability) ) = suggestion {
124
- err. span_suggestion ( inner_types, msg, sugg, applicability) ;
125
- }
126
- err. emit ( ) ;
112
+ let features = vec ! [ feature] ;
113
+
114
+ let mut err = sess. dcx ( ) . create_err ( UnstableLibraryFeatureError :: new ( feature, reason, span) ) ;
115
+ add_feature_diagnostics_for_issues (
116
+ & mut err,
117
+ sess,
118
+ & features,
119
+ GateIssues :: Library ( Vec :: from_iter ( issue) ) ,
120
+ false ,
121
+ None ,
122
+ ) ;
123
+ if let Some ( ( inner_types, msg, sugg, applicability) ) = suggestion {
124
+ err. span_suggestion ( inner_types, msg, sugg, applicability) ;
127
125
}
126
+ err. emit ( ) ;
128
127
}
129
128
130
129
fn deprecation_lint ( is_in_effect : bool ) -> & ' static Lint {
@@ -565,26 +564,23 @@ impl<'tcx> TyCtxt<'tcx> {
565
564
allow_unstable : AllowUnstable ,
566
565
unmarked : impl FnOnce ( Span , DefId ) ,
567
566
) -> bool {
568
- let soft_handler = |lint, span, msg : String | {
569
- self . node_span_lint ( lint, id. unwrap_or ( hir:: CRATE_HIR_ID ) , span, |lint| {
570
- lint. primary_message ( msg) ;
571
- } )
572
- } ;
573
567
let eval_result =
574
568
self . eval_stability_allow_unstable ( def_id, id, span, method_span, allow_unstable) ;
575
569
let is_allowed = matches ! ( eval_result, EvalResult :: Allow ) ;
576
570
match eval_result {
577
571
EvalResult :: Allow => { }
578
- EvalResult :: Deny { feature, reason, issue, suggestion, is_soft } => report_unstable (
579
- self . sess ,
580
- feature,
581
- reason,
582
- issue,
583
- suggestion,
584
- is_soft,
585
- span,
586
- soft_handler,
587
- ) ,
572
+ EvalResult :: Deny { feature, reason, issue, suggestion, is_soft } => {
573
+ if is_soft {
574
+ self . emit_node_span_lint (
575
+ SOFT_UNSTABLE ,
576
+ id. unwrap_or ( hir:: CRATE_HIR_ID ) ,
577
+ span,
578
+ SoftUnstableLibraryFeature :: new ( feature, reason) ,
579
+ ) ;
580
+ } else {
581
+ report_unstable ( self . sess , feature, reason, issue, suggestion, span) ;
582
+ }
583
+ }
588
584
EvalResult :: Unmarked => unmarked ( span, def_id) ,
589
585
}
590
586
0 commit comments