Skip to content

Commit 800d2e3

Browse files
authored
Rollup merge of #73796 - lcnr:LocalDefId, r=matthewjasper
replace more `DefId`s with `LocalDefId` part of #70853
2 parents 596af5a + 2d280a5 commit 800d2e3

File tree

19 files changed

+304
-301
lines changed

19 files changed

+304
-301
lines changed

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

+19-22
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,27 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2828
br: &ty::BoundRegion,
2929
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
31-
let def_id = anon_reg.def_id;
32-
if let Some(def_id) = def_id.as_local() {
33-
let hir_id = self.tcx().hir().as_local_hir_id(def_id);
34-
let fndecl = match self.tcx().hir().get(hir_id) {
35-
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
36-
| Node::TraitItem(&hir::TraitItem {
37-
kind: hir::TraitItemKind::Fn(ref m, ..),
38-
..
39-
})
40-
| Node::ImplItem(&hir::ImplItem {
41-
kind: hir::ImplItemKind::Fn(ref m, ..),
42-
..
43-
}) => &m.decl,
44-
_ => return None,
45-
};
31+
let hir_id = self.tcx().hir().as_local_hir_id(anon_reg.def_id);
32+
let fndecl = match self.tcx().hir().get(hir_id) {
33+
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
34+
| Node::TraitItem(&hir::TraitItem {
35+
kind: hir::TraitItemKind::Fn(ref m, ..),
36+
..
37+
})
38+
| Node::ImplItem(&hir::ImplItem {
39+
kind: hir::ImplItemKind::Fn(ref m, ..), ..
40+
}) => &m.decl,
41+
_ => return None,
42+
};
4643

47-
return fndecl
48-
.inputs
49-
.iter()
50-
.find_map(|arg| self.find_component_for_bound_region(arg, br))
51-
.map(|ty| (ty, &**fndecl));
52-
}
44+
fndecl
45+
.inputs
46+
.iter()
47+
.find_map(|arg| self.find_component_for_bound_region(arg, br))
48+
.map(|ty| (ty, &**fndecl))
49+
} else {
50+
None
5351
}
54-
None
5552
}
5653

5754
// This method creates a FindNestedTypeVisitor which returns the type corresponding

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7575
}
7676

7777
if let Some((_, fndecl)) = self.find_anon_type(anon, &br) {
78-
let is_self_anon = self.is_self_anon(is_first, scope_def_id);
79-
if is_self_anon {
78+
if self.is_self_anon(is_first, scope_def_id) {
8079
return None;
8180
}
8281

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

+196-198
Large diffs are not rendered by default.

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
55
use rustc_hir as hir;
6-
use rustc_hir::def_id::DefId;
6+
use rustc_hir::def_id::LocalDefId;
77
use rustc_middle::ty::{self, DefIdTree, Region, Ty};
88
use rustc_span::Span;
99

@@ -92,7 +92,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
9292
// FIXME(#42703) - Need to handle certain cases here.
9393
pub(super) fn is_return_type_anon(
9494
&self,
95-
scope_def_id: DefId,
95+
scope_def_id: LocalDefId,
9696
br: ty::BoundRegion,
9797
decl: &hir::FnDecl<'_>,
9898
) -> Option<Span> {
@@ -112,9 +112,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
112112
// corresponds to self and if yes, we display E0312.
113113
// FIXME(#42700) - Need to format self properly to
114114
// enable E0621 for it.
115-
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
115+
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: LocalDefId) -> bool {
116116
is_first
117-
&& self.tcx().opt_associated_item(scope_def_id).map(|i| i.fn_has_self_parameter)
117+
&& self
118+
.tcx()
119+
.opt_associated_item(scope_def_id.to_def_id())
120+
.map(|i| i.fn_has_self_parameter)
118121
== Some(true)
119122
}
120123
}

src/librustc_middle/hir/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,11 @@ impl<'hir> Map<'hir> {
458458
}
459459
}
460460

461-
pub fn visit_item_likes_in_module<V>(&self, module: DefId, visitor: &mut V)
461+
pub fn visit_item_likes_in_module<V>(&self, module: LocalDefId, visitor: &mut V)
462462
where
463463
V: ItemLikeVisitor<'hir>,
464464
{
465-
let module = self.tcx.hir_module_items(module.expect_local());
465+
let module = self.tcx.hir_module_items(module);
466466

467467
for id in &module.items {
468468
visitor.visit_item(self.expect_item(*id));

src/librustc_middle/query/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use rustc_query_system::query::QueryDescription;
1515
use rustc_span::symbol::Symbol;
1616
use std::borrow::Cow;
1717

18-
fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
18+
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
1919
if def_id.is_top_level_module() {
2020
"top-level module".to_string()
2121
} else {
22-
format!("module `{}`", tcx.def_path_str(def_id))
22+
format!("module `{}`", tcx.def_path_str(def_id.to_def_id()))
2323
}
2424
}
2525

@@ -473,49 +473,49 @@ rustc_queries! {
473473

474474
Other {
475475
query lint_mod(key: LocalDefId) -> () {
476-
desc { |tcx| "linting {}", describe_as_module(key.to_def_id(), tcx) }
476+
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
477477
}
478478

479479
/// Checks the attributes in the module.
480-
query check_mod_attrs(key: DefId) -> () {
480+
query check_mod_attrs(key: LocalDefId) -> () {
481481
desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
482482
}
483483

484-
query check_mod_unstable_api_usage(key: DefId) -> () {
484+
query check_mod_unstable_api_usage(key: LocalDefId) -> () {
485485
desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
486486
}
487487

488488
/// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
489-
query check_mod_const_bodies(key: DefId) -> () {
489+
query check_mod_const_bodies(key: LocalDefId) -> () {
490490
desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
491491
}
492492

493493
/// Checks the loops in the module.
494-
query check_mod_loops(key: DefId) -> () {
494+
query check_mod_loops(key: LocalDefId) -> () {
495495
desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
496496
}
497497

498-
query check_mod_item_types(key: DefId) -> () {
498+
query check_mod_item_types(key: LocalDefId) -> () {
499499
desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
500500
}
501501

502502
query check_mod_privacy(key: LocalDefId) -> () {
503-
desc { |tcx| "checking privacy in {}", describe_as_module(key.to_def_id(), tcx) }
503+
desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
504504
}
505505

506-
query check_mod_intrinsics(key: DefId) -> () {
506+
query check_mod_intrinsics(key: LocalDefId) -> () {
507507
desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
508508
}
509509

510-
query check_mod_liveness(key: DefId) -> () {
510+
query check_mod_liveness(key: LocalDefId) -> () {
511511
desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
512512
}
513513

514-
query check_mod_impl_wf(key: DefId) -> () {
514+
query check_mod_impl_wf(key: LocalDefId) -> () {
515515
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
516516
}
517517

518-
query collect_mod_item_types(key: DefId) -> () {
518+
query collect_mod_item_types(key: LocalDefId) -> () {
519519
desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
520520
}
521521

src/librustc_middle/ty/context.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,8 @@ impl<'tcx> CommonConsts<'tcx> {
873873
// conflict.
874874
#[derive(Debug)]
875875
pub struct FreeRegionInfo {
876-
// def id corresponding to FreeRegion
877-
pub def_id: DefId,
876+
// `LocalDefId` corresponding to FreeRegion
877+
pub def_id: LocalDefId,
878878
// the bound region corresponding to FreeRegion
879879
pub boundregion: ty::BoundRegion,
880880
// checks if bound region is in Impl Item
@@ -1412,14 +1412,17 @@ impl<'tcx> TyCtxt<'tcx> {
14121412
// Returns the `DefId` and the `BoundRegion` corresponding to the given region.
14131413
pub fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
14141414
let (suitable_region_binding_scope, bound_region) = match *region {
1415-
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
1416-
ty::ReEarlyBound(ref ebr) => {
1417-
(self.parent(ebr.def_id).unwrap(), ty::BoundRegion::BrNamed(ebr.def_id, ebr.name))
1415+
ty::ReFree(ref free_region) => {
1416+
(free_region.scope.expect_local(), free_region.bound_region)
14181417
}
1418+
ty::ReEarlyBound(ref ebr) => (
1419+
self.parent(ebr.def_id).unwrap().expect_local(),
1420+
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
1421+
),
14191422
_ => return None, // not a free region
14201423
};
14211424

1422-
let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope.expect_local());
1425+
let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope);
14231426
let is_impl_item = match self.hir().find(hir_id) {
14241427
Some(Node::Item(..) | Node::TraitItem(..)) => false,
14251428
Some(Node::ImplItem(..)) => {
@@ -1436,8 +1439,11 @@ impl<'tcx> TyCtxt<'tcx> {
14361439
}
14371440

14381441
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.
1439-
pub fn return_type_impl_or_dyn_traits(&self, scope_def_id: DefId) -> Vec<&'tcx hir::Ty<'tcx>> {
1440-
let hir_id = self.hir().as_local_hir_id(scope_def_id.expect_local());
1442+
pub fn return_type_impl_or_dyn_traits(
1443+
&self,
1444+
scope_def_id: LocalDefId,
1445+
) -> Vec<&'tcx hir::Ty<'tcx>> {
1446+
let hir_id = self.hir().as_local_hir_id(scope_def_id);
14411447
let hir_output = match self.hir().get(hir_id) {
14421448
Node::Item(hir::Item {
14431449
kind:
@@ -1480,9 +1486,9 @@ impl<'tcx> TyCtxt<'tcx> {
14801486
v.0
14811487
}
14821488

1483-
pub fn return_type_impl_trait(&self, scope_def_id: DefId) -> Option<(Ty<'tcx>, Span)> {
1489+
pub fn return_type_impl_trait(&self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx>, Span)> {
14841490
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
1485-
let hir_id = self.hir().as_local_hir_id(scope_def_id.expect_local());
1491+
let hir_id = self.hir().as_local_hir_id(scope_def_id);
14861492
match self.hir().get(hir_id) {
14871493
Node::Item(item) => {
14881494
match item.kind {
@@ -1512,8 +1518,9 @@ impl<'tcx> TyCtxt<'tcx> {
15121518
}
15131519

15141520
// Checks if the bound region is in Impl Item.
1515-
pub fn is_bound_region_in_impl_item(&self, suitable_region_binding_scope: DefId) -> bool {
1516-
let container_id = self.associated_item(suitable_region_binding_scope).container.id();
1521+
pub fn is_bound_region_in_impl_item(&self, suitable_region_binding_scope: LocalDefId) -> bool {
1522+
let container_id =
1523+
self.associated_item(suitable_region_binding_scope.to_def_id()).container.id();
15171524
if self.impl_trait_ref(container_id).is_some() {
15181525
// For now, we do not try to target impls of traits. This is
15191526
// because this message is going to suggest that the user

src/librustc_mir/borrow_check/diagnostics/region_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
579579
if let (Some(f), Some(ty::RegionKind::ReStatic)) =
580580
(self.to_error_region(fr), self.to_error_region(outlived_fr))
581581
{
582-
if let Some((ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self
582+
if let Some((&ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self
583583
.infcx
584584
.tcx
585585
.is_suitable_region(f)
@@ -592,7 +592,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
592592
//
593593
// eg. check for `impl Trait + 'static` instead of `impl Trait`.
594594
let has_static_predicate = {
595-
let predicates_of = self.infcx.tcx.predicates_of(*did);
595+
let predicates_of = self.infcx.tcx.predicates_of(did);
596596
let bounds = predicates_of.instantiate(self.infcx.tcx, substs);
597597

598598
let mut found = false;
@@ -625,7 +625,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
625625
diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str));
626626
} else {
627627
// Otherwise, we should suggest adding a constraint on the return type.
628-
let span = self.infcx.tcx.def_span(*did);
628+
let span = self.infcx.tcx.def_span(did);
629629
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
630630
let suggestable_fr_name = if fr_name.was_named() {
631631
fr_name.to_string()

0 commit comments

Comments
 (0)