Skip to content

Commit f62c6e1

Browse files
committed
librustc_middle: return LocalDefId instead of DefId in body_owner_def_id
1 parent 1dc363b commit f62c6e1

File tree

13 files changed

+30
-32
lines changed

13 files changed

+30
-32
lines changed

src/librustc_infer/infer/error_reporting/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5959
use rustc_errors::{pluralize, struct_span_err};
6060
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6161
use rustc_hir as hir;
62-
use rustc_hir::def_id::{DefId, LocalDefId};
62+
use rustc_hir::def_id::DefId;
6363
use rustc_hir::Node;
6464
use rustc_middle::middle::region;
6565
use rustc_middle::ty::error::TypeError;
@@ -1589,16 +1589,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15891589
// it's a actual definition. According to the comments (e.g. in
15901590
// librustc_typeck/check/compare_method.rs:compare_predicate_entailment) the latter
15911591
// is relied upon by some other code. This might (or might not) need cleanup.
1592-
let body_owner_def_id = self
1593-
.tcx
1594-
.hir()
1595-
.opt_local_def_id(cause.body_id)
1596-
.map(LocalDefId::to_def_id)
1597-
.unwrap_or_else(|| {
1592+
let body_owner_def_id =
1593+
self.tcx.hir().opt_local_def_id(cause.body_id).unwrap_or_else(|| {
15981594
self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
15991595
});
16001596
self.check_and_note_conflicting_crates(diag, terr);
1601-
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id);
1597+
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id.to_def_id());
16021598

16031599
// It reads better to have the error origin as the final
16041600
// thing.

src/librustc_interface/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
812812
{
813813
sess.time("match_checking", || {
814814
tcx.par_body_owners(|def_id| {
815-
tcx.ensure().check_match(def_id);
815+
tcx.ensure().check_match(def_id.to_def_id());
816816
});
817817
});
818818
},
@@ -834,7 +834,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
834834
});
835835

836836
sess.time("MIR_borrow_checking", || {
837-
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
837+
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id.to_def_id()));
838838
});
839839

840840
sess.time("dumping_chalk_like_clauses", || {
@@ -843,7 +843,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
843843

844844
sess.time("MIR_effect_checking", || {
845845
for def_id in tcx.body_owners() {
846-
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
846+
mir::transform::check_unsafety::check_unsafety(tcx, def_id.to_def_id())
847847
}
848848
});
849849

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ declare_lint_pass!(
11661166
);
11671167

11681168
fn check_const(cx: &LateContext<'_, '_>, body_id: hir::BodyId) {
1169-
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
1169+
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
11701170
// trigger the query once for all constants since that will already report the errors
11711171
// FIXME: Use ensure here
11721172
let _ = cx.tcx.const_eval_poly(def_id);

src/librustc_middle/hir/map/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,8 @@ impl<'hir> Map<'hir> {
370370
parent
371371
}
372372

373-
// FIXME(eddyb) this function can and should return `LocalDefId`.
374-
pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
375-
self.local_def_id(self.body_owner(id))
373+
pub fn body_owner_def_id(&self, id: BodyId) -> LocalDefId {
374+
self.local_def_id(self.body_owner(id)).expect_local()
376375
}
377376

378377
/// Given a `HirId`, returns the `BodyId` associated with it,

src/librustc_middle/ty/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2678,21 +2678,21 @@ pub enum ImplOverlapKind {
26782678

26792679
impl<'tcx> TyCtxt<'tcx> {
26802680
pub fn body_tables(self, body: hir::BodyId) -> &'tcx TypeckTables<'tcx> {
2681-
self.typeck_tables_of(self.hir().body_owner_def_id(body))
2681+
self.typeck_tables_of(self.hir().body_owner_def_id(body).to_def_id())
26822682
}
26832683

26842684
/// Returns an iterator of the `DefId`s for all body-owners in this
26852685
/// crate. If you would prefer to iterate over the bodies
26862686
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
2687-
pub fn body_owners(self) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'tcx {
2687+
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + Captures<'tcx> + 'tcx {
26882688
self.hir()
26892689
.krate()
26902690
.body_ids
26912691
.iter()
26922692
.map(move |&body_id| self.hir().body_owner_def_id(body_id))
26932693
}
26942694

2695-
pub fn par_body_owners<F: Fn(DefId) + sync::Sync + sync::Send>(self, f: F) {
2695+
pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F) {
26962696
par_iter(&self.hir().krate().body_ids)
26972697
.for_each(|&body_id| f(self.hir().body_owner_def_id(body_id)));
26982698
}

src/librustc_mir/transform/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{shim, util};
22
use rustc_ast::ast;
33
use rustc_hir as hir;
4-
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LOCAL_CRATE};
4+
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LocalDefId, LOCAL_CRATE};
55
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
66
use rustc_index::vec::IndexVec;
77
use rustc_middle::mir::{BodyAndCache, ConstQualifs, MirPhase, Promoted};
@@ -62,7 +62,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
6262
let mut set = DefIdSet::default();
6363

6464
// All body-owners have MIR associated with them.
65-
set.extend(tcx.body_owners());
65+
set.extend(tcx.body_owners().map(LocalDefId::to_def_id));
6666

6767
// Additionally, tuple struct/variant constructors have MIR, but
6868
// they don't have a BodyId, so we need to build them separately.

src/librustc_passes/intrinsicck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl Visitor<'tcx> for ItemVisitor<'tcx> {
131131
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
132132
let owner_def_id = self.tcx.hir().body_owner_def_id(body_id);
133133
let body = self.tcx.hir().body(body_id);
134-
let param_env = self.tcx.param_env(owner_def_id);
135-
let tables = self.tcx.typeck_tables_of(owner_def_id);
134+
let param_env = self.tcx.param_env(owner_def_id.to_def_id());
135+
let tables = self.tcx.typeck_tables_of(owner_def_id.to_def_id());
136136
ExprVisitor { tcx: self.tcx, param_env, tables }.visit_body(body);
137137
self.visit_body(body);
138138
}

src/librustc_trait_selection/traits/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::infer::{self, InferCtxt, TyCtxtInferExt};
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
1616
use rustc_hir as hir;
17-
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
17+
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1818
use rustc_hir::{Node, QPath, TyKind, WhereBoundPredicate, WherePredicate};
1919
use rustc_middle::mir::interpret::ErrorHandled;
2020
use rustc_middle::ty::error::ExpectedFound;
@@ -354,12 +354,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
354354
let enclosing_scope_span = tcx.def_span(
355355
tcx.hir()
356356
.opt_local_def_id(obligation.cause.body_id)
357-
.map(LocalDefId::to_def_id)
358357
.unwrap_or_else(|| {
359358
tcx.hir().body_owner_def_id(hir::BodyId {
360359
hir_id: obligation.cause.body_id,
361360
})
362-
}),
361+
})
362+
.to_def_id(),
363363
);
364364

365365
err.span_label(enclosing_scope_span, s.as_str());

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: DefId) {
751751
fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) {
752752
debug_assert!(crate_num == LOCAL_CRATE);
753753
tcx.par_body_owners(|body_owner_def_id| {
754-
tcx.ensure().typeck_tables_of(body_owner_def_id);
754+
tcx.ensure().typeck_tables_of(body_owner_def_id.to_def_id());
755755
});
756756
}
757757

src/librustc_typeck/check/regionck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ macro_rules! ignore_err {
109109

110110
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
111111
pub fn regionck_expr(&self, body: &'tcx hir::Body<'tcx>) {
112-
let subject = self.tcx.hir().body_owner_def_id(body.id());
112+
let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
113113
let id = body.value.hir_id;
114114
let mut rcx =
115115
RegionCtxt::new(self, RepeatingScope(id), id, Subject(subject), self.param_env);
@@ -154,7 +154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
154154
/// constraints to add.
155155
pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) {
156156
debug!("regionck_fn(id={})", fn_id);
157-
let subject = self.tcx.hir().body_owner_def_id(body.id());
157+
let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
158158
let hir_id = body.value.hir_id;
159159
let mut rcx =
160160
RegionCtxt::new(self, RepeatingScope(hir_id), hir_id, Subject(subject), self.param_env);
@@ -290,7 +290,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
290290

291291
let body_id = body.id();
292292
self.body_id = body_id.hir_id;
293-
self.body_owner = self.tcx.hir().body_owner_def_id(body_id);
293+
self.body_owner = self.tcx.hir().body_owner_def_id(body_id).to_def_id();
294294

295295
let call_site =
296296
region::Scope { id: body.value.hir_id.local_id, data: region::ScopeData::CallSite };

src/librustc_typeck/check/upvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
146146
}
147147
}
148148

149-
let body_owner_def_id = self.tcx.hir().body_owner_def_id(body.id());
149+
let body_owner_def_id = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
150150
assert_eq!(body_owner_def_id, closure_def_id);
151151
let mut delegate = InferBorrowKind {
152152
fcx: self,

src/librustc_typeck/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
1212
let mut used_trait_imports = DefIdSet::default();
1313
for &body_id in tcx.hir().krate().bodies.keys() {
1414
let item_def_id = tcx.hir().body_owner_def_id(body_id);
15-
let imports = tcx.used_trait_imports(item_def_id);
15+
let imports = tcx.used_trait_imports(item_def_id.to_def_id());
1616
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
1717
used_trait_imports.extend(imports.iter());
1818
}

src/librustdoc/clean/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ impl Clean<Lifetime> for hir::GenericParam<'_> {
419419
impl Clean<Constant> for hir::ConstArg {
420420
fn clean(&self, cx: &DocContext<'_>) -> Constant {
421421
Constant {
422-
type_: cx.tcx.type_of(cx.tcx.hir().body_owner_def_id(self.value.body)).clean(cx),
422+
type_: cx
423+
.tcx
424+
.type_of(cx.tcx.hir().body_owner_def_id(self.value.body).to_def_id())
425+
.clean(cx),
423426
expr: print_const_expr(cx, self.value.body),
424427
value: None,
425428
is_literal: is_literal_expr(cx, self.value.body.hir_id),

0 commit comments

Comments
 (0)