Skip to content

Commit

Permalink
Get TyCtxt from self instead of passing as argument in AutoTraitFinder
Browse files Browse the repository at this point in the history
methods
  • Loading branch information
noslaver committed Mar 1, 2021
1 parent 5233edc commit 854fffd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
ty: Ty<'tcx>,
orig_env: ty::ParamEnv<'tcx>,
trait_did: DefId,
mut auto_trait_callback: impl FnMut(&InferCtxt<'_, 'tcx>, AutoTraitInfo<'tcx>) -> A,
mut auto_trait_callback: impl FnMut(AutoTraitInfo<'tcx>) -> A,
) -> AutoTraitResult<A> {
let tcx = self.tcx;

Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {

let info = AutoTraitInfo { full_user_env, region_data, vid_to_region };

AutoTraitResult::PositiveImpl(auto_trait_callback(&infcx, info))
AutoTraitResult::PositiveImpl(auto_trait_callback(info))
})
}
}
Expand Down
27 changes: 12 additions & 15 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
return None;
}

let result = f.find_auto_trait_generics(ty, param_env, trait_def_id, |infcx, info| {
let result = f.find_auto_trait_generics(ty, param_env, trait_def_id, |info| {
let region_data = info.region_data;

let names_map = tcx
Expand All @@ -61,7 +61,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.collect();
let lifetime_predicates = Self::handle_lifetimes(&region_data, &names_map);
let new_generics = self.param_env_to_generics(
infcx.tcx,
item_def_id,
info.full_user_env,
lifetime_predicates,
Expand Down Expand Up @@ -313,12 +312,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
lifetime_predicates
}

fn extract_for_generics(
&self,
tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>,
) -> FxHashSet<GenericParamDef> {
fn extract_for_generics(&self, pred: ty::Predicate<'tcx>) -> FxHashSet<GenericParamDef> {
let bound_predicate = pred.kind();
let tcx = self.cx.tcx;
let regions = match bound_predicate.skip_binder() {
ty::PredicateKind::Trait(poly_trait_pred, _) => {
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))
Expand Down Expand Up @@ -443,7 +439,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
// * We explicitly add a '?Sized' bound if we didn't find any 'Sized' predicates for a type
fn param_env_to_generics(
&mut self,
tcx: TyCtxt<'tcx>,
item_def_id: DefId,
param_env: ty::ParamEnv<'tcx>,
mut existing_predicates: Vec<WherePredicate>,
Expand All @@ -455,14 +450,15 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
item_def_id, param_env, existing_predicates
);

let tcx = self.cx.tcx;

// The `Sized` trait must be handled specially, since we only display it when
// it is *not* required (i.e., '?Sized')
let sized_trait = self.cx.tcx.require_lang_item(LangItem::Sized, None);
let sized_trait = tcx.require_lang_item(LangItem::Sized, None);

let mut replacer = RegionReplacer { vid_to_region: &vid_to_region, tcx };

let orig_bounds: FxHashSet<_> =
self.cx.tcx.param_env(item_def_id).caller_bounds().iter().collect();
let orig_bounds: FxHashSet<_> = tcx.param_env(item_def_id).caller_bounds().iter().collect();
let clean_where_predicates = param_env
.caller_bounds()
.iter()
Expand Down Expand Up @@ -512,7 +508,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
continue;
}

let mut for_generics = self.extract_for_generics(tcx, orig_p);
let mut for_generics = self.extract_for_generics(orig_p);

assert!(bounds.len() == 1);
let mut b = bounds.pop().expect("bounds were empty");
Expand Down Expand Up @@ -541,7 +537,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
// that we don't end up with duplicate bounds (e.g., for<'b, 'b>)
for_generics.extend(p.generic_params.clone());
p.generic_params = for_generics.into_iter().collect();
self.is_fn_ty(tcx, &p.trait_)
self.is_fn_ty(&p.trait_)
}
_ => false,
};
Expand Down Expand Up @@ -576,7 +572,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
} => {
let mut new_trait_path = trait_path.clone();

if self.is_fn_ty(tcx, trait_) && left_name == sym::Output {
if self.is_fn_ty(trait_) && left_name == sym::Output {
ty_to_fn
.entry(*ty.clone())
.and_modify(|e| *e = (e.0.clone(), Some(rhs.clone())))
Expand Down Expand Up @@ -734,7 +730,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
vec.sort_by_cached_key(|x| format!("{:?}", x))
}

fn is_fn_ty(&self, tcx: TyCtxt<'_>, ty: &Type) -> bool {
fn is_fn_ty(&self, ty: &Type) -> bool {
let tcx = self.cx.tcx;
match ty {
&Type::ResolvedPath { did, .. } => {
did == tcx.require_lang_item(LangItem::Fn, None)
Expand Down

0 comments on commit 854fffd

Please sign in to comment.