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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 7 deletions
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

Lines changed: 4 additions & 9 deletions
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

Lines changed: 5 additions & 7 deletions
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

Lines changed: 5 additions & 7 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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
}

0 commit comments

Comments
 (0)