@@ -19,7 +19,7 @@ use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
19
19
use ty:: { self , TyCtxt } ;
20
20
use middle:: privacy:: AccessLevels ;
21
21
use syntax:: symbol:: Symbol ;
22
- use syntax_pos:: { Span , DUMMY_SP } ;
22
+ use syntax_pos:: { Span , MultiSpan , DUMMY_SP } ;
23
23
use syntax:: ast;
24
24
use syntax:: ast:: { NodeId , Attribute } ;
25
25
use syntax:: feature_gate:: { GateIssue , emit_feature_err, find_lang_feature_accepted_version} ;
@@ -597,8 +597,32 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
597
597
feature. as_str( ) , & r) ,
598
598
None => format ! ( "use of unstable library feature '{}'" , & feature)
599
599
} ;
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
+
602
626
}
603
627
Some ( _) => {
604
628
// Stable APIs are always ok to call and deprecated APIs are
0 commit comments