implemented code review
This commit is contained in:
parent
52d0e51473
commit
304c8b1eda
2 changed files with 24 additions and 18 deletions
|
@ -18,6 +18,7 @@ use hir::def::Def;
|
||||||
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
||||||
use ty::{self, TyCtxt};
|
use ty::{self, TyCtxt};
|
||||||
use middle::privacy::AccessLevels;
|
use middle::privacy::AccessLevels;
|
||||||
|
use session::DiagnosticMessageId;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
|
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
@ -601,27 +602,25 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
let msp: MultiSpan = span.into();
|
let msp: MultiSpan = span.into();
|
||||||
let cm = &self.sess.parse_sess.codemap();
|
let cm = &self.sess.parse_sess.codemap();
|
||||||
let span_key =
|
let span_key = msp.primary_span().and_then(|sp: Span|
|
||||||
msp.primary_span().and_then(|sp:Span|
|
if sp != DUMMY_SP {
|
||||||
if sp != DUMMY_SP {
|
let file = cm.lookup_char_pos(sp.lo()).file;
|
||||||
let fname = cm.lookup_char_pos(sp.lo()).file.as_ref().name.clone();
|
if file.name.starts_with("<") && file.name.ends_with(" macros>") {
|
||||||
if fname.starts_with("<") && fname.ends_with(" macros>") {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(span)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
Some(span)
|
||||||
}
|
}
|
||||||
);
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let tuple = (None, span_key, msg.clone());
|
let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone());
|
||||||
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(tuple);
|
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(error_id);
|
||||||
if fresh {
|
if fresh {
|
||||||
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
|
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
|
||||||
GateIssue::Library(Some(issue)), &msg);
|
GateIssue::Library(Some(issue)), &msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
// Stable APIs are always ok to call and deprecated APIs are
|
// Stable APIs are always ok to call and deprecated APIs are
|
||||||
|
|
|
@ -75,10 +75,10 @@ pub struct Session {
|
||||||
pub working_dir: (String, bool),
|
pub working_dir: (String, bool),
|
||||||
pub lint_store: RefCell<lint::LintStore>,
|
pub lint_store: RefCell<lint::LintStore>,
|
||||||
pub buffered_lints: RefCell<Option<lint::LintBuffer>>,
|
pub buffered_lints: RefCell<Option<lint::LintBuffer>>,
|
||||||
/// Set of (LintId, Option<Span>, message) tuples tracking lint
|
/// Set of (DiagnosticId, Option<Span>, message) tuples tracking
|
||||||
/// (sub)diagnostics that have been set once, but should not be set again,
|
/// (sub)diagnostics that have been set once, but should not be set again,
|
||||||
/// in order to avoid redundantly verbose output (Issue #24690).
|
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
|
||||||
pub one_time_diagnostics: RefCell<FxHashSet<(Option<lint::LintId>, Option<Span>, String)>>,
|
pub one_time_diagnostics: RefCell<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
|
||||||
pub plugin_llvm_passes: RefCell<Vec<String>>,
|
pub plugin_llvm_passes: RefCell<Vec<String>>,
|
||||||
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>,
|
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>,
|
||||||
pub crate_types: RefCell<Vec<config::CrateType>>,
|
pub crate_types: RefCell<Vec<config::CrateType>>,
|
||||||
|
@ -164,6 +164,13 @@ enum DiagnosticBuilderMethod {
|
||||||
// add more variants as needed to support one-time diagnostics
|
// add more variants as needed to support one-time diagnostics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Diagnostic message id - used in order to avoid emitting the same message more than once
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub enum DiagnosticMessageId {
|
||||||
|
LintId(lint::LintId),
|
||||||
|
StabilityId(u32)
|
||||||
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
pub fn local_crate_disambiguator(&self) -> CrateDisambiguator {
|
pub fn local_crate_disambiguator(&self) -> CrateDisambiguator {
|
||||||
match *self.crate_disambiguator.borrow() {
|
match *self.crate_disambiguator.borrow() {
|
||||||
|
@ -361,7 +368,7 @@ impl Session {
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
let lint_id = lint::LintId::of(lint);
|
let lint_id = lint::LintId::of(lint);
|
||||||
let id_span_message = (Some(lint_id), span, message.to_owned());
|
let id_span_message = (DiagnosticMessageId::LintId(lint_id), span, message.to_owned());
|
||||||
let fresh = self.one_time_diagnostics.borrow_mut().insert(id_span_message);
|
let fresh = self.one_time_diagnostics.borrow_mut().insert(id_span_message);
|
||||||
if fresh {
|
if fresh {
|
||||||
do_method()
|
do_method()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue