@@ -477,6 +477,36 @@ pub fn provide(providers: &mut Providers<'_>) {
477477 } ;
478478}
479479
480+ pub fn report_unstable (
481+ sess : & Session , feature : Symbol , reason : Option < Symbol > , issue : u32 , span : Span
482+ ) {
483+ let msg = match reason {
484+ Some ( r) => format ! ( "use of unstable library feature '{}': {}" , feature, r) ,
485+ None => format ! ( "use of unstable library feature '{}'" , & feature)
486+ } ;
487+
488+ let msp: MultiSpan = span. into ( ) ;
489+ let cm = & sess. parse_sess . source_map ( ) ;
490+ let span_key = msp. primary_span ( ) . and_then ( |sp : Span |
491+ if !sp. is_dummy ( ) {
492+ let file = cm. lookup_char_pos ( sp. lo ( ) ) . file ;
493+ if file. name . is_macros ( ) {
494+ None
495+ } else {
496+ Some ( span)
497+ }
498+ } else {
499+ None
500+ }
501+ ) ;
502+
503+ let error_id = ( DiagnosticMessageId :: StabilityId ( issue) , span_key, msg. clone ( ) ) ;
504+ let fresh = sess. one_time_diagnostics . borrow_mut ( ) . insert ( error_id) ;
505+ if fresh {
506+ emit_feature_err ( & sess. parse_sess , feature, span, GateIssue :: Library ( Some ( issue) ) , & msg) ;
507+ }
508+ }
509+
480510/// Checks whether an item marked with `deprecated(since="X")` is currently
481511/// deprecated (i.e., whether X is not greater than the current rustc version).
482512pub fn deprecation_in_effect ( since : & str ) -> bool {
@@ -715,34 +745,8 @@ impl<'tcx> TyCtxt<'tcx> {
715745 pub fn check_stability ( self , def_id : DefId , id : Option < HirId > , span : Span ) {
716746 match self . eval_stability ( def_id, id, span) {
717747 EvalResult :: Allow => { }
718- EvalResult :: Deny { feature, reason, issue } => {
719- let msg = match reason {
720- Some ( r) => format ! ( "use of unstable library feature '{}': {}" , feature, r) ,
721- None => format ! ( "use of unstable library feature '{}'" , & feature)
722- } ;
723-
724- let msp: MultiSpan = span. into ( ) ;
725- let cm = & self . sess . parse_sess . source_map ( ) ;
726- let span_key = msp. primary_span ( ) . and_then ( |sp : Span |
727- if !sp. is_dummy ( ) {
728- let file = cm. lookup_char_pos ( sp. lo ( ) ) . file ;
729- if file. name . is_macros ( ) {
730- None
731- } else {
732- Some ( span)
733- }
734- } else {
735- None
736- }
737- ) ;
738-
739- let error_id = ( DiagnosticMessageId :: StabilityId ( issue) , span_key, msg. clone ( ) ) ;
740- let fresh = self . sess . one_time_diagnostics . borrow_mut ( ) . insert ( error_id) ;
741- if fresh {
742- emit_feature_err ( & self . sess . parse_sess , feature, span,
743- GateIssue :: Library ( Some ( issue) ) , & msg) ;
744- }
745- }
748+ EvalResult :: Deny { feature, reason, issue } =>
749+ report_unstable ( self . sess , feature, reason, issue, span) ,
746750 EvalResult :: Unmarked => {
747751 // The API could be uncallable for other reasons, for example when a private module
748752 // was referenced.
0 commit comments