@@ -18,12 +18,13 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1818use rustc_session:: Session ;
1919use rustc_session:: lint:: builtin:: { DEPRECATED , DEPRECATED_IN_FUTURE , SOFT_UNSTABLE } ;
2020use 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 ;
2222use rustc_span:: Span ;
2323use rustc_span:: symbol:: { Symbol , sym} ;
2424use tracing:: debug;
2525
2626pub use self :: StabilityLevel :: * ;
27+ use crate :: error:: { SoftUnstableLibraryFeature , UnstableLibraryFeatureError } ;
2728use crate :: ty:: { self , TyCtxt } ;
2829
2930#[ derive( PartialEq , Clone , Copy , Debug ) ]
@@ -107,25 +108,23 @@ pub fn report_unstable(
107108 reason : Option < Symbol > ,
108109 issue : Option < NonZero < u32 > > ,
109110 suggestion : Option < ( Span , String , String , Applicability ) > ,
110- is_soft : bool ,
111111 span : Span ,
112- soft_handler : impl FnOnce ( & ' static Lint , Span , String ) ,
113112) {
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) ;
128126 }
127+ err. emit ( ) ;
129128}
130129
131130fn deprecation_lint ( is_in_effect : bool ) -> & ' static Lint {
@@ -592,26 +591,23 @@ impl<'tcx> TyCtxt<'tcx> {
592591 allow_unstable : AllowUnstable ,
593592 unmarked : impl FnOnce ( Span , DefId ) ,
594593 ) -> 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- } ;
600594 let eval_result =
601595 self . eval_stability_allow_unstable ( def_id, id, span, method_span, allow_unstable) ;
602596 let is_allowed = matches ! ( eval_result, EvalResult :: Allow ) ;
603597 match eval_result {
604598 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+ }
615611 EvalResult :: Unmarked => unmarked ( span, def_id) ,
616612 }
617613
0 commit comments