Skip to content

Commit f22378f

Browse files
committed
blanket impls uwu
1 parent 7540f59 commit f22378f

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,10 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
953953
}
954954

955955
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
956-
debug_assert!(!r.is_bound(), "Should not be resolving bound region.");
957-
self.fcx.tcx.lifetimes.re_erased
956+
match r.kind() {
957+
ty::ReBound(..) => r,
958+
_ => self.fcx.tcx.lifetimes.re_erased,
959+
}
958960
}
959961

960962
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
589589
| ty::Bound(_, _) => bug!("unexpected self type: {self_ty}"),
590590
}
591591

592-
let trait_impls = tcx.trait_impls_of(trait_def_id);
592+
#[allow(rustc::usage_of_type_ir_traits)]
593+
self.for_each_blanket_impl(trait_def_id, f)
594+
}
595+
fn for_each_blanket_impl(self, trait_def_id: DefId, mut f: impl FnMut(DefId)) {
596+
let trait_impls = self.trait_impls_of(trait_def_id);
593597
for &impl_def_id in trait_impls.blanket_impls() {
594598
f(impl_def_id);
595599
}

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,26 @@ where
885885
};
886886

887887
let mut candidates = vec![];
888+
889+
let cx = self.cx();
890+
cx.for_each_blanket_impl(goal.predicate.trait_def_id(cx), |impl_def_id| {
891+
// For every `default impl`, there's always a non-default `impl`
892+
// that will *also* apply. There's no reason to register a candidate
893+
// for this impl, since it is *not* proof that the trait goal holds.
894+
if cx.impl_is_default(impl_def_id) {
895+
return;
896+
}
897+
898+
match G::consider_impl_candidate(self, goal, impl_def_id) {
899+
Ok(mut candidate) => {
900+
candidate.result.value.certainty =
901+
candidate.result.value.certainty.and(Certainty::AMBIGUOUS);
902+
candidates.push(candidate);
903+
}
904+
Err(NoSolution) => (),
905+
}
906+
});
907+
888908
for item_bound in
889909
self.cx().item_self_bounds(alias_ty.def_id).iter_instantiated(self.cx(), alias_ty.args)
890910
{

compiler/rustc_type_ir/src/interner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ pub trait Interner:
290290
self_ty: Self::Ty,
291291
f: impl FnMut(Self::DefId),
292292
);
293+
fn for_each_blanket_impl(self, trait_def_id: Self::DefId, f: impl FnMut(Self::DefId));
293294

294295
fn has_item_definition(self, def_id: Self::DefId) -> bool;
295296

0 commit comments

Comments
 (0)