Skip to content

Commit c15e13a

Browse files
committed
Remove DUMMY_HIR_ID
1 parent b9161ab commit c15e13a

File tree

9 files changed

+13
-64
lines changed

9 files changed

+13
-64
lines changed

src/librustc_hir/definitions.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
pub use crate::def_id::DefPathHash;
88
use crate::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
99
use crate::hir;
10-
use crate::hir_id::DUMMY_HIR_ID;
1110

1211
use rustc_ast::ast;
1312
use rustc_ast::crate_disambiguator::CrateDisambiguator;
@@ -345,8 +344,7 @@ impl Definitions {
345344
#[inline]
346345
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<hir::HirId> {
347346
if let Some(def_id) = def_id.as_local() {
348-
let hir_id = self.local_def_id_to_hir_id(def_id);
349-
if hir_id != DUMMY_HIR_ID { Some(hir_id) } else { None }
347+
Some(self.local_def_id_to_hir_id(def_id))
350348
} else {
351349
None
352350
}

src/librustc_hir/hir_id.rs

-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,4 @@ pub const CRATE_HIR_ID: HirId = HirId {
4545
local_id: ItemLocalId::from_u32(0),
4646
};
4747

48-
pub const DUMMY_HIR_ID: HirId =
49-
HirId { owner: LocalDefId { local_def_index: CRATE_DEF_INDEX }, local_id: DUMMY_ITEM_LOCAL_ID };
50-
5148
pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;

src/librustc_middle/hir/map/collector.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,16 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
250250
None => format!("{:?}", node),
251251
};
252252

253-
let forgot_str = if hir_id == hir::DUMMY_HIR_ID {
254-
format!("\nMaybe you forgot to lower the node id {:?}?", node_id)
255-
} else {
256-
String::new()
257-
};
258-
259253
span_bug!(
260254
span,
261255
"inconsistent DepNode at `{:?}` for `{}`: \
262-
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
256+
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
263257
self.source_map.span_to_string(span),
264258
node_str,
265259
self.definitions.def_path(self.current_dep_node_owner).to_string_no_crate(),
266260
self.current_dep_node_owner,
267261
self.definitions.def_path(hir_id.owner).to_string_no_crate(),
268262
hir_id.owner,
269-
forgot_str,
270263
)
271264
}
272265
}

src/librustc_middle/middle/stability.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ fn late_report_deprecation(
215215
suggestion: Option<Symbol>,
216216
lint: &'static Lint,
217217
span: Span,
218-
def_id: DefId,
219218
hir_id: HirId,
220219
) {
221220
if span.in_derive_expansion() {
@@ -229,9 +228,6 @@ fn late_report_deprecation(
229228
}
230229
diag.emit()
231230
});
232-
if hir_id == hir::DUMMY_HIR_ID {
233-
span_bug!(span, "emitted a {} lint with dummy HIR id: {:?}", lint.name, def_id);
234-
}
235231
}
236232

237233
/// Result of `TyCtxt::eval_stability`.
@@ -296,7 +292,7 @@ impl<'tcx> TyCtxt<'tcx> {
296292
if !skip {
297293
let (message, lint) =
298294
deprecation_message(&depr_entry.attr, &self.def_path_str(def_id));
299-
late_report_deprecation(self, &message, None, lint, span, def_id, id);
295+
late_report_deprecation(self, &message, None, lint, span, id);
300296
}
301297
};
302298
}
@@ -319,15 +315,7 @@ impl<'tcx> TyCtxt<'tcx> {
319315
if let Some(depr) = &stability.rustc_depr {
320316
let (message, lint) =
321317
rustc_deprecation_message(depr, &self.def_path_str(def_id));
322-
late_report_deprecation(
323-
self,
324-
&message,
325-
depr.suggestion,
326-
lint,
327-
span,
328-
def_id,
329-
id,
330-
);
318+
late_report_deprecation(self, &message, depr.suggestion, lint, span, id);
331319
}
332320
}
333321
}

src/librustc_passes/hir_id_validator.rs

-10
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,6 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
143143
fn visit_id(&mut self, hir_id: HirId) {
144144
let owner = self.owner.expect("no owner");
145145

146-
if hir_id == hir::DUMMY_HIR_ID {
147-
self.error(|| {
148-
format!(
149-
"HirIdValidator: HirId {:?} is invalid",
150-
self.hir_map.node_to_string(hir_id)
151-
)
152-
});
153-
return;
154-
}
155-
156146
if owner != hir_id.owner {
157147
self.error(|| {
158148
format!(

src/librustc_resolve/late/lifetimes.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2704,14 +2704,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27042704
}
27052705

27062706
fn insert_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime, def: Region) {
2707-
if lifetime_ref.hir_id == hir::DUMMY_HIR_ID {
2708-
span_bug!(
2709-
lifetime_ref.span,
2710-
"lifetime reference not renumbered, \
2711-
probably a bug in rustc_ast::fold"
2712-
);
2713-
}
2714-
27152707
debug!(
27162708
"insert_lifetime: {} resolved to {:?} span={:?}",
27172709
self.tcx.hir().node_to_string(lifetime_ref.hir_id),

src/librustc_typeck/check/method/probe.rs

-3
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
860860
&mut self,
861861
expr_hir_id: hir::HirId,
862862
) -> Result<(), MethodError<'tcx>> {
863-
if expr_hir_id == hir::DUMMY_HIR_ID {
864-
return Ok(());
865-
}
866863
let mut duplicates = FxHashSet::default();
867864
let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_id);
868865
if let Some(applicable_traits) = opt_applicable_traits {

src/librustdoc/clean/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,16 @@ impl<'tcx> Clean<Option<Vec<GenericBound>>> for InternalSubsts<'tcx> {
375375

376376
impl Clean<Lifetime> for hir::Lifetime {
377377
fn clean(&self, cx: &DocContext<'_>) -> Lifetime {
378-
if self.hir_id != hir::DUMMY_HIR_ID {
379-
let def = cx.tcx.named_region(self.hir_id);
380-
match def {
381-
Some(rl::Region::EarlyBound(_, node_id, _))
382-
| Some(rl::Region::LateBound(_, node_id, _))
383-
| Some(rl::Region::Free(_, node_id)) => {
384-
if let Some(lt) = cx.lt_substs.borrow().get(&node_id).cloned() {
385-
return lt;
386-
}
378+
let def = cx.tcx.named_region(self.hir_id);
379+
match def {
380+
Some(rl::Region::EarlyBound(_, node_id, _))
381+
| Some(rl::Region::LateBound(_, node_id, _))
382+
| Some(rl::Region::Free(_, node_id)) => {
383+
if let Some(lt) = cx.lt_substs.borrow().get(&node_id).cloned() {
384+
return lt;
387385
}
388-
_ => {}
389386
}
387+
_ => {}
390388
}
391389
Lifetime(self.name.ident().to_string())
392390
}

src/librustdoc/clean/utils.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,7 @@ pub fn print_const_expr(cx: &DocContext<'_>, body: hir::BodyId) -> String {
580580

581581
/// Given a type Path, resolve it to a Type using the TyCtxt
582582
pub fn resolve_type(cx: &DocContext<'_>, path: Path, id: hir::HirId) -> Type {
583-
if id == hir::DUMMY_HIR_ID {
584-
debug!("resolve_type({:?})", path);
585-
} else {
586-
debug!("resolve_type({:?},{:?})", path, id);
587-
}
583+
debug!("resolve_type({:?},{:?})", path, id);
588584

589585
let is_generic = match path.res {
590586
Res::PrimTy(p) => return Primitive(PrimitiveType::from(p)),

0 commit comments

Comments
 (0)