diff options
| author | ljedrz <ljedrz@gmail.com> | 2019-02-26 11:48:34 +0100 |
|---|---|---|
| committer | ljedrz <ljedrz@gmail.com> | 2019-03-01 11:18:49 +0100 |
| commit | c2e517e0c4eabda5f71bec1124ed5bb746c39eb0 (patch) | |
| tree | 22417bf2d8b51d6c99beb91a2c64edd4bf488526 /src | |
| parent | e72584c3a1b74dcc8f2ef51fb1d934c397b524aa (diff) | |
| download | rust-c2e517e0c4eabda5f71bec1124ed5bb746c39eb0.tar.gz rust-c2e517e0c4eabda5f71bec1124ed5bb746c39eb0.zip | |
ty: HirIdify some lints
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/lint/context.rs | 3 | ||||
| -rw-r--r-- | src/librustc/middle/stability.rs | 5 | ||||
| -rw-r--r-- | src/librustc/traits/specialize/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/ty/context.rs | 33 | ||||
| -rw-r--r-- | src/librustc_mir/hair/pattern/check_match.rs | 16 | ||||
| -rw-r--r-- | src/librustc_mir/hair/pattern/mod.rs | 3 | ||||
| -rw-r--r-- | src/librustc_mir/lints.rs | 10 | ||||
| -rw-r--r-- | src/librustc_mir/transform/check_unsafety.rs | 14 | ||||
| -rw-r--r-- | src/librustc_mir/transform/const_prop.rs | 8 | ||||
| -rw-r--r-- | src/librustc_privacy/lib.rs | 16 | ||||
| -rw-r--r-- | src/librustc_typeck/check_unused.rs | 17 | ||||
| -rw-r--r-- | src/librustc_typeck/coherence/inherent_impls_overlap.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/passes/collect_intra_doc_links.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/passes/mod.rs | 10 |
14 files changed, 62 insertions, 89 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index a856bfbfd7e..9761ee31353 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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) }, } } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index f85b8060544..5b7bfab5acc 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -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)); diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 1d84f22acd9..a2924cb993f 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -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 { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index d02c9fc174c..1983dfbd4b7 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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); - 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); + 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_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); diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 9cecf4af7d4..0f151cd688d 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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", ); diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index c234c2474ff..d5f2e7a7275 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -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, diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index bf6d6e1ba73..bfc977c28cd 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -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 { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 3ed63d749cd..caddc23077d 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -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`. diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 5ed0055e7c4..ed0e27a1f78 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -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, ); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 93305797eef..6c03dbd8f0b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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)); } } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 3da090aed9c..4c6d7710009 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -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, diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 282f1bad172..a51f45a6ff8 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -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) ) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 67f291285c4..25c86b24c18 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -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), ); diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 3a9d8ef20ce..d6f3585a04f 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -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(); |
