Skip to content

Commit

Permalink
Address comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
marmeladema committed Apr 16, 2020
1 parent 9d5e085 commit da9c867
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 104 deletions.
5 changes: 2 additions & 3 deletions src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ impl CodegenCx<'ll, 'tcx> {

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

let g = if let Some(id) =
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
{
let g = if let Some(def_id) = def_id.as_local() {
let id = self.tcx.hir().as_local_hir_id(def_id);
let llty = self.layout_of(ty).llvm_type(self);
let (g, attrs) = match self.tcx.hir().get(id) {
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
) -> Option<(&hir::Ty<'_>, &hir::FnDecl<'_>)> {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let def_id = anon_reg.def_id;
if let Some(hir_id) =
def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id))
{
if let Some(def_id) = def_id.as_local() {
let hir_id = self.tcx().hir().as_local_hir_id(def_id);
let fndecl = match self.tcx().hir().get(hir_id) {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
| Node::TraitItem(&hir::TraitItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
) = (&sub_origin, sup_region)
{
let hir = &self.tcx().hir();
if let Some(hir_id) =
free_region.scope.as_local().map(|def_id| hir.as_local_hir_id(def_id))
{
if let Some(def_id) = free_region.scope.as_local() {
let hir_id = hir.as_local_hir_id(def_id);
if let Node::Expr(Expr { kind: Closure(_, _, _, closure_span, None), .. }) =
hir.get(hir_id)
{
Expand Down
11 changes: 4 additions & 7 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
// If the trait is private, add the impl items to `private_traits` so they don't get
// reported for missing docs.
let real_trait = trait_ref.path.res.def_id();
if let Some(hir_id) =
real_trait.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = real_trait.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id);
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in items {
Expand Down Expand Up @@ -611,10 +610,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
let mut impls = HirIdSet::default();
cx.tcx.for_each_impl(debug, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
if let Some(hir_id) =
ty_def.did.as_local().map(|def_id| cx.tcx.hir().as_local_hir_id(def_id))
{
impls.insert(hir_id);
if let Some(def_id) = ty_def.did.as_local() {
impls.insert(cx.tcx.hir().as_local_hir_id(def_id));
}
}
});
Expand Down
13 changes: 4 additions & 9 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl<'hir> Map<'hir> {
}

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

pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
Expand Down Expand Up @@ -885,7 +885,7 @@ impl<'hir> Map<'hir> {
}

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

pub fn res_span(&self, res: Res) -> Option<Span> {
Expand Down Expand Up @@ -1084,11 +1084,6 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String {
}

pub fn provide(providers: &mut Providers<'_>) {
providers.def_kind = |tcx, def_id| {
if let Some(def_id) = def_id.as_local() {
tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id))
} else {
bug!("calling local def_kind query provider for upstream DefId: {:?}", def_id);
}
};
providers.def_kind =
|tcx, def_id| tcx.hir().def_kind(tcx.hir().as_local_hir_id(def_id.expect_local()));
}
12 changes: 5 additions & 7 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2284,14 +2284,13 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}

AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
if let Some(hir_id) =
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
let substs = tcx.lift(&substs).unwrap();
format!(
"[closure@{}]",
tcx.def_path_str_with_substs(def_id, substs),
tcx.def_path_str_with_substs(def_id.to_def_id(), substs),
)
} else {
format!("[closure@{:?}]", tcx.hir().span(hir_id))
Expand All @@ -2312,9 +2311,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}),

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

Expand Down
12 changes: 5 additions & 7 deletions src/librustc_middle/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,8 @@ pub trait PrettyPrinter<'tcx>:
}

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

if substs.as_generator().is_valid() {
Expand Down Expand Up @@ -668,11 +667,10 @@ pub trait PrettyPrinter<'tcx>:
p!(write("[closure"));

// FIXME(eddyb) should use `def_span`.
if let Some(hir_id) =
did.as_local().map(|did| self.tcx().hir().as_local_hir_id(did))
{
if let Some(did) = did.as_local() {
let hir_id = self.tcx().hir().as_local_hir_id(did);
if self.tcx().sess.opts.debugging_opts.span_free_formats {
p!(write("@"), print_def_path(did, substs));
p!(write("@"), print_def_path(did.to_def_id(), substs));
} else {
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
}
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
format!("`{}` would have to be valid for `{}`...", name, region_name),
);

if let Some(fn_hir_id) = self
.mir_def_id
.as_local()
.map(|def_id| self.infcx.tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = self.mir_def_id.as_local() {
let fn_hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id);
err.span_label(
drop_span,
format!(
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ fn check_recursion_limit<'tcx>(
// infinite expansion.
if adjusted_recursion_depth > *tcx.sess.recursion_limit.get() {
let error = format!("reached the recursion limit while instantiating `{}`", instance);
if let Some(hir_id) = def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) {
if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().as_local_hir_id(def_id);
tcx.sess.span_fatal(tcx.hir().span(hir_id), &error);
} else {
tcx.sess.fatal(&error);
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_passes/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,8 @@ impl DeadVisitor<'tcx> {
let inherent_impls = self.tcx.inherent_impls(def_id);
for &impl_did in inherent_impls.iter() {
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
if let Some(item_hir_id) =
item_did.as_local().map(|did| self.tcx.hir().as_local_hir_id(did))
{
if let Some(did) = item_did.as_local() {
let item_hir_id = self.tcx.hir().as_local_hir_id(did);
if self.live_symbols.contains(&item_hir_id) {
return true;
}
Expand Down
16 changes: 6 additions & 10 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,8 @@ impl VisibilityLike for Option<AccessLevel> {
const SHALLOW: bool = true;
fn new_min(find: &FindMin<'_, '_, Self>, def_id: DefId) -> Self {
cmp::min(
if let Some(hir_id) =
def_id.as_local().map(|def_id| find.tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = def_id.as_local() {
let hir_id = find.tcx.hir().as_local_hir_id(def_id);
find.access_levels.map.get(&hir_id).cloned()
} else {
Self::MAX
Expand Down Expand Up @@ -549,9 +548,8 @@ impl EmbargoVisitor<'tcx> {
if export.vis.is_accessible_from(defining_mod, self.tcx) {
if let Res::Def(def_kind, def_id) = export.res {
let vis = def_id_visibility(self.tcx, def_id).0;
if let Some(hir_id) =
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = def_id.as_local() {
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
}
}
Expand Down Expand Up @@ -914,10 +912,8 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
for export in exports.iter() {
if export.vis == ty::Visibility::Public {
if let Some(def_id) = export.res.opt_def_id() {
if let Some(hir_id) = def_id
.as_local()
.map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = def_id.as_local() {
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
self.update(hir_id, Some(AccessLevel::Exported));
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/librustc_resolve/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// In the future, this should be fixed and this error should be removed.
let def = self.map.defs.get(&lifetime.hir_id).cloned();
if let Some(Region::LateBound(_, def_id, _)) = def {
if let Some(hir_id) = def_id
.as_local()
.map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = def_id.as_local() {
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
// Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().get_parent_node(hir_id);
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
Expand Down Expand Up @@ -1559,10 +1557,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}

if let Some(parent_def_id) = self.tcx.parent(def_id) {
if let Some(parent_hir_id) = parent_def_id
.as_local()
.map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = parent_def_id.as_local() {
let parent_hir_id = self.tcx.hir().as_local_hir_id(def_id);
// lifetimes in `derive` expansions don't count (Issue #53738)
if self
.tcx
Expand Down Expand Up @@ -1954,9 +1950,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
};

let map = &self.map;
let unsubst = if let Some(id) =
def_id.as_local().map(|def_id| self.tcx.hir().as_local_hir_id(def_id))
{
let unsubst = if let Some(def_id) = def_id.as_local() {
let id = self.tcx.hir().as_local_hir_id(def_id);
&map.object_lifetime_defaults[&id]
} else {
let tcx = self.tcx;
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_trait_selection/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,9 +1036,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
// let x = || foo(); // returns the Opaque assoc with `foo`
// }
// ```
if let Some(opaque_hir_id) =
def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = def_id.as_local() {
let opaque_hir_id = tcx.hir().as_local_hir_id(def_id);
let parent_def_id = self.parent_def_id;
let def_scope_default = || {
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
Expand Down Expand Up @@ -1085,7 +1084,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
),
};
if in_definition_scope {
return self.fold_opaque_ty(ty, def_id, substs, origin);
return self.fold_opaque_ty(ty, def_id.to_def_id(), substs, origin);
}

debug!(
Expand Down
15 changes: 6 additions & 9 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,8 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(

match *terr {
TypeError::Mutability => {
if let Some(trait_m_hir_id) =
trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = trait_m.def_id.as_local() {
let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id);
let trait_m_iter = match tcx.hir().expect_trait_item(trait_m_hir_id).kind {
TraitItemKind::Fn(ref trait_m_sig, _) => trait_m_sig.decl.inputs.iter(),
_ => bug!("{:?} is not a TraitItemKind::Fn", trait_m),
Expand All @@ -438,9 +437,8 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
}
}
TypeError::Sorts(ExpectedFound { .. }) => {
if let Some(trait_m_hir_id) =
trait_m.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
{
if let Some(def_id) = trait_m.def_id.as_local() {
let trait_m_hir_id = tcx.hir().as_local_hir_id(def_id);
let (trait_m_output, trait_m_iter) =
match tcx.hir().expect_trait_item(trait_m_hir_id).kind {
TraitItemKind::Fn(ref trait_m_sig, _) => {
Expand Down Expand Up @@ -591,9 +589,8 @@ fn compare_number_of_generics<'tcx>(
if impl_count != trait_count {
err_occurred = true;

let (trait_spans, impl_trait_spans) = if let Some(trait_hir_id) =
trait_.def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id))
{
let (trait_spans, impl_trait_spans) = if let Some(def_id) = trait_.def_id.as_local() {
let trait_hir_id = tcx.hir().as_local_hir_id(def_id);
let trait_item = tcx.hir().expect_trait_item(trait_hir_id);
if trait_item.generics.params.is_empty() {
(Some(vec![trait_item.generics.span]), vec![])
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let generics = self.tcx.generics_of(table_owner.to_def_id());
let type_param = generics.type_param(param, self.tcx);
let hir = &self.tcx.hir();
if let Some(id) =
type_param.def_id.as_local().map(|def_id| hir.as_local_hir_id(def_id))
{
if let Some(def_id) = type_param.def_id.as_local() {
let id = hir.as_local_hir_id(def_id);
// Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: FooBar`,
// instead we suggest `T: Foo + Bar` in that case.
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_typeck/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
return;
}

let (local, remote) = if let Some(id) =
def_id.as_local().map(|def_id| self.tcx().hir().as_local_hir_id(def_id))
{
let (local, remote) = if let Some(def_id) = def_id.as_local() {
let id = self.tcx().hir().as_local_hir_id(def_id);
(Some(self.terms_cx.inferred_starts[&id]), None)
} else {
(None, Some(self.tcx().variances_of(def_id)))
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ pub fn build_impl(
}
}

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

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

pub fn print_inlined_const(cx: &DocContext<'_>, did: DefId) -> String {
if let Some(hir_id) = did.as_local().map(|did| cx.tcx.hir().as_local_hir_id(did)) {
if let Some(did) = did.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(did);
rustc_hir_pretty::id_to_string(&cx.tcx.hir(), hir_id)
} else {
cx.tcx.rendered_const(did)
Expand Down
Loading

0 comments on commit da9c867

Please sign in to comment.