Skip to content
Closed
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
Only calculate trait_ref.self_ty() once in get_blanket_impls
On crates with many blanket impls, such as `stm32`, this inner closure
is executed many hundreds of thousands of times. This makes it very
slightly faster.

Unfortunately, I don't have a good test case for showing that it's
faster until rust-lang/rustc-perf#802 is merged.
  • Loading branch information
jyn514 committed Mar 7, 2021
commit 8b5bc9521cd148210eb4b2275e85b6ec26ba9786
7 changes: 4 additions & 3 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
trait_def_id, impl_def_id
);
let trait_ref = self.cx.tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ty = trait_ref.self_ty();
let may_apply = self.cx.tcx.infer_ctxt().enter(|infcx| {
match trait_ref.self_ty().kind() {
match trait_ty.kind() {
ty::Param(_) => {}
_ => return false,
}
Expand All @@ -48,7 +49,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
// Require the type the impl is implemented on to match
// our type, and ignore the impl if there was a mismatch.
let cause = traits::ObligationCause::dummy();
let eq_result = infcx.at(&cause, param_env).eq(trait_ref.self_ty(), ty);
let eq_result = infcx.at(&cause, param_env).eq(trait_ty, ty);
if let Ok(InferOk { value: (), obligations }) = eq_result {
// FIXME(eddyb) ignoring `obligations` might cause false positives.
drop(obligations);
Expand Down Expand Up @@ -128,7 +129,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.clean(self.cx),
negative_polarity: false,
synthetic: false,
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
blanket_impl: Some(trait_ty.clean(self.cx)),
}),
});
});
Expand Down