Skip to content

Commit fe75315

Browse files
committed
Address comments from review
1 parent bfce24a commit fe75315

File tree

20 files changed

+68
-104
lines changed

20 files changed

+68
-104
lines changed

src/librustc_codegen_llvm/consts.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ impl CodegenCx<'ll, 'tcx> {
209209

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

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

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ 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) =
33-
def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id))
34-
{
32+
if let Some(def_id) = def_id.as_local() {
33+
let hir_id = self.tcx().hir().as_local_hir_id(def_id);
3534
let fndecl = match self.tcx().hir().get(hir_id) {
3635
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
3736
| Node::TraitItem(&hir::TraitItem {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4646
) = (&sub_origin, sup_region)
4747
{
4848
let hir = &self.tcx().hir();
49-
if let Some(hir_id) =
50-
free_region.scope.as_local().map(|def_id| hir.as_local_hir_id(def_id))
51-
{
49+
if let Some(def_id) = free_region.scope.as_local() {
50+
let hir_id = hir.as_local_hir_id(def_id);
5251
if let Node::Expr(Expr { kind: Closure(_, _, _, closure_span, None), .. }) =
5352
hir.get(hir_id)
5453
{

src/librustc_lint/builtin.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,8 @@ 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) =
440-
real_trait.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id))
441-
{
439+
if let Some(def_id) = real_trait.as_local() {
440+
let hir_id = cx.tcx.hir().as_local_hir_id(def_id);
442441
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
443442
if let hir::VisibilityKind::Inherited = item.vis.node {
444443
for impl_item_ref in items {
@@ -611,10 +610,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
611610
let mut impls = HirIdSet::default();
612611
cx.tcx.for_each_impl(debug, |d| {
613612
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
614-
if let Some(hir_id) =
615-
ty_def.did.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id))
616-
{
617-
impls.insert(hir_id);
613+
if let Some(def_id) = ty_def.did.as_local() {
614+
impls.insert(cx.tcx.hir().as_local_hir_id(def_id));
618615
}
619616
}
620617
});

src/librustc_middle/hir/map/mod.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'hir> Map<'hir> {
482482
}
483483

484484
pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
485-
if let Some(id) = id.as_local() { Some(self.get(self.as_local_hir_id(id))) } else { None }
485+
id.as_local().map(|id| self.get(self.as_local_hir_id(id)))
486486
}
487487

488488
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
@@ -883,7 +883,7 @@ impl<'hir> Map<'hir> {
883883
}
884884

885885
pub fn span_if_local(&self, id: DefId) -> Option<Span> {
886-
if let Some(id) = id.as_local() { Some(self.span(self.as_local_hir_id(id))) } else { None }
886+
id.as_local().map(|id| self.span(self.as_local_hir_id(id)))
887887
}
888888

889889
pub fn res_span(&self, res: Res) -> Option<Span> {
@@ -1082,11 +1082,6 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String {
10821082
}
10831083

10841084
pub fn provide(providers: &mut Providers<'_>) {
1085-
providers.def_kind = |tcx, def_id| {
1086-
if let Some(def_id) = def_id.as_local() {
1087-
tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id))
1088-
} else {
1089-
bug!("calling local def_kind query provider for upstream DefId: {:?}", def_id);
1090-
}
1091-
};
1085+
providers.def_kind =
1086+
|tcx, def_id| tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id.expect_local()));
10921087
}

src/librustc_middle/mir/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -2338,14 +2338,13 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23382338
}
23392339

23402340
AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
2341-
if let Some(hir_id) =
2342-
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
2343-
{
2341+
if let Some(def_id) = def_id.as_local() {
2342+
let hir_id = tcx.hir().as_local_hir_id(def_id);
23442343
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
23452344
let substs = tcx.lift(&substs).unwrap();
23462345
format!(
23472346
"[closure@{}]",
2348-
tcx.def_path_str_with_substs(def_id, substs),
2347+
tcx.def_path_str_with_substs(def_id.to_def_id(), substs),
23492348
)
23502349
} else {
23512350
format!("[closure@{:?}]", tcx.hir().span(hir_id))
@@ -2366,9 +2365,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23662365
}),
23672366

23682367
AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
2369-
if let Some(hir_id) =
2370-
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
2371-
{
2368+
if let Some(def_id) = def_id.as_local() {
2369+
let hir_id = tcx.hir().as_local_hir_id(def_id);
23722370
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
23732371
let mut struct_fmt = fmt.debug_struct(&name);
23742372

src/librustc_middle/ty/print/pretty.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,8 @@ pub trait PrettyPrinter<'tcx>:
608608
}
609609

610610
// FIXME(eddyb) should use `def_span`.
611-
if let Some(hir_id) =
612-
did.as_local().map(|did| self.tcx().hir().as_local_hir_id(did))
613-
{
611+
if let Some(did) = did.as_local() {
612+
let hir_id = self.tcx().hir().as_local_hir_id(did);
614613
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
615614

616615
if substs.as_generator().is_valid() {
@@ -654,11 +653,10 @@ pub trait PrettyPrinter<'tcx>:
654653
p!(write("[closure"));
655654

656655
// FIXME(eddyb) should use `def_span`.
657-
if let Some(hir_id) =
658-
did.as_local().map(|did| self.tcx().hir().as_local_hir_id(did))
659-
{
656+
if let Some(did) = did.as_local() {
657+
let hir_id = self.tcx().hir().as_local_hir_id(did);
660658
if self.tcx().sess.opts.debugging_opts.span_free_formats {
661-
p!(write("@"), print_def_path(did, substs));
659+
p!(write("@"), print_def_path(did.to_def_id(), substs));
662660
} else {
663661
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
664662
}

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
864864
format!("`{}` would have to be valid for `{}`...", name, region_name),
865865
);
866866

867-
if let Some(fn_hir_id) = self
868-
.mir_def_id
869-
.as_local()
870-
.map(|def_id| self.infcx.tcx.hir().as_local_hir_id(def_id))
871-
{
867+
if let Some(def_id) = self.mir_def_id.as_local() {
868+
let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id);
872869
err.span_label(
873870
drop_span,
874871
format!(

src/librustc_mir/monomorphize/collector.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ fn check_recursion_limit<'tcx>(
430430
// infinite expansion.
431431
if adjusted_recursion_depth > *tcx.sess.recursion_limit.get() {
432432
let error = format!("reached the recursion limit while instantiating `{}`", instance);
433-
if let Some(hir_id) = def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) {
433+
if let Some(def_id) = def_id.as_local() {
434+
let hir_id = tcx.hir().as_local_hir_id(def_id);
434435
tcx.sess.span_fatal(tcx.hir().span(hir_id), &error);
435436
} else {
436437
tcx.sess.fatal(&error);

src/librustc_passes/dead.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,8 @@ impl DeadVisitor<'tcx> {
537537
let inherent_impls = self.tcx.inherent_impls(def_id);
538538
for &impl_did in inherent_impls.iter() {
539539
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
540-
if let Some(item_hir_id) =
541-
item_did.as_local().map(|did| self.tcx.hir().as_local_hir_id(did))
542-
{
540+
if let Some(did) = item_did.as_local() {
541+
let item_hir_id = self.tcx.hir().as_local_hir_id(did);
543542
if self.live_symbols.contains(&item_hir_id) {
544543
return true;
545544
}

src/librustc_privacy/lib.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,8 @@ impl VisibilityLike for Option<AccessLevel> {
445445
const SHALLOW: bool = true;
446446
fn new_min(find: &FindMin<'_, '_, Self>, def_id: DefId) -> Self {
447447
cmp::min(
448-
if let Some(hir_id) =
449-
def_id.as_local().map(|def_id| find.tcx.hir().as_local_hir_id(def_id))
450-
{
448+
if let Some(def_id) = def_id.as_local() {
449+
let hir_id = find.tcx.hir().as_local_hir_id(def_id);
451450
find.access_levels.map.get(&hir_id).cloned()
452451
} else {
453452
Self::MAX
@@ -549,9 +548,8 @@ impl EmbargoVisitor<'tcx> {
549548
if export.vis.is_accessible_from(defining_mod, self.tcx) {
550549
if let Res::Def(def_kind, def_id) = export.res {
551550
let vis = def_id_visibility(self.tcx, def_id).0;
552-
if let Some(hir_id) =
553-
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
554-
{
551+
if let Some(def_id) = def_id.as_local() {
552+
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
555553
self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
556554
}
557555
}
@@ -914,10 +912,8 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
914912
for export in exports.iter() {
915913
if export.vis == ty::Visibility::Public {
916914
if let Some(def_id) = export.res.opt_def_id() {
917-
if let Some(hir_id) = def_id
918-
.as_local()
919-
.map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
920-
{
915+
if let Some(def_id) = def_id.as_local() {
916+
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
921917
self.update(hir_id, Some(AccessLevel::Exported));
922918
}
923919
}

src/librustc_resolve/late/lifetimes.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
596596
// In the future, this should be fixed and this error should be removed.
597597
let def = self.map.defs.get(&lifetime.hir_id).cloned();
598598
if let Some(Region::LateBound(_, def_id, _)) = def {
599-
if let Some(hir_id) = def_id
600-
.as_local()
601-
.map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
602-
{
599+
if let Some(def_id) = def_id.as_local() {
600+
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
603601
// Ensure that the parent of the def is an item, not HRTB
604602
let parent_id = self.tcx.hir().get_parent_node(hir_id);
605603
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
@@ -1559,10 +1557,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15591557
}
15601558

15611559
if let Some(parent_def_id) = self.tcx.parent(def_id) {
1562-
if let Some(parent_hir_id) = parent_def_id
1563-
.as_local()
1564-
.map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
1565-
{
1560+
if let Some(def_id) = parent_def_id.as_local() {
1561+
let parent_hir_id = self.tcx.hir().as_local_hir_id(def_id);
15661562
// lifetimes in `derive` expansions don't count (Issue #53738)
15671563
if self
15681564
.tcx
@@ -1959,9 +1955,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19591955
};
19601956

19611957
let map = &self.map;
1962-
let unsubst = if let Some(id) =
1963-
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
1964-
{
1958+
let unsubst = if let Some(def_id) = def_id.as_local() {
1959+
let id = self.tcx.hir().as_local_hir_id(def_id);
19651960
&map.object_lifetime_defaults[&id]
19661961
} else {
19671962
let tcx = self.tcx;

src/librustc_trait_selection/opaque_types.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10361036
// let x = || foo(); // returns the Opaque assoc with `foo`
10371037
// }
10381038
// ```
1039-
if let Some(opaque_hir_id) =
1040-
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
1041-
{
1039+
if let Some(def_id) = def_id.as_local() {
1040+
let opaque_hir_id = tcx.hir().as_local_hir_id(def_id);
10421041
let parent_def_id = self.parent_def_id;
10431042
let def_scope_default = || {
10441043
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
@@ -1085,7 +1084,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10851084
),
10861085
};
10871086
if in_definition_scope {
1088-
return self.fold_opaque_ty(ty, def_id, substs, origin);
1087+
return self.fold_opaque_ty(ty, def_id.to_def_id(), substs, origin);
10891088
}
10901089

10911090
debug!(

src/librustc_typeck/check/compare_method.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,8 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
409409

410410
match *terr {
411411
TypeError::Mutability => {
412-
if let Some(trait_m_hir_id) =
413-
trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
414-
{
412+
if let Some(def_id) = trait_m.def_id.as_local() {
413+
let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id);
415414
let trait_m_iter = match tcx.hir().expect_trait_item(trait_m_hir_id).kind {
416415
TraitItemKind::Fn(ref trait_m_sig, _) => trait_m_sig.decl.inputs.iter(),
417416
_ => bug!("{:?} is not a TraitItemKind::Fn", trait_m),
@@ -438,9 +437,8 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
438437
}
439438
}
440439
TypeError::Sorts(ExpectedFound { .. }) => {
441-
if let Some(trait_m_hir_id) =
442-
trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
443-
{
440+
if let Some(def_id) = trait_m.def_id.as_local() {
441+
let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id);
444442
let (trait_m_output, trait_m_iter) =
445443
match tcx.hir().expect_trait_item(trait_m_hir_id).kind {
446444
TraitItemKind::Fn(ref trait_m_sig, _) => {
@@ -591,9 +589,8 @@ fn compare_number_of_generics<'tcx>(
591589
if impl_count != trait_count {
592590
err_occurred = true;
593591

594-
let (trait_spans, impl_trait_spans) = if let Some(trait_hir_id) =
595-
trait_.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
596-
{
592+
let (trait_spans, impl_trait_spans) = if let Some(def_id) = trait_.def_id.as_local() {
593+
let trait_hir_id = tcx.hir().as_local_hir_id(def_id);
597594
let trait_item = tcx.hir().expect_trait_item(trait_hir_id);
598595
if trait_item.generics.params.is_empty() {
599596
(Some(vec![trait_item.generics.span]), vec![])

src/librustc_typeck/check/method/suggest.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10521052
let generics = self.tcx.generics_of(table_owner.to_def_id());
10531053
let type_param = generics.type_param(param, self.tcx);
10541054
let hir = &self.tcx.hir();
1055-
if let Some(id) =
1056-
type_param.def_id.as_local().map(|def_id| hir.as_local_hir_id(def_id))
1057-
{
1055+
if let Some(def_id) = type_param.def_id.as_local() {
1056+
let id = hir.as_local_hir_id(def_id);
10581057
// Get the `hir::Param` to verify whether it already has any bounds.
10591058
// We do this to avoid suggesting code that ends up as `T: FooBar`,
10601059
// instead we suggest `T: Foo + Bar` in that case.

src/librustc_typeck/variance/constraints.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
377377
return;
378378
}
379379

380-
let (local, remote) = if let Some(id) =
381-
def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id))
382-
{
380+
let (local, remote) = if let Some(def_id) = def_id.as_local() {
381+
let id = self.tcx().hir().as_local_hir_id(def_id);
383382
(Some(self.terms_cx.inferred_starts[&id]), None)
384383
} else {
385384
(None, Some(self.tcx().variances_of(def_id)))

src/librustdoc/clean/inline.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ pub fn build_impl(
340340
}
341341
}
342342

343-
let for_ = if let Some(hir_id) = did.as_local().map(|did| tcx.hir().as_local_hir_id(did)) {
343+
let for_ = if let Some(did) = did.as_local() {
344+
let hir_id = tcx.hir().as_local_hir_id(did);
344345
match tcx.hir().expect_item(hir_id).kind {
345346
hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx),
346347
_ => panic!("did given to build_impl was not an impl"),
@@ -360,9 +361,8 @@ pub fn build_impl(
360361
}
361362

362363
let predicates = tcx.explicit_predicates_of(did);
363-
let (trait_items, generics) = if let Some(hir_id) =
364-
did.as_local().map(|did| tcx.hir().as_local_hir_id(did))
365-
{
364+
let (trait_items, generics) = if let Some(did) = did.as_local() {
365+
let hir_id = tcx.hir().as_local_hir_id(did);
366366
match tcx.hir().expect_item(hir_id).kind {
367367
hir::ItemKind::Impl { ref generics, ref items, .. } => (
368368
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
@@ -488,7 +488,8 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
488488
}
489489

490490
pub fn print_inlined_const(cx: &DocContext<'_>, did: DefId) -> String {
491-
if let Some(hir_id) = did.as_local().map(|did| cx.tcx.hir().as_local_hir_id(did)) {
491+
if let Some(did) = did.as_local() {
492+
let hir_id = cx.tcx.hir().as_local_hir_id(did);
492493
rustc_hir_pretty::id_to_string(&cx.tcx.hir(), hir_id)
493494
} else {
494495
cx.tcx.rendered_const(did)

0 commit comments

Comments
 (0)