Skip to content

Commit c2e517e

Browse files
committed
ty: HirIdify some lints
1 parent e72584c commit c2e517e

File tree

14 files changed

+62
-89
lines changed

14 files changed

+62
-89
lines changed

src/librustc/lint/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,7 @@ impl<'a, 'tcx> LintContext<'tcx> for LateContext<'a, 'tcx> {
729729
match span {
730730
Some(s) => self.tcx.struct_span_lint_hir(lint, hir_id, s, msg),
731731
None => {
732-
let node_id = self.tcx.hir().hir_to_node_id(hir_id); // FIXME(@ljedrz): remove later
733-
self.tcx.struct_lint_node(lint, node_id, msg)
732+
self.tcx.struct_lint_node(lint, hir_id, msg)
734733
},
735734
}
736735
}

src/librustc/middle/stability.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::middle::privacy::AccessLevels;
1313
use crate::session::{DiagnosticMessageId, Session};
1414
use syntax::symbol::Symbol;
1515
use syntax_pos::{Span, MultiSpan};
16-
use syntax::ast;
1716
use syntax::ast::Attribute;
1817
use syntax::errors::Applicability;
1918
use syntax::feature_gate::{GateIssue, emit_feature_err};
@@ -922,8 +921,8 @@ fn unnecessary_stable_feature_lint<'a, 'tcx>(
922921
feature: Symbol,
923922
since: Symbol
924923
) {
925-
tcx.lint_node(lint::builtin::STABLE_FEATURES,
926-
ast::CRATE_NODE_ID,
924+
tcx.lint_hir(lint::builtin::STABLE_FEATURES,
925+
hir::CRATE_HIR_ID,
927926
span,
928927
&format!("the feature `{}` has been stable since {} and no longer requires \
929928
an attribute to enable", feature, since));

src/librustc/traits/specialize/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(
334334
FutureCompatOverlapErrorKind::Issue33140 =>
335335
lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS,
336336
};
337-
tcx.struct_span_lint_node(
337+
tcx.struct_span_lint_hir(
338338
lint,
339-
tcx.hir().as_local_node_id(impl_def_id).unwrap(),
339+
tcx.hir().as_local_hir_id(impl_def_id).unwrap(),
340340
impl_span,
341341
&msg)
342342
} else {

src/librustc/ty/context.rs

+6-27
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use std::sync::mpsc;
6565
use std::sync::Arc;
6666
use std::marker::PhantomData;
6767
use rustc_target::spec::abi;
68-
use syntax::ast::{self, NodeId};
68+
use syntax::ast;
6969
use syntax::attr;
7070
use syntax::source_map::MultiSpan;
7171
use syntax::edition::Edition;
@@ -2836,14 +2836,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28362836
self.struct_span_lint_hir(lint, hir_id, span.into(), msg).emit()
28372837
}
28382838

2839-
pub fn lint_node<S: Into<MultiSpan>>(self,
2840-
lint: &'static Lint,
2841-
id: NodeId,
2842-
span: S,
2843-
msg: &str) {
2844-
self.struct_span_lint_node(lint, id, span.into(), msg).emit()
2845-
}
2846-
28472839
pub fn lint_hir_note<S: Into<MultiSpan>>(self,
28482840
lint: &'static Lint,
28492841
hir_id: HirId,
@@ -2866,7 +2858,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28662858
err.emit()
28672859
}
28682860

2869-
pub fn lint_level_at_node(self, lint: &'static Lint, mut id: NodeId)
2861+
pub fn lint_level_at_node(self, lint: &'static Lint, mut id: hir::HirId)
28702862
-> (lint::Level, lint::LintSource)
28712863
{
28722864
// 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> {
28802872
self.dep_graph.with_ignore(|| {
28812873
let sets = self.lint_levels(LOCAL_CRATE);
28822874
loop {
2883-
let hir_id = self.hir().definitions().node_to_hir_id(id);
2884-
if let Some(pair) = sets.level_and_source(lint, hir_id, self.sess) {
2875+
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {
28852876
return pair
28862877
}
2887-
let next = self.hir().get_parent_node(id);
2878+
let next = self.hir().get_parent_node_by_hir_id(id);
28882879
if next == id {
28892880
bug!("lint traversal reached the root of the crate");
28902881
}
@@ -2900,23 +2891,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
29002891
msg: &str)
29012892
-> DiagnosticBuilder<'tcx>
29022893
{
2903-
let node_id = self.hir().hir_to_node_id(hir_id);
2904-
let (level, src) = self.lint_level_at_node(lint, node_id);
2905-
lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg)
2906-
}
2907-
2908-
pub fn struct_span_lint_node<S: Into<MultiSpan>>(self,
2909-
lint: &'static Lint,
2910-
id: NodeId,
2911-
span: S,
2912-
msg: &str)
2913-
-> DiagnosticBuilder<'tcx>
2914-
{
2915-
let (level, src) = self.lint_level_at_node(lint, id);
2894+
let (level, src) = self.lint_level_at_node(lint, hir_id);
29162895
lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg)
29172896
}
29182897

2919-
pub fn struct_lint_node(self, lint: &'static Lint, id: NodeId, msg: &str)
2898+
pub fn struct_lint_node(self, lint: &'static Lint, id: HirId, msg: &str)
29202899
-> DiagnosticBuilder<'tcx>
29212900
{
29222901
let (level, src) = self.lint_level_at_node(lint, id);

src/librustc_mir/hair/pattern/check_match.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
346346
NotUseful => {
347347
match source {
348348
hir::MatchSource::IfLetDesugar { .. } => {
349-
cx.tcx.lint_node(
349+
cx.tcx.lint_hir(
350350
lint::builtin::IRREFUTABLE_LET_PATTERNS,
351-
hir_pat.id,
351+
hir_pat.hir_id,
352352
pat.span,
353353
"irrefutable if-let pattern",
354354
);
@@ -359,16 +359,16 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
359359
match arm_index {
360360
// The arm with the user-specified pattern.
361361
0 => {
362-
cx.tcx.lint_node(
362+
cx.tcx.lint_hir(
363363
lint::builtin::UNREACHABLE_PATTERNS,
364-
hir_pat.id, pat.span,
364+
hir_pat.hir_id, pat.span,
365365
"unreachable pattern");
366366
},
367367
// The arm with the wildcard pattern.
368368
1 => {
369-
cx.tcx.lint_node(
369+
cx.tcx.lint_hir(
370370
lint::builtin::IRREFUTABLE_LET_PATTERNS,
371-
hir_pat.id,
371+
hir_pat.hir_id,
372372
pat.span,
373373
"irrefutable while-let pattern",
374374
);
@@ -379,9 +379,9 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
379379

380380
hir::MatchSource::ForLoopDesugar |
381381
hir::MatchSource::Normal => {
382-
let mut err = cx.tcx.struct_span_lint_node(
382+
let mut err = cx.tcx.struct_span_lint_hir(
383383
lint::builtin::UNREACHABLE_PATTERNS,
384-
hir_pat.id,
384+
hir_pat.hir_id,
385385
pat.span,
386386
"unreachable pattern",
387387
);

src/librustc_mir/hair/pattern/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
955955
debug!("const_to_pat: cv.ty={:?} span={:?}", cv.ty, span);
956956
let kind = match cv.ty.sty {
957957
ty::Float(_) => {
958-
let id = self.tcx.hir().hir_to_node_id(id);
959-
self.tcx.lint_node(
958+
self.tcx.lint_hir(
960959
::rustc::lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
961960
id,
962961
span,

src/librustc_mir/lints.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'a, 'tcx, 'tcx>,
129129
// no break */ }`) shouldn't be linted unless it actually
130130
// recurs.
131131
if !reached_exit_without_self_call && !self_call_locations.is_empty() {
132-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
132+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
133133
let sp = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(hir_id));
134-
let mut db = tcx.struct_span_lint_node(UNCONDITIONAL_RECURSION,
135-
node_id,
136-
sp,
137-
"function cannot return without recursing");
134+
let mut db = tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION,
135+
hir_id,
136+
sp,
137+
"function cannot return without recursing");
138138
db.span_label(sp, "cannot return without recursing");
139139
// offer some help to the programmer.
140140
for location in &self_call_locations {

src/librustc_mir/transform/check_unsafety.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,8 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
553553
}
554554

555555
fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
556-
let lint_node_id = match tcx.hir().as_local_node_id(def_id) {
557-
Some(node_id) => node_id,
558-
None => bug!("checking unsafety for non-local def id {:?}", def_id)
559-
};
556+
let lint_hir_id = tcx.hir().as_local_hir_id(def_id).unwrap_or_else(||
557+
bug!("checking unsafety for non-local def id {:?}", def_id));
560558

561559
// FIXME: when we make this a hard error, this should have its
562560
// own error code.
@@ -567,10 +565,10 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
567565
"#[derive] can't be used on a #[repr(packed)] struct that \
568566
does not derive Copy (error E0133)".to_string()
569567
};
570-
tcx.lint_node(SAFE_PACKED_BORROWS,
571-
lint_node_id,
572-
tcx.def_span(def_id),
573-
&message);
568+
tcx.lint_hir(SAFE_PACKED_BORROWS,
569+
lint_hir_id,
570+
tcx.def_span(def_id),
571+
&message);
574572
}
575573

576574
/// Returns the `HirId` for an enclosing scope that is also `unsafe`.

src/librustc_mir/transform/const_prop.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,10 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
603603
.unwrap()
604604
.source_info
605605
.span;
606-
let node_id = self
606+
let hir_id = self
607607
.tcx
608608
.hir()
609-
.as_local_node_id(self.source.def_id())
609+
.as_local_hir_id(self.source.def_id())
610610
.expect("some part of a failing const eval must be local");
611611
use rustc::mir::interpret::EvalErrorKind::*;
612612
let msg = match msg {
@@ -643,9 +643,9 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
643643
// Need proper const propagator for these
644644
_ => return,
645645
};
646-
self.tcx.lint_node(
646+
self.tcx.lint_hir(
647647
::rustc::lint::builtin::CONST_ERR,
648-
node_id,
648+
hir_id,
649649
span,
650650
&msg,
651651
);

src/librustc_privacy/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1539,12 +1539,12 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
15391539

15401540
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
15411541
if self.leaks_private_dep(def_id) {
1542-
self.tcx.lint_node(lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
1543-
self.item_id,
1544-
self.span,
1545-
&format!("{} `{}` from private dependency '{}' in public \
1546-
interface", kind, descr,
1547-
self.tcx.crate_name(def_id.krate)));
1542+
self.tcx.lint_hir(lint::builtin::EXPORTED_PRIVATE_DEPENDENCIES,
1543+
self.item_id,
1544+
self.span,
1545+
&format!("{} `{}` from private dependency '{}' in public \
1546+
interface", kind, descr,
1547+
self.tcx.crate_name(def_id.krate)));
15481548

15491549
}
15501550

@@ -1567,8 +1567,8 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
15671567
err.emit();
15681568
} else {
15691569
let err_code = if kind == "trait" { "E0445" } else { "E0446" };
1570-
self.tcx.lint_node(lint::builtin::PRIVATE_IN_PUBLIC, node_id, self.span,
1571-
&format!("{} (error {})", msg, err_code));
1570+
self.tcx.lint_hir(lint::builtin::PRIVATE_IN_PUBLIC, hir_id, self.span,
1571+
&format!("{} (error {})", msg, err_code));
15721572
}
15731573

15741574
}

src/librustc_typeck/check_unused.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ struct CheckVisitor<'a, 'tcx: 'a> {
5151
}
5252

5353
impl<'a, 'tcx> CheckVisitor<'a, 'tcx> {
54-
fn check_import(&self, id: ast::NodeId, span: Span) {
55-
let def_id = self.tcx.hir().local_def_id(id);
54+
fn check_import(&self, id: hir::HirId, span: Span) {
55+
let def_id = self.tcx.hir().local_def_id_from_hir_id(id);
5656
if !self.tcx.maybe_unused_trait_import(def_id) {
5757
return;
5858
}
5959

60-
let import_def_id = self.tcx.hir().local_def_id(id);
61-
if self.used_trait_imports.contains(&import_def_id) {
60+
if self.used_trait_imports.contains(&def_id) {
6261
return;
6362
}
6463

@@ -67,7 +66,7 @@ impl<'a, 'tcx> CheckVisitor<'a, 'tcx> {
6766
} else {
6867
"unused import".to_owned()
6968
};
70-
self.tcx.lint_node(lint::builtin::UNUSED_IMPORTS, id, span, &msg);
69+
self.tcx.lint_hir(lint::builtin::UNUSED_IMPORTS, id, span, &msg);
7170
}
7271
}
7372

@@ -121,8 +120,8 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
121120
});
122121

123122
for extern_crate in &crates_to_lint {
124-
let id = tcx.hir().as_local_node_id(extern_crate.def_id).unwrap();
125-
let item = tcx.hir().expect_item(id);
123+
let id = tcx.hir().as_local_hir_id(extern_crate.def_id).unwrap();
124+
let item = tcx.hir().expect_item_by_hir_id(id);
126125

127126
// If the crate is fully unused, we suggest removing it altogether.
128127
// We do this in any edition.
@@ -135,7 +134,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
135134
.map(|attr| attr.span)
136135
.fold(span, |acc, attr_span| acc.to(attr_span));
137136

138-
tcx.struct_span_lint_node(lint, id, span, msg)
137+
tcx.struct_span_lint_hir(lint, id, span, msg)
139138
.span_suggestion_short(
140139
span_with_attrs,
141140
"remove it",
@@ -177,7 +176,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
177176
None => format!("use {};", item.ident.name),
178177
};
179178
let replacement = visibility_qualified(&item.vis, base_replacement);
180-
tcx.struct_span_lint_node(lint, id, extern_crate.span, msg)
179+
tcx.struct_span_lint_hir(lint, id, extern_crate.span, msg)
181180
.span_suggestion_short(
182181
extern_crate.span,
183182
&help,

src/librustc_typeck/coherence/inherent_impls_overlap.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ impl<'a, 'tcx> InherentOverlapChecker<'a, 'tcx> {
3636

3737
for &item2 in &impl_items2[..] {
3838
if (name, namespace) == name_and_namespace(item2) {
39-
let node_id = self.tcx.hir().as_local_node_id(impl1);
40-
let mut err = if used_to_be_allowed && node_id.is_some() {
41-
self.tcx.struct_span_lint_node(
39+
let hir_id = self.tcx.hir().as_local_hir_id(impl1);
40+
let mut err = if used_to_be_allowed && hir_id.is_some() {
41+
self.tcx.struct_span_lint_hir(
4242
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
43-
node_id.unwrap(),
43+
hir_id.unwrap(),
4444
self.tcx.span_of_impl(item1).unwrap(),
4545
&format!("duplicate definitions with name `{}` (E0592)", name)
4646
)

src/librustdoc/passes/collect_intra_doc_links.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,9 @@ fn resolution_failure(
473473
) {
474474
let sp = span_of_attrs(attrs);
475475

476-
let mut diag = cx.tcx.struct_span_lint_node(
476+
let mut diag = cx.tcx.struct_span_lint_hir(
477477
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
478-
NodeId::from_u32(0),
478+
hir::CRATE_HIR_ID,
479479
sp,
480480
&format!("`[{}]` cannot be resolved, ignoring it...", path_str),
481481
);

src/librustdoc/passes/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! Contains information about "passes", used to modify crate information during the documentation
22
//! process.
33
4+
use rustc::hir;
45
use rustc::hir::def_id::DefId;
56
use rustc::lint as lint;
67
use rustc::middle::privacy::AccessLevels;
78
use rustc::util::nodemap::DefIdSet;
89
use std::mem;
9-
use syntax::ast::NodeId;
1010
use syntax_pos::{DUMMY_SP, Span};
1111
use std::ops::Range;
1212

@@ -312,18 +312,18 @@ pub fn look_for_tests<'a, 'tcx: 'a, 'rcx: 'a>(
312312

313313
if find_testable_code(&dox, &mut tests, ErrorCodes::No).is_ok() {
314314
if check_missing_code == true && tests.found_tests == 0 {
315-
let mut diag = cx.tcx.struct_span_lint_node(
315+
let mut diag = cx.tcx.struct_span_lint_hir(
316316
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
317-
NodeId::from_u32(0),
317+
hir::CRATE_HIR_ID,
318318
span_of_attrs(&item.attrs),
319319
"Missing code example in this documentation");
320320
diag.emit();
321321
} else if check_missing_code == false &&
322322
tests.found_tests > 0 &&
323323
!cx.renderinfo.borrow().access_levels.is_doc_reachable(item.def_id) {
324-
let mut diag = cx.tcx.struct_span_lint_node(
324+
let mut diag = cx.tcx.struct_span_lint_hir(
325325
lint::builtin::PRIVATE_DOC_TESTS,
326-
NodeId::from_u32(0),
326+
hir::CRATE_HIR_ID,
327327
span_of_attrs(&item.attrs),
328328
"Documentation test in private item");
329329
diag.emit();

0 commit comments

Comments
 (0)