-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove unnecessary self_ty
parameter to get_blanket_impls
#81349
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
ty: Ty<'tcx>, | ||
trait_def_id: DefId, | ||
param_env: ty::ParamEnv<'tcx>, | ||
param_env_def_id: DefId, | ||
item_def_id: DefId, | ||
f: &auto_trait::AutoTraitFinder<'tcx>, | ||
// If this is set, show only negative trait implementations, not positive ones. | ||
discard_positive_impl: bool, | ||
|
@@ -50,7 +50,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
let region_data = info.region_data; | ||
|
||
let names_map = tcx | ||
.generics_of(param_env_def_id) | ||
.generics_of(item_def_id) | ||
.params | ||
.iter() | ||
.filter_map(|param| match param.kind { | ||
|
@@ -62,16 +62,16 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
let lifetime_predicates = Self::handle_lifetimes(®ion_data, &names_map); | ||
let new_generics = self.param_env_to_generics( | ||
infcx.tcx, | ||
param_env_def_id, | ||
item_def_id, | ||
info.full_user_env, | ||
lifetime_predicates, | ||
info.vid_to_region, | ||
); | ||
|
||
debug!( | ||
"find_auto_trait_generics(param_env_def_id={:?}, trait_def_id={:?}): \ | ||
"find_auto_trait_generics(item_def_id={:?}, trait_def_id={:?}): \ | ||
finished with {:?}", | ||
param_env_def_id, trait_def_id, new_generics | ||
item_def_id, trait_def_id, new_generics | ||
); | ||
|
||
new_generics | ||
|
@@ -101,7 +101,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
// Instead, we generate `impl !Send for Foo<T>`, which better | ||
// expresses the fact that `Foo<T>` never implements `Send`, | ||
// regardless of the choice of `T`. | ||
let params = (tcx.generics_of(param_env_def_id), ty::GenericPredicates::default()) | ||
let params = (tcx.generics_of(item_def_id), ty::GenericPredicates::default()) | ||
.clean(self.cx) | ||
.params; | ||
|
||
|
@@ -115,7 +115,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
name: None, | ||
attrs: Default::default(), | ||
visibility: Inherited, | ||
def_id: self.cx.next_def_id(param_env_def_id.krate), | ||
def_id: self.cx.next_def_id(item_def_id.krate), | ||
kind: box ImplItem(Impl { | ||
unsafety: hir::Unsafety::Normal, | ||
generics: new_generics, | ||
|
@@ -130,26 +130,25 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
}) | ||
} | ||
|
||
// FIXME(eddyb) figure out a better way to pass information about | ||
// parametrization of `ty` than `param_env_def_id`. | ||
crate fn get_auto_trait_impls(&mut self, ty: Ty<'tcx>, param_env_def_id: DefId) -> Vec<Item> { | ||
crate fn get_auto_trait_impls(&mut self, item_def_id: DefId) -> Vec<Item> { | ||
let tcx = self.cx.tcx; | ||
let param_env = tcx.param_env(param_env_def_id); | ||
let f = auto_trait::AutoTraitFinder::new(self.cx.tcx); | ||
let param_env = tcx.param_env(item_def_id); | ||
let ty = tcx.type_of(item_def_id); | ||
let f = auto_trait::AutoTraitFinder::new(tcx); | ||
|
||
debug!("get_auto_trait_impls({:?})", ty); | ||
let auto_traits: Vec<_> = self.cx.auto_traits.iter().cloned().collect(); | ||
let mut auto_traits: Vec<Item> = auto_traits | ||
.into_iter() | ||
.filter_map(|trait_def_id| { | ||
self.generate_for_trait(ty, trait_def_id, param_env, param_env_def_id, &f, false) | ||
self.generate_for_trait(ty, trait_def_id, param_env, item_def_id, &f, false) | ||
}) | ||
.collect(); | ||
// We are only interested in case the type *doesn't* implement the Sized trait. | ||
if !ty.is_sized(self.cx.tcx.at(rustc_span::DUMMY_SP), param_env) { | ||
if !ty.is_sized(tcx.at(rustc_span::DUMMY_SP), param_env) { | ||
// In case `#![no_core]` is used, `sized_trait` returns nothing. | ||
if let Some(item) = self.cx.tcx.lang_items().sized_trait().and_then(|sized_trait_did| { | ||
self.generate_for_trait(ty, sized_trait_did, param_env, param_env_def_id, &f, true) | ||
if let Some(item) = tcx.lang_items().sized_trait().and_then(|sized_trait_did| { | ||
self.generate_for_trait(ty, sized_trait_did, param_env, item_def_id, &f, true) | ||
}) { | ||
auto_traits.push(item); | ||
} | ||
|
@@ -445,15 +444,15 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
fn param_env_to_generics( | ||
&mut self, | ||
tcx: TyCtxt<'tcx>, | ||
param_env_def_id: DefId, | ||
item_def_id: DefId, | ||
Comment on lines
-448
to
+447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this change made? Did the meaning change, or is Sorry for all the questions; I know almost nothing about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as it did before, all this does is rename the parameter and move the |
||
param_env: ty::ParamEnv<'tcx>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Same here as #81349 (comment).) |
||
mut existing_predicates: Vec<WherePredicate>, | ||
vid_to_region: FxHashMap<ty::RegionVid, ty::Region<'tcx>>, | ||
) -> Generics { | ||
debug!( | ||
"param_env_to_generics(param_env_def_id={:?}, param_env={:?}, \ | ||
"param_env_to_generics(item_def_id={:?}, param_env={:?}, \ | ||
existing_predicates={:?})", | ||
param_env_def_id, param_env, existing_predicates | ||
item_def_id, param_env, existing_predicates | ||
); | ||
|
||
// The `Sized` trait must be handled specially, since we only display it when | ||
|
@@ -463,7 +462,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
let mut replacer = RegionReplacer { vid_to_region: &vid_to_region, tcx }; | ||
|
||
let orig_bounds: FxHashSet<_> = | ||
self.cx.tcx.param_env(param_env_def_id).caller_bounds().iter().collect(); | ||
self.cx.tcx.param_env(item_def_id).caller_bounds().iter().collect(); | ||
let clean_where_predicates = param_env | ||
.caller_bounds() | ||
.iter() | ||
|
@@ -477,14 +476,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
.map(|p| p.fold_with(&mut replacer)); | ||
|
||
let mut generic_params = | ||
(tcx.generics_of(param_env_def_id), tcx.explicit_predicates_of(param_env_def_id)) | ||
(tcx.generics_of(item_def_id), tcx.explicit_predicates_of(item_def_id)) | ||
.clean(self.cx) | ||
.params; | ||
|
||
debug!( | ||
"param_env_to_generics({:?}): generic_params={:?}", | ||
param_env_def_id, generic_params | ||
); | ||
debug!("param_env_to_generics({:?}): generic_params={:?}", item_def_id, generic_params); | ||
|
||
let mut has_sized = FxHashSet::default(); | ||
let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default(); | ||
|
@@ -648,13 +644,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { | |
.or_default() | ||
.insert(*trait_.clone()); | ||
} | ||
_ => panic!( | ||
"Unexpected trait {:?} for {:?}", | ||
trait_, param_env_def_id, | ||
), | ||
_ => panic!("Unexpected trait {:?} for {:?}", trait_, item_def_id), | ||
} | ||
} | ||
_ => panic!("Unexpected LHS {:?} for {:?}", lhs, param_env_def_id), | ||
_ => panic!("Unexpected LHS {:?} for {:?}", lhs, item_def_id), | ||
} | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this still take a
param_env
given that the other places calltcx.param_env
on theitem_def_id
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added after I opened the original PR, I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, actually this is called in a loop, I don't know if it makes sense to change. It will have to lookup the type/param_env each time, even though it's memoized that still has overhead.