Skip to content

rustdoc: Get TyCtxt from self instead of passing as argument in AutoTraitFinder #82597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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;

@@ -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))
})
}
}
27 changes: 12 additions & 15 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
@@ -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))
@@ -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>,
@@ -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()
@@ -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");
@@ -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,
};
@@ -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())))
@@ -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)