Skip to content

Commit 3532d6e

Browse files
committed
Modify as_local_hir_id to accept a LocalDefId instead of a DefId
1 parent 3e246bb commit 3532d6e

File tree

86 files changed

+588
-447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+588
-447
lines changed

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
116116
if cx.tcx.sess.opts.share_generics() {
117117
// We are in share_generics mode.
118118

119-
if instance_def_id.is_local() {
119+
if let Some(instance_def_id) = instance_def_id.as_local() {
120120
// This is a definition from the current crate. If the
121121
// definition is unreachable for downstream crates or
122122
// the current crate does not re-export generics, the

src/librustc_codegen_llvm/consts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ impl CodegenCx<'ll, 'tcx> {
209209

210210
debug!("get_static: sym={} instance={:?}", sym, instance);
211211

212-
let g = if let Some(id) = self.tcx.hir().as_local_hir_id(def_id) {
212+
let g = if let Some(id) =
213+
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id).unwrap())
214+
{
213215
let llty = self.layout_of(ty).llvm_type(self);
214216
let (g, attrs) = match self.tcx.hir().get(id) {
215217
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ fn upstream_drop_glue_for_provider<'tcx>(
359359
}
360360

361361
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
362-
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
363-
!tcx.reachable_set(LOCAL_CRATE).contains(&hir_id)
362+
if let Some(def_id) = def_id.as_local() {
363+
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id).unwrap())
364364
} else {
365365
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
366366
}

src/librustc_hir/definitions.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,8 @@ impl Definitions {
342342
}
343343

344344
#[inline]
345-
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<hir::HirId> {
346-
if let Some(def_id) = def_id.as_local() {
347-
Some(self.local_def_id_to_hir_id(def_id))
348-
} else {
349-
None
350-
}
345+
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> Option<hir::HirId> {
346+
Some(self.local_def_id_to_hir_id(def_id))
351347
}
352348

353349
#[inline]

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn msg_span_from_early_bound_and_free_regions(
191191
let sm = tcx.sess.source_map();
192192

193193
let scope = region.free_region_binding_scope(tcx);
194-
let node = tcx.hir().as_local_hir_id(scope).unwrap();
194+
let node = tcx.hir().as_local_hir_id(scope.expect_local()).unwrap();
195195
let tag = match tcx.hir().find(node) {
196196
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
197197
Some(Node::Item(it)) => item_scope_tag(&it),
@@ -1780,10 +1780,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17801780
if !(generics.has_self && param.index == 0) {
17811781
let type_param = generics.type_param(param, self.tcx);
17821782
let hir = &self.tcx.hir();
1783-
hir.as_local_hir_id(type_param.def_id).map(|id| {
1783+
type_param.def_id.as_local().map(|def_id| {
17841784
// Get the `hir::Param` to verify whether it already has any bounds.
17851785
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
17861786
// instead we suggest `T: 'a + 'b` in that case.
1787+
let id = hir.as_local_hir_id(def_id).unwrap();
17871788
let mut has_bounds = false;
17881789
if let Node::GenericParam(param) = hir.get(id) {
17891790
has_bounds = !param.bounds.is_empty();

src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2929
) -> Option<(&hir::Ty<'_>, &hir::FnDecl<'_>)> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3131
let def_id = anon_reg.def_id;
32-
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
32+
if let Some(hir_id) =
33+
def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id).unwrap())
34+
{
3335
let fndecl = match self.tcx().hir().get(hir_id) {
3436
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
3537
| Node::TraitItem(&hir::TraitItem {

src/librustc_infer/infer/error_reporting/nice_region_error/outlives_closure.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4646
) = (&sub_origin, sup_region)
4747
{
4848
let hir = &self.tcx().hir();
49-
if let Some(hir_id) = hir.as_local_hir_id(free_region.scope) {
49+
if let Some(hir_id) =
50+
free_region.scope.as_local().map(|def_id| hir.as_local_hir_id(def_id).unwrap())
51+
{
5052
if let Node::Expr(Expr { kind: Closure(_, _, _, closure_span, None), .. }) =
5153
hir.get(hir_id)
5254
{

src/librustc_infer/infer/error_reporting/nice_region_error/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5151
};
5252

5353
let hir = &self.tcx().hir();
54-
let hir_id = hir.as_local_hir_id(id)?;
54+
let hir_id = hir.as_local_hir_id(id.as_local()?)?;
5555
let body_id = hir.maybe_body_owned_by(hir_id)?;
5656
let body = hir.body(body_id);
5757
let owner_id = hir.body_owner(body_id);

src/librustc_lint/builtin.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
436436
// If the trait is private, add the impl items to `private_traits` so they don't get
437437
// reported for missing docs.
438438
let real_trait = trait_ref.path.res.def_id();
439-
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) {
439+
if let Some(hir_id) = real_trait
440+
.as_local()
441+
.map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap())
442+
{
440443
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
441444
if let hir::VisibilityKind::Inherited = item.vis.node {
442445
for impl_item_ref in items {
@@ -609,7 +612,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
609612
let mut impls = HirIdSet::default();
610613
cx.tcx.for_each_impl(debug, |d| {
611614
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
612-
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(ty_def.did) {
615+
if let Some(hir_id) = ty_def
616+
.did
617+
.as_local()
618+
.map(|def_id| cx.tcx.hir().as_local_hir_id(def_id).unwrap())
619+
{
613620
impls.insert(hir_id);
614621
}
615622
}

src/librustc_lint/late.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_ast::ast;
1919
use rustc_ast::walk_list;
2020
use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
2121
use rustc_hir as hir;
22-
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
22+
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
2323
use rustc_hir::intravisit as hir_visit;
2424
use rustc_hir::intravisit::Visitor;
2525
use rustc_middle::hir::map::Map;
@@ -353,7 +353,7 @@ crate::late_lint_methods!(late_lint_pass_impl, [], ['tcx]);
353353

354354
fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
355355
tcx: TyCtxt<'tcx>,
356-
module_def_id: DefId,
356+
module_def_id: LocalDefId,
357357
pass: T,
358358
) {
359359
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
@@ -382,7 +382,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
382382

383383
pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
384384
tcx: TyCtxt<'tcx>,
385-
module_def_id: DefId,
385+
module_def_id: LocalDefId,
386386
builtin_lints: T,
387387
) {
388388
if tcx.sess.opts.debugging_opts.no_interleave_lints {

0 commit comments

Comments
 (0)