Skip to content

Commit

Permalink
Rollup merge of #108133 - kylematsuda:earlybinder-cleanups, r=compile…
Browse files Browse the repository at this point in the history
…r-errors

Small cleanups around `EarlyBinder`

Cleaning up a few things that were brought up by `@lcnr` in reviewing #106696:

- [make `issue33140_self_ty` query return `Option<EarlyBinder<Ty>>`](#106696 (comment))
- [small style improvement](#106696 (comment))
  • Loading branch information
matthiaskrgr authored Feb 16, 2023
2 parents 9b2ee41 + 382ade6 commit e1e58fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,8 +1541,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.tables.impl_defaultness.set_some(def_id.index, *defaultness);
self.tables.constness.set_some(def_id.index, *constness);

let trait_ref = self.tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::skip_binder);
let trait_ref = self.tcx.impl_trait_ref(def_id);
if let Some(trait_ref) = trait_ref {
let trait_ref = trait_ref.skip_binder();
let trait_def = self.tcx.trait_def(trait_ref.def_id);
if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) {
if let Some(specialization_graph::Node::Impl(parent)) = an.nth(1) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ rustc_queries! {
separate_provide_extern
}

query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
query issue33140_self_ty(key: DefId) -> Option<ty::EarlyBinder<ty::Ty<'tcx>>> {
desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
}

Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir;
use rustc_index::bit_set::BitSet;
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
use rustc_middle::ty::{
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::{DefId, CRATE_DEF_ID};
use rustc_trait_selection::traits;
Expand Down Expand Up @@ -355,7 +357,7 @@ fn instance_def_size_estimate<'tcx>(
/// If `def_id` is an issue 33140 hack impl, returns its self type; otherwise, returns `None`.
///
/// See [`ty::ImplOverlapKind::Issue33140`] for more details.
fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'_>>> {
debug!("issue33140_self_ty({:?})", def_id);

let trait_ref = tcx
Expand Down Expand Up @@ -394,7 +396,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {

if self_ty_matches {
debug!("issue33140_self_ty - MATCHES!");
Some(self_ty)
Some(EarlyBinder(self_ty))
} else {
debug!("issue33140_self_ty - non-matching self type");
None
Expand Down

0 comments on commit e1e58fc

Please sign in to comment.