@@ -17,12 +17,13 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1717use rustc_session:: Session ;
1818use rustc_session:: lint:: builtin:: { DEPRECATED , DEPRECATED_IN_FUTURE , SOFT_UNSTABLE } ;
1919use 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 ;
2121use rustc_span:: Span ;
2222use rustc_span:: symbol:: { Symbol , sym} ;
2323use tracing:: debug;
2424
2525pub use self :: StabilityLevel :: * ;
26+ use crate :: error:: { SoftUnstableLibraryFeature , UnstableLibraryFeatureError } ;
2627use crate :: ty:: TyCtxt ;
2728
2829#[ derive( PartialEq , Clone , Copy , Debug ) ]
@@ -106,25 +107,23 @@ pub fn report_unstable(
106107 reason : Option < Symbol > ,
107108 issue : Option < NonZero < u32 > > ,
108109 suggestion : Option < ( Span , String , String , Applicability ) > ,
109- is_soft : bool ,
110110 span : Span ,
111- soft_handler : impl FnOnce ( & ' static Lint , Span , String ) ,
112111) {
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) ;
127125 }
126+ err. emit ( ) ;
128127}
129128
130129fn deprecation_lint ( is_in_effect : bool ) -> & ' static Lint {
@@ -565,26 +564,23 @@ impl<'tcx> TyCtxt<'tcx> {
565564 allow_unstable : AllowUnstable ,
566565 unmarked : impl FnOnce ( Span , DefId ) ,
567566 ) -> 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- } ;
573567 let eval_result =
574568 self . eval_stability_allow_unstable ( def_id, id, span, method_span, allow_unstable) ;
575569 let is_allowed = matches ! ( eval_result, EvalResult :: Allow ) ;
576570 match eval_result {
577571 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+ }
588584 EvalResult :: Unmarked => unmarked ( span, def_id) ,
589585 }
590586
0 commit comments