Skip to content

Commit 4e16e30

Browse files
author
Virgil Palanciuc
committed
fix rust-lang#44953 - The “use of unstable library feature 'rustc_private'” error is very repetitive
1 parent f9d2416 commit 4e16e30

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/librustc/middle/stability.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
1919
use ty::{self, TyCtxt};
2020
use middle::privacy::AccessLevels;
2121
use syntax::symbol::Symbol;
22-
use syntax_pos::{Span, DUMMY_SP};
22+
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
2323
use syntax::ast;
2424
use syntax::ast::{NodeId, Attribute};
2525
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> {
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

src/librustc/session/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct Session {
7878
/// Set of (LintId, Option<Span>, message) tuples tracking lint
7979
/// (sub)diagnostics that have been set once, but should not be set again,
8080
/// in order to avoid redundantly verbose output (Issue #24690).
81-
pub one_time_diagnostics: RefCell<FxHashSet<(lint::LintId, Option<Span>, String)>>,
81+
pub one_time_diagnostics: RefCell<FxHashSet<(Option<lint::LintId>, Option<Span>, String)>>,
8282
pub plugin_llvm_passes: RefCell<Vec<String>>,
8383
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>,
8484
pub crate_types: RefCell<Vec<config::CrateType>>,
@@ -361,7 +361,7 @@ impl Session {
361361
},
362362
_ => {
363363
let lint_id = lint::LintId::of(lint);
364-
let id_span_message = (lint_id, span, message.to_owned());
364+
let id_span_message = (Some(lint_id), span, message.to_owned());
365365
let fresh = self.one_time_diagnostics.borrow_mut().insert(id_span_message);
366366
if fresh {
367367
do_method()

0 commit comments

Comments
 (0)