ty: HirIdify some lints
This commit is contained in:
parent
e72584c3a1
commit
c2e517e0c4
14 changed files with 62 additions and 89 deletions
|
@ -729,8 +729,7 @@ impl<'a, 'tcx> LintContext<'tcx> for LateContext<'a, 'tcx> {
|
|||
match span {
|
||||
Some(s) => self.tcx.struct_span_lint_hir(lint, hir_id, s, msg),
|
||||
None => {
|
||||
let node_id = self.tcx.hir().hir_to_node_id(hir_id); // FIXME(@ljedrz): remove later
|
||||
self.tcx.struct_lint_node(lint, node_id, msg)
|
||||
self.tcx.struct_lint_node(lint, hir_id, msg)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ use crate::middle::privacy::AccessLevels;
|
|||
use crate::session::{DiagnosticMessageId, Session};
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax_pos::{Span, MultiSpan};
|
||||
use syntax::ast;
|
||||
use syntax::ast::Attribute;
|
||||
use syntax::errors::Applicability;
|
||||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
||||
|
@ -922,8 +921,8 @@ fn unnecessary_stable_feature_lint<'a, 'tcx>(
|
|||
feature: Symbol,
|
||||
since: Symbol
|
||||
) {
|
||||
tcx.lint_node(lint::builtin::STABLE_FEATURES,
|
||||
ast::CRATE_NODE_ID,
|
||||
tcx.lint_hir(lint::builtin::STABLE_FEATURES,
|
||||
hir::CRATE_HIR_ID,
|
||||
span,
|
||||
&format!("the feature `{}` has been stable since {} and no longer requires \
|
||||
an attribute to enable", feature, since));
|
||||
|
|
|
@ -334,9 +334,9 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(
|
|||
FutureCompatOverlapErrorKind::Issue33140 =>
|
||||
lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS,
|
||||
};
|
||||
tcx.struct_span_lint_node(
|
||||
tcx.struct_span_lint_hir(
|
||||
lint,
|
||||
tcx.hir().as_local_node_id(impl_def_id).unwrap(),
|
||||
tcx.hir().as_local_hir_id(impl_def_id).unwrap(),
|
||||
impl_span,
|
||||
&msg)
|
||||
} else {
|
||||
|
|
|
@ -65,7 +65,7 @@ use std::sync::mpsc;
|
|||
use std::sync::Arc;
|
||||
use std::marker::PhantomData;
|
||||
use rustc_target::spec::abi;
|
||||
use syntax::ast::{self, NodeId};
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::source_map::MultiSpan;
|
||||
use syntax::edition::Edition;
|
||||
|
@ -2836,14 +2836,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
self.struct_span_lint_hir(lint, hir_id, span.into(), msg).emit()
|
||||
}
|
||||
|
||||
pub fn lint_node<S: Into<MultiSpan>>(self,
|
||||
lint: &'static Lint,
|
||||
id: NodeId,
|
||||
span: S,
|
||||
msg: &str) {
|
||||
self.struct_span_lint_node(lint, id, span.into(), msg).emit()
|
||||
}
|
||||
|
||||
pub fn lint_hir_note<S: Into<MultiSpan>>(self,
|
||||
lint: &'static Lint,
|
||||
hir_id: HirId,
|
||||
|
@ -2866,7 +2858,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
err.emit()
|
||||
}
|
||||
|
||||
pub fn lint_level_at_node(self, lint: &'static Lint, mut id: NodeId)
|
||||
pub fn lint_level_at_node(self, lint: &'static Lint, mut id: hir::HirId)
|
||||
-> (lint::Level, lint::LintSource)
|
||||
{
|
||||
// Right now we insert a `with_ignore` node in the dep graph here to
|
||||
|
@ -2880,11 +2872,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
self.dep_graph.with_ignore(|| {
|
||||
let sets = self.lint_levels(LOCAL_CRATE);
|
||||
loop {
|
||||
let hir_id = self.hir().definitions().node_to_hir_id(id);
|
||||
if let Some(pair) = sets.level_and_source(lint, hir_id, self.sess) {
|
||||
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {
|
||||
return pair
|
||||
}
|
||||
let next = self.hir().get_parent_node(id);
|
||||
let next = self.hir().get_parent_node_by_hir_id(id);
|
||||
if next == id {
|
||||
bug!("lint traversal reached the root of the crate");
|
||||
}
|
||||
|
@ -2900,23 +2891,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
msg: &str)
|
||||
-> DiagnosticBuilder<'tcx>
|
||||
{
|
||||
let node_id = self.hir().hir_to_node_id(hir_id);
|
||||
let (level, src) = self.lint_level_at_node(lint, node_id);
|
||||
let (level, src) = self.lint_level_at_node(lint, hir_id);
|
||||
lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg)
|
||||
}
|
||||
|
||||
pub fn struct_span_lint_node<S: Into<MultiSpan>>(self,
|
||||
lint: &'static Lint,
|
||||
id: NodeId,
|
||||
span: S,
|
||||
msg: &str)
|
||||
-> DiagnosticBuilder<'tcx>
|
||||
{
|
||||
let (level, src) = self.lint_level_at_node(lint, id);
|
||||
lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg)
|
||||
}
|
||||
|
||||
pub fn struct_lint_node(self, lint: &'static Lint, id: NodeId, msg: &str)
|
||||
pub fn struct_lint_node(self, lint: &'static Lint, id: HirId, msg: &str)
|
||||
-> DiagnosticBuilder<'tcx>
|
||||
{
|
||||
let (level, src) = self.lint_level_at_node(lint, id);
|
||||
|
|
|
@ -346,9 +346,9 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
|||
NotUseful => {
|
||||
match source {
|
||||
hir::MatchSource::IfLetDesugar { .. } => {
|
||||
cx.tcx.lint_node(
|
||||
cx.tcx.lint_hir(
|
||||
lint::builtin::IRREFUTABLE_LET_PATTERNS,
|
||||
hir_pat.id,
|
||||
hir_pat.hir_id,
|
||||
pat.span,
|
||||
"irrefutable if-let pattern",
|
||||
);
|
||||
|
@ -359,16 +359,16 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
|||
match arm_index {
|
||||
// The arm with the user-specified pattern.
|
||||
0 => {
|
||||
cx.tcx.lint_node(
|
||||
cx.tcx.lint_hir(
|
||||
lint::builtin::UNREACHABLE_PATTERNS,
|
||||
hir_pat.id, pat.span,
|
||||
hir_pat.hir_id, pat.span,
|
||||
"unreachable pattern");
|
||||
},
|
||||
// The arm with the wildcard pattern.
|
||||
1 => {
|
||||
cx.tcx.lint_node(
|
||||
cx.tcx.lint_hir(
|
||||
lint::builtin::IRREFUTABLE_LET_PATTERNS,
|
||||
hir_pat.id,
|
||||
hir_pat.hir_id,
|
||||
pat.span,
|
||||
"irrefutable while-let pattern",
|
||||
);
|
||||
|
@ -379,9 +379,9 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
|||
|
||||
hir::MatchSource::ForLoopDesugar |
|
||||
hir::MatchSource::Normal => {
|
||||
let mut err = cx.tcx.struct_span_lint_node(
|
||||
let mut err = cx.tcx.struct_span_lint_hir(
|
||||
lint::builtin::UNREACHABLE_PATTERNS,
|
||||
hir_pat.id,
|
||||
hir_pat.hir_id,
|
||||
pat.span,
|
||||
"unreachable pattern",
|
||||
);
|
||||
|
|
|
@ -955,8 +955,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
|||
debug!("const_to_pat: cv.ty={:?} span={:?}", cv.ty, span);
|
||||
let kind = match cv.ty.sty {
|
||||
ty::Float(_) => {
|
||||
let id = self.tcx.hir().hir_to_node_id(id);
|
||||
self.tcx.lint_node(
|
||||
self.tcx.lint_hir(
|
||||
::rustc::lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
|
||||
id,
|
||||
span,
|
||||
|
|
|
@ -129,12 +129,12 @@ fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
// no break */ }`) shouldn't be linted unless it actually
|
||||
// recurs.
|
||||
if !reached_exit_without_self_call && !self_call_locations.is_empty() {
|
||||
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
|
||||
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
|
||||
let sp = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(hir_id));
|
||||
let mut db = tcx.struct_span_lint_node(UNCONDITIONAL_RECURSION,
|
||||
node_id,
|
||||
sp,
|
||||
"function cannot return without recursing");
|
||||
let mut db = tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION,
|
||||
hir_id,
|
||||
sp,
|
||||
"function cannot return without recursing");
|
||||
db.span_label(sp, "cannot return without recursing");
|
||||
// offer some help to the programmer.
|
||||
for location in &self_call_locations {
|
||||
|
|
|
@ -553,10 +553,8 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
|
|||
}
|
||||
|
||||
fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
|
||||
let lint_node_id = match tcx.hir().as_local_node_id(def_id) {
|
||||
Some(node_id) => node_id,
|
||||
None => bug!("checking unsafety for non-local def id {:?}", def_id)
|
||||
};
|
||||
let lint_hir_id = tcx.hir().as_local_hir_id(def_id).unwrap_or_else(||
|
||||
bug!("checking unsafety for non-local def id {:?}", def_id));
|
||||
|
||||
// FIXME: when we make this a hard error, this should have its
|
||||
// own error code.
|
||||
|
@ -567,10 +565,10 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
|
|||
"#[derive] can't be used on a #[repr(packed)] struct that \
|
||||
does not derive Copy (error E0133)".to_string()
|
||||
};
|
||||
tcx.lint_node(SAFE_PACKED_BORROWS,
|
||||
lint_node_id,
|
||||
tcx.def_span(def_id),
|
||||
&message);
|
||||
tcx.lint_hir(SAFE_PACKED_BORROWS,
|
||||
lint_hir_id,
|
||||
tcx.def_span(def_id),
|
||||
&message);
|
||||
}
|
||||
|
||||
/// Returns the `HirId` for an enclosing scope that is also `unsafe`.
|
||||
|
|
|
@ -603,10 +603,10 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
|
|||
.unwrap()
|
||||
.source_info
|
||||
.span;
|
||||
let node_id = self
|
||||
let hir_id = self
|
||||
.tcx
|
||||
.hir()
|
||||
.as_local_node_id(self.source.def_id())
|
||||
.as_local_hir_id(self.source.def_id())
|
||||
.expect("some part of a failing const eval must be local");
|
||||
use rustc::mir::interpret::EvalErrorKind::*;
|
||||
let msg = match msg {
|
||||
|
@ -643,9 +643,9 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
|
|||
// Need proper const propagator for these
|
||||
_ => return,
|
||||
};
|
||||
self.tcx.lint_node(
|
||||
self.tcx.lint_hir(
|
||||
::rustc::lint::builtin::CONST_ERR,
|
||||
node_id,
|
||||
hir_id,
|
||||
span,
|
||||
&msg,
|
||||
);
|
||||
|
|
|
@ -1539,12 +1539,12 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
|
|||
|
||||
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
|
||||
if self.leaks_private_dep(def_id) {
|
||||
self.tcx.lint_node(lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
|
||||
self.item_id,
|
||||
self.span,
|
||||
&format!("{} `{}` from private dependency '{}' in public \
|
||||
interface", kind, descr,
|
||||
self.tcx.crate_name(def_id.krate)));
|
||||
self.tcx.lint_hir(lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
|
||||
self.item_id,
|
||||
self.span,
|
||||
&format!("{} `{}` from private dependency '{}' in public \
|
||||
interface", kind, descr,
|
||||
self.tcx.crate_name(def_id.krate)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1567,8 +1567,8 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
|
|||
err.emit();
|
||||
} else {
|
||||
let err_code = if kind == "trait" { "E0445" } else { "E0446" };
|
||||
self.tcx.lint_node(lint::builtin::PRIVATE_IN_PUBLIC, node_id, self.span,
|
||||
&format!("{} (error {})", msg, err_code));
|
||||
self.tcx.lint_hir(lint::builtin::PRIVATE_IN_PUBLIC, hir_id, self.span,
|
||||
&format!("{} (error {})", msg, err_code));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,14 +51,13 @@ struct CheckVisitor<'a, 'tcx: 'a> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> CheckVisitor<'a, 'tcx> {
|
||||
fn check_import(&self, id: ast::NodeId, span: Span) {
|
||||
let def_id = self.tcx.hir().local_def_id(id);
|
||||
fn check_import(&self, id: hir::HirId, span: Span) {
|
||||
let def_id = self.tcx.hir().local_def_id_from_hir_id(id);
|
||||
if !self.tcx.maybe_unused_trait_import(def_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
let import_def_id = self.tcx.hir().local_def_id(id);
|
||||
if self.used_trait_imports.contains(&import_def_id) {
|
||||
if self.used_trait_imports.contains(&def_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -67,7 +66,7 @@ impl<'a, 'tcx> CheckVisitor<'a, 'tcx> {
|
|||
} else {
|
||||
"unused import".to_owned()
|
||||
};
|
||||
self.tcx.lint_node(lint::builtin::UNUSED_IMPORTS, id, span, &msg);
|
||||
self.tcx.lint_hir(lint::builtin::UNUSED_IMPORTS, id, span, &msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,8 +120,8 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
|
|||
});
|
||||
|
||||
for extern_crate in &crates_to_lint {
|
||||
let id = tcx.hir().as_local_node_id(extern_crate.def_id).unwrap();
|
||||
let item = tcx.hir().expect_item(id);
|
||||
let id = tcx.hir().as_local_hir_id(extern_crate.def_id).unwrap();
|
||||
let item = tcx.hir().expect_item_by_hir_id(id);
|
||||
|
||||
// If the crate is fully unused, we suggest removing it altogether.
|
||||
// We do this in any edition.
|
||||
|
@ -135,7 +134,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
|
|||
.map(|attr| attr.span)
|
||||
.fold(span, |acc, attr_span| acc.to(attr_span));
|
||||
|
||||
tcx.struct_span_lint_node(lint, id, span, msg)
|
||||
tcx.struct_span_lint_hir(lint, id, span, msg)
|
||||
.span_suggestion_short(
|
||||
span_with_attrs,
|
||||
"remove it",
|
||||
|
@ -177,7 +176,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
|
|||
None => format!("use {};", item.ident.name),
|
||||
};
|
||||
let replacement = visibility_qualified(&item.vis, base_replacement);
|
||||
tcx.struct_span_lint_node(lint, id, extern_crate.span, msg)
|
||||
tcx.struct_span_lint_hir(lint, id, extern_crate.span, msg)
|
||||
.span_suggestion_short(
|
||||
extern_crate.span,
|
||||
&help,
|
||||
|
|
|
@ -36,11 +36,11 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
|
|||
|
||||
for &item2 in &impl_items2[..] {
|
||||
if (name, namespace) == name_and_namespace(item2) {
|
||||
let node_id = self.tcx.hir().as_local_node_id(impl1);
|
||||
let mut err = if used_to_be_allowed && node_id.is_some() {
|
||||
self.tcx.struct_span_lint_node(
|
||||
let hir_id = self.tcx.hir().as_local_hir_id(impl1);
|
||||
let mut err = if used_to_be_allowed && hir_id.is_some() {
|
||||
self.tcx.struct_span_lint_hir(
|
||||
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
|
||||
node_id.unwrap(),
|
||||
hir_id.unwrap(),
|
||||
self.tcx.span_of_impl(item1).unwrap(),
|
||||
&format!("duplicate definitions with name `{}` (E0592)", name)
|
||||
)
|
||||
|
|
|
@ -473,9 +473,9 @@ fn resolution_failure(
|
|||
) {
|
||||
let sp = span_of_attrs(attrs);
|
||||
|
||||
let mut diag = cx.tcx.struct_span_lint_node(
|
||||
let mut diag = cx.tcx.struct_span_lint_hir(
|
||||
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
|
||||
NodeId::from_u32(0),
|
||||
hir::CRATE_HIR_ID,
|
||||
sp,
|
||||
&format!("`[{}]` cannot be resolved, ignoring it...", path_str),
|
||||
);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
//! Contains information about "passes", used to modify crate information during the documentation
|
||||
//! process.
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::lint as lint;
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::util::nodemap::DefIdSet;
|
||||
use std::mem;
|
||||
use syntax::ast::NodeId;
|
||||
use syntax_pos::{DUMMY_SP, Span};
|
||||
use std::ops::Range;
|
||||
|
||||
|
@ -312,18 +312,18 @@ pub fn look_for_tests<'a, 'tcx: 'a, 'rcx: 'a>(
|
|||
|
||||
if find_testable_code(&dox, &mut tests, ErrorCodes::No).is_ok() {
|
||||
if check_missing_code == true && tests.found_tests == 0 {
|
||||
let mut diag = cx.tcx.struct_span_lint_node(
|
||||
let mut diag = cx.tcx.struct_span_lint_hir(
|
||||
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
|
||||
NodeId::from_u32(0),
|
||||
hir::CRATE_HIR_ID,
|
||||
span_of_attrs(&item.attrs),
|
||||
"Missing code example in this documentation");
|
||||
diag.emit();
|
||||
} else if check_missing_code == false &&
|
||||
tests.found_tests > 0 &&
|
||||
!cx.renderinfo.borrow().access_levels.is_doc_reachable(item.def_id) {
|
||||
let mut diag = cx.tcx.struct_span_lint_node(
|
||||
let mut diag = cx.tcx.struct_span_lint_hir(
|
||||
lint::builtin::PRIVATE_DOC_TESTS,
|
||||
NodeId::from_u32(0),
|
||||
hir::CRATE_HIR_ID,
|
||||
span_of_attrs(&item.attrs),
|
||||
"Documentation test in private item");
|
||||
diag.emit();
|
||||
|
|
Loading…
Reference in a new issue