@@ -19,7 +19,7 @@ use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
1919use ty:: { self , TyCtxt } ;
2020use middle:: privacy:: AccessLevels ;
2121use syntax:: symbol:: Symbol ;
22- use syntax_pos:: { Span , DUMMY_SP } ;
22+ use syntax_pos:: { Span , MultiSpan , DUMMY_SP } ;
2323use syntax:: ast;
2424use syntax:: ast:: { NodeId , Attribute } ;
2525use syntax:: feature_gate:: { GateIssue , emit_feature_err, find_lang_feature_accepted_version} ;
@@ -597,8 +597,32 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
597597 feature. as_str( ) , & r) ,
598598 None => format ! ( "use of unstable library feature '{}'" , & feature)
599599 } ;
600- emit_feature_err ( & self . sess . parse_sess , & feature. as_str ( ) , span,
601- GateIssue :: Library ( Some ( issue) ) , & msg) ;
600+
601+ let msp: MultiSpan = span. into ( ) ;
602+ let cm = & self . sess . parse_sess . codemap ( ) ;
603+ let real_file_location =
604+ msp. primary_span ( ) . and_then ( |sp : Span |
605+ if sp != DUMMY_SP {
606+ let fname = cm. lookup_char_pos ( sp. lo ( ) ) . file . as_ref ( ) . name . clone ( ) ;
607+ if fname. starts_with ( "<" ) && fname. ends_with ( " macros>" ) {
608+ None
609+ } else {
610+ Some ( fname)
611+ }
612+ } else {
613+ None
614+ }
615+ ) ;
616+
617+ if let Some ( _) = real_file_location {
618+ let tuple = ( None , Some ( span) , msg. clone ( ) ) ;
619+ let fresh = self . sess . one_time_diagnostics . borrow_mut ( ) . insert ( tuple) ;
620+ if fresh {
621+ emit_feature_err ( & self . sess . parse_sess , & feature. as_str ( ) , span,
622+ GateIssue :: Library ( Some ( issue) ) , & msg) ;
623+ }
624+ }
625+
602626 }
603627 Some ( _) => {
604628 // Stable APIs are always ok to call and deprecated APIs are
0 commit comments