Skip to content

Commit c066564

Browse files
committed
blanket impls uwu
1 parent b744518 commit c066564

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

compiler/rustc_hir_typeck/src/writeback.rs

+4-2
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

+5-1
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

+20
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,26 @@ where
884884
};
885885

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

compiler/rustc_type_ir/src/interner.rs

+1
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)