Skip to content

Commit 830e4fd

Browse files
committed
Remove usage of DUMMY_HIR_ID in some visitors
1 parent 795fa0a commit 830e4fd

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/librustc_lint/builtin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,15 +1354,15 @@ declare_lint! {
13541354
}
13551355

13561356
pub struct UnnameableTestItems {
1357-
boundary: hir::HirId, // HirId of the item under which things are not nameable
1357+
boundary: Option<hir::HirId>, // HirId of the item under which things are not nameable
13581358
items_nameable: bool,
13591359
}
13601360

13611361
impl_lint_pass!(UnnameableTestItems => [UNNAMEABLE_TEST_ITEMS]);
13621362

13631363
impl UnnameableTestItems {
13641364
pub fn new() -> Self {
1365-
Self { boundary: hir::DUMMY_HIR_ID, items_nameable: true }
1365+
Self { boundary: None, items_nameable: true }
13661366
}
13671367
}
13681368

@@ -1372,7 +1372,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
13721372
if let hir::ItemKind::Mod(..) = it.kind {
13731373
} else {
13741374
self.items_nameable = false;
1375-
self.boundary = it.hir_id;
1375+
self.boundary = Some(it.hir_id);
13761376
}
13771377
return;
13781378
}
@@ -1385,7 +1385,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
13851385
}
13861386

13871387
fn check_item_post(&mut self, _cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
1388-
if !self.items_nameable && self.boundary == it.hir_id {
1388+
if !self.items_nameable && self.boundary == Some(it.hir_id) {
13891389
self.items_nameable = true;
13901390
}
13911391
}

src/librustc_lint/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ declare_lint! {
4343
#[derive(Copy, Clone)]
4444
pub struct TypeLimits {
4545
/// Id of the last visited negated expression
46-
negated_expr_id: hir::HirId,
46+
negated_expr_id: Option<hir::HirId>,
4747
}
4848

4949
impl_lint_pass!(TypeLimits => [UNUSED_COMPARISONS, OVERFLOWING_LITERALS]);
5050

5151
impl TypeLimits {
5252
pub fn new() -> TypeLimits {
53-
TypeLimits { negated_expr_id: hir::DUMMY_HIR_ID }
53+
TypeLimits { negated_expr_id: None }
5454
}
5555
}
5656

@@ -244,7 +244,7 @@ fn lint_int_literal<'a, 'tcx>(
244244
let int_type = t.normalize(cx.sess().target.ptr_width);
245245
let (min, max) = int_ty_range(int_type);
246246
let max = max as u128;
247-
let negative = type_limits.negated_expr_id == e.hir_id;
247+
let negative = type_limits.negated_expr_id == Some(e.hir_id);
248248

249249
// Detect literal value out of range [min, max] inclusive
250250
// avoiding use of -min to prevent overflow/panic
@@ -397,8 +397,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
397397
match e.kind {
398398
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
399399
// propagate negation, if the negation itself isn't negated
400-
if self.negated_expr_id != e.hir_id {
401-
self.negated_expr_id = expr.hir_id;
400+
if self.negated_expr_id != Some(e.hir_id) {
401+
self.negated_expr_id = Some(expr.hir_id);
402402
}
403403
}
404404
hir::ExprKind::Binary(binop, ref l, ref r) => {

src/librustc_privacy/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
10121012
struct NamePrivacyVisitor<'a, 'tcx> {
10131013
tcx: TyCtxt<'tcx>,
10141014
tables: &'a ty::TypeckTables<'tcx>,
1015-
current_item: hir::HirId,
1015+
current_item: Option<hir::HirId>,
10161016
empty_tables: &'a ty::TypeckTables<'tcx>,
10171017
}
10181018

@@ -1028,7 +1028,7 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
10281028
) {
10291029
// definition of the field
10301030
let ident = Ident::new(kw::Invalid, use_ctxt);
1031-
let current_hir = self.current_item;
1031+
let current_hir = self.current_item.unwrap();
10321032
let def_id = self.tcx.adjust_ident_and_get_scope(ident, def.did, current_hir).1;
10331033
if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) {
10341034
let label = if in_update_syntax {
@@ -1074,7 +1074,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
10741074
}
10751075

10761076
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
1077-
let orig_current_item = mem::replace(&mut self.current_item, item.hir_id);
1077+
let orig_current_item = mem::replace(&mut self.current_item, Some(item.hir_id));
10781078
let orig_tables =
10791079
mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables));
10801080
intravisit::walk_item(self, item);
@@ -2059,7 +2059,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: DefId) {
20592059
let mut visitor = NamePrivacyVisitor {
20602060
tcx,
20612061
tables: &empty_tables,
2062-
current_item: hir::DUMMY_HIR_ID,
2062+
current_item: None,
20632063
empty_tables: &empty_tables,
20642064
};
20652065
let (module, span, hir_id) = tcx.hir().get_module(module_def_id);

0 commit comments

Comments
 (0)