Rollup merge of #82597 - noslaver:fix-82137, r=nagisa
Get TyCtxt from self instead of passing as argument in AutoTraitFinder First contribution 🦀, let me know if anything is amiss. Fix #82137.
This commit is contained in:
commit
43bcfdb0d0
@ -77,7 +77,7 @@ pub fn find_auto_trait_generics<A>(
|
||||
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;
|
||||
|
||||
@ -211,7 +211,7 @@ pub fn find_auto_trait_generics<A>(
|
||||
|
||||
let info = AutoTraitInfo { full_user_env, region_data, vid_to_region };
|
||||
|
||||
AutoTraitResult::PositiveImpl(auto_trait_callback(&infcx, info))
|
||||
AutoTraitResult::PositiveImpl(auto_trait_callback(info))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ fn generate_for_trait(
|
||||
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
|
||||
@ -61,7 +61,6 @@ fn generate_for_trait(
|
||||
.collect();
|
||||
let lifetime_predicates = Self::handle_lifetimes(®ion_data, &names_map);
|
||||
let new_generics = self.param_env_to_generics(
|
||||
infcx.tcx,
|
||||
item_def_id,
|
||||
info.full_user_env,
|
||||
lifetime_predicates,
|
||||
@ -313,12 +312,9 @@ fn handle_lifetimes<'cx>(
|
||||
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))
|
||||
@ -443,7 +439,6 @@ fn make_final_bounds(
|
||||
// * 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>,
|
||||
@ -455,14 +450,15 @@ fn param_env_to_generics(
|
||||
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()
|
||||
@ -512,7 +508,7 @@ fn param_env_to_generics(
|
||||
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");
|
||||
@ -541,7 +537,7 @@ fn param_env_to_generics(
|
||||
// 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,
|
||||
};
|
||||
@ -576,7 +572,7 @@ fn param_env_to_generics(
|
||||
} => {
|
||||
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())))
|
||||
@ -734,7 +730,8 @@ fn unstable_debug_sort<T: Debug>(&self, vec: &mut Vec<T>) {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user