Skip to content

Commit 304c8b1

Browse files
author
Virgil Palanciuc
committed
implemented code review
1 parent 52d0e51 commit 304c8b1

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/librustc/middle/stability.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use hir::def::Def;
1818
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
1919
use ty::{self, TyCtxt};
2020
use middle::privacy::AccessLevels;
21+
use session::DiagnosticMessageId;
2122
use syntax::symbol::Symbol;
2223
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
2324
use syntax::ast;
@@ -601,27 +602,25 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
601602

602603
let msp: MultiSpan = span.into();
603604
let cm = &self.sess.parse_sess.codemap();
604-
let span_key =
605-
msp.primary_span().and_then(|sp:Span|
606-
if sp != DUMMY_SP {
607-
let fname = cm.lookup_char_pos(sp.lo()).file.as_ref().name.clone();
608-
if fname.starts_with("<") && fname.ends_with(" macros>") {
609-
None
610-
} else {
611-
Some(span)
612-
}
613-
} else {
605+
let span_key = msp.primary_span().and_then(|sp: Span|
606+
if sp != DUMMY_SP {
607+
let file = cm.lookup_char_pos(sp.lo()).file;
608+
if file.name.starts_with("<") && file.name.ends_with(" macros>") {
614609
None
610+
} else {
611+
Some(span)
615612
}
616-
);
613+
} else {
614+
None
615+
}
616+
);
617617

618-
let tuple = (None, span_key, msg.clone());
619-
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(tuple);
618+
let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone());
619+
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(error_id);
620620
if fresh {
621621
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
622622
GateIssue::Library(Some(issue)), &msg);
623623
}
624-
625624
}
626625
Some(_) => {
627626
// Stable APIs are always ok to call and deprecated APIs are

src/librustc/session/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ pub struct Session {
7575
pub working_dir: (String, bool),
7676
pub lint_store: RefCell<lint::LintStore>,
7777
pub buffered_lints: RefCell<Option<lint::LintBuffer>>,
78-
/// Set of (LintId, Option<Span>, message) tuples tracking lint
78+
/// Set of (DiagnosticId, Option<Span>, message) tuples tracking
7979
/// (sub)diagnostics that have been set once, but should not be set again,
80-
/// in order to avoid redundantly verbose output (Issue #24690).
81-
pub one_time_diagnostics: RefCell<FxHashSet<(Option<lint::LintId>, Option<Span>, String)>>,
80+
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
81+
pub one_time_diagnostics: RefCell<FxHashSet<(DiagnosticMessageId, 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>>,
@@ -164,6 +164,13 @@ enum DiagnosticBuilderMethod {
164164
// add more variants as needed to support one-time diagnostics
165165
}
166166

167+
/// Diagnostic message id - used in order to avoid emitting the same message more than once
168+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
169+
pub enum DiagnosticMessageId {
170+
LintId(lint::LintId),
171+
StabilityId(u32)
172+
}
173+
167174
impl Session {
168175
pub fn local_crate_disambiguator(&self) -> CrateDisambiguator {
169176
match *self.crate_disambiguator.borrow() {
@@ -361,7 +368,7 @@ impl Session {
361368
},
362369
_ => {
363370
let lint_id = lint::LintId::of(lint);
364-
let id_span_message = (Some(lint_id), span, message.to_owned());
371+
let id_span_message = (DiagnosticMessageId::LintId(lint_id), span, message.to_owned());
365372
let fresh = self.one_time_diagnostics.borrow_mut().insert(id_span_message);
366373
if fresh {
367374
do_method()

0 commit comments

Comments
 (0)