Skip to content

Commit 747d449

Browse files
committed
blanket impls uwu
1 parent a1c5cab commit 747d449

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
@@ -590,7 +590,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
590590
| ty::Bound(_, _) => bug!("unexpected self type: {self_ty}"),
591591
}
592592

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

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

+20
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,26 @@ where
886886
};
887887

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

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)