@@ -18,12 +18,13 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
18
18
use rustc_session:: Session ;
19
19
use rustc_session:: lint:: builtin:: { DEPRECATED , DEPRECATED_IN_FUTURE , SOFT_UNSTABLE } ;
20
20
use rustc_session:: lint:: { BuiltinLintDiag , DeprecatedSinceKind , Level , Lint , LintBuffer } ;
21
- use rustc_session:: parse:: feature_err_issues ;
21
+ use rustc_session:: parse:: add_feature_diagnostics_for_issues ;
22
22
use rustc_span:: Span ;
23
23
use rustc_span:: symbol:: { Symbol , sym} ;
24
24
use tracing:: debug;
25
25
26
26
pub use self :: StabilityLevel :: * ;
27
+ use crate :: error:: { SoftUnstableLibraryFeature , UnstableLibraryFeatureError } ;
27
28
use crate :: ty:: { self , TyCtxt } ;
28
29
29
30
#[ derive( PartialEq , Clone , Copy , Debug ) ]
@@ -107,25 +108,23 @@ pub fn report_unstable(
107
108
reason : Option < Symbol > ,
108
109
issue : Option < NonZero < u32 > > ,
109
110
suggestion : Option < ( Span , String , String , Applicability ) > ,
110
- is_soft : bool ,
111
111
span : Span ,
112
- soft_handler : impl FnOnce ( & ' static Lint , Span , String ) ,
113
112
) {
114
- let msg = match reason {
115
- Some ( r) => format ! ( "use of unstable library feature `{feature}`: {r}" ) ,
116
- None => format ! ( "use of unstable library feature `{feature}`" ) ,
117
- } ;
118
-
119
- if is_soft {
120
- soft_handler ( SOFT_UNSTABLE , span, msg)
121
- } else {
122
- let issues = Vec :: from_iter ( issue) ;
123
- let mut err = feature_err_issues ( sess, & [ feature] , span, GateIssues :: Library ( issues) , msg) ;
124
- if let Some ( ( inner_types, msg, sugg, applicability) ) = suggestion {
125
- err. span_suggestion ( inner_types, msg, sugg, applicability) ;
126
- }
127
- err. emit ( ) ;
113
+ let features = vec ! [ feature] ;
114
+
115
+ let mut err = sess. dcx ( ) . create_err ( UnstableLibraryFeatureError :: new ( feature, reason, span) ) ;
116
+ add_feature_diagnostics_for_issues (
117
+ & mut err,
118
+ sess,
119
+ & features,
120
+ GateIssues :: Library ( Vec :: from_iter ( issue) ) ,
121
+ false ,
122
+ None ,
123
+ ) ;
124
+ if let Some ( ( inner_types, msg, sugg, applicability) ) = suggestion {
125
+ err. span_suggestion ( inner_types, msg, sugg, applicability) ;
128
126
}
127
+ err. emit ( ) ;
129
128
}
130
129
131
130
fn deprecation_lint ( is_in_effect : bool ) -> & ' static Lint {
@@ -592,26 +591,23 @@ impl<'tcx> TyCtxt<'tcx> {
592
591
allow_unstable : AllowUnstable ,
593
592
unmarked : impl FnOnce ( Span , DefId ) ,
594
593
) -> bool {
595
- let soft_handler = |lint, span, msg : String | {
596
- self . node_span_lint ( lint, id. unwrap_or ( hir:: CRATE_HIR_ID ) , span, |lint| {
597
- lint. primary_message ( msg) ;
598
- } )
599
- } ;
600
594
let eval_result =
601
595
self . eval_stability_allow_unstable ( def_id, id, span, method_span, allow_unstable) ;
602
596
let is_allowed = matches ! ( eval_result, EvalResult :: Allow ) ;
603
597
match eval_result {
604
598
EvalResult :: Allow => { }
605
- EvalResult :: Deny { feature, reason, issue, suggestion, is_soft } => report_unstable (
606
- self . sess ,
607
- feature,
608
- reason,
609
- issue,
610
- suggestion,
611
- is_soft,
612
- span,
613
- soft_handler,
614
- ) ,
599
+ EvalResult :: Deny { feature, reason, issue, suggestion, is_soft } => {
600
+ if is_soft {
601
+ self . emit_node_span_lint (
602
+ SOFT_UNSTABLE ,
603
+ id. unwrap_or ( hir:: CRATE_HIR_ID ) ,
604
+ span,
605
+ SoftUnstableLibraryFeature :: new ( feature, reason) ,
606
+ ) ;
607
+ } else {
608
+ report_unstable ( self . sess , feature, reason, issue, suggestion, span) ;
609
+ }
610
+ }
615
611
EvalResult :: Unmarked => unmarked ( span, def_id) ,
616
612
}
617
613
0 commit comments