Skip to content

Commit 1985bbd

Browse files
committed
chore: update next-solver to 0.166
1 parent ffc3232 commit 1985bbd

5 files changed

Lines changed: 95 additions & 59 deletions

File tree

Cargo.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
8686
vfs = { path = "./crates/vfs", version = "0.0.0" }
8787
edition = { path = "./crates/edition", version = "0.0.0" }
8888

89-
ra-ap-rustc_lexer = { version = "0.165", default-features = false }
90-
ra-ap-rustc_parse_format = { version = "0.165", default-features = false }
91-
ra-ap-rustc_index = { version = "0.165", default-features = false }
92-
ra-ap-rustc_abi = { version = "0.165", default-features = false }
93-
ra-ap-rustc_pattern_analysis = { version = "0.165", default-features = false }
94-
ra-ap-rustc_ast_ir = { version = "0.165", default-features = false }
95-
ra-ap-rustc_type_ir = { version = "0.165", default-features = false }
96-
ra-ap-rustc_next_trait_solver = { version = "0.165", default-features = false }
89+
ra-ap-rustc_lexer = { version = "0.166", default-features = false }
90+
ra-ap-rustc_parse_format = { version = "0.166", default-features = false }
91+
ra-ap-rustc_index = { version = "0.166", default-features = false }
92+
ra-ap-rustc_abi = { version = "0.166", default-features = false }
93+
ra-ap-rustc_pattern_analysis = { version = "0.166", default-features = false }
94+
ra-ap-rustc_ast_ir = { version = "0.166", default-features = false }
95+
ra-ap-rustc_type_ir = { version = "0.166", default-features = false }
96+
ra-ap-rustc_next_trait_solver = { version = "0.166", default-features = false }
9797

9898
# local crates that aren't published to crates.io. These should not have versions.
9999

crates/hir-ty/src/method_resolution.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use hir_def::{
3131
};
3232
use rustc_hash::{FxHashMap, FxHashSet};
3333
use rustc_type_ir::{
34-
TypeVisitableExt,
34+
TypeVisitableExt, VisitorResult,
3535
fast_reject::{TreatParams, simplify_type},
3636
inherent::{BoundExistentialPredicates, IntoKind},
3737
};
@@ -54,6 +54,7 @@ use crate::{
5454
obligation_ctxt::ObligationCtxt,
5555
util::clauses_as_obligations,
5656
},
57+
ret,
5758
traits::ParamEnvAndCrate,
5859
};
5960

@@ -835,27 +836,34 @@ impl<'db> TraitImpls<'db> {
835836
}
836837
}
837838

838-
pub fn for_each_crate_and_block(
839+
pub fn for_each_crate_and_block<R: VisitorResult>(
839840
db: &'db dyn HirDatabase,
840841
krate: Crate,
841842
block: Option<BlockIdLt<'db>>,
842-
for_each: &mut dyn FnMut(&TraitImpls<'db>),
843-
) {
843+
for_each: &mut dyn FnMut(&TraitImpls<'db>) -> R,
844+
) -> R {
844845
let blocks = std::iter::successors(block, |block| block.module(db).block(db));
845-
blocks.filter_map(|block| Self::for_block(db, block)).for_each(&mut *for_each);
846-
Self::for_crate_and_deps(db, krate).iter().map(|it| &**it).for_each(for_each);
846+
for impl_ in blocks.filter_map(|block| Self::for_block(db, block)) {
847+
ret!(for_each(impl_));
848+
}
849+
for impl_ in Self::for_crate_and_deps(db, krate) {
850+
ret!(for_each(impl_));
851+
}
852+
R::output()
847853
}
848854

849855
/// Like [`Self::for_each_crate_and_block()`], but takes in account two blocks, one for a trait and one for a self type.
850-
pub fn for_each_crate_and_block_trait_and_type(
856+
pub fn for_each_crate_and_block_trait_and_type<R: VisitorResult>(
851857
db: &'db dyn HirDatabase,
852858
krate: Crate,
853859
type_block: Option<BlockIdLt<'db>>,
854860
trait_block: Option<BlockIdLt<'db>>,
855-
for_each: &mut dyn FnMut(&TraitImpls<'db>),
856-
) {
861+
for_each: &mut dyn FnMut(&TraitImpls<'db>) -> R,
862+
) -> R {
857863
let in_self_and_deps = TraitImpls::for_crate_and_deps(db, krate);
858-
in_self_and_deps.iter().for_each(|impls| for_each(impls));
864+
for impl_ in in_self_and_deps {
865+
ret!(for_each(impl_));
866+
}
859867

860868
// We must not provide duplicate impls to the solver. Therefore we work with the following strategy:
861869
// start from each block, and walk ancestors until you meet the other block. If they never meet,
@@ -874,13 +882,20 @@ impl<'db> TraitImpls<'db> {
874882
.filter_map(move |block| TraitImpls::for_block(db, block))
875883
};
876884
if trait_block == type_block {
877-
blocks_iter(trait_block)
878-
.filter_map(|block| TraitImpls::for_block(db, block))
879-
.for_each(for_each);
885+
for impl_ in
886+
blocks_iter(trait_block).filter_map(|block| TraitImpls::for_block(db, block))
887+
{
888+
ret!(for_each(impl_));
889+
}
880890
} else {
881-
for_each_block(trait_block, type_block).for_each(&mut *for_each);
882-
for_each_block(type_block, trait_block).for_each(for_each);
891+
for impl_ in for_each_block(trait_block, type_block) {
892+
ret!(for_each(impl_));
893+
}
894+
for impl_ in for_each_block(type_block, trait_block) {
895+
ret!(for_each(impl_));
896+
}
883897
}
898+
R::output()
884899
}
885900
}
886901

crates/hir-ty/src/next_solver/interner.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_index::bit_set::DenseBitSet;
2929
use rustc_type_ir::{
3030
AliasTy, BoundVar, CoroutineWitnessTypes, DebruijnIndex, EarlyBinder, FlagComputation, Flags,
3131
FnSigKind, GenericArgKind, GenericTypeVisitable, ImplPolarity, InferTy, Interner, TraitRef,
32-
TypeFlags, TypeVisitableExt, Upcast, Variance,
32+
TypeFlags, TypeVisitableExt, Upcast, Variance, VisitorResult,
3333
elaborate::elaborate,
3434
error::TypeError,
3535
fast_reject,
@@ -54,6 +54,7 @@ use crate::{
5454
TraitAssocTyId, TraitIdWrapper, TypeAliasIdWrapper, UnevaluatedConst, Unnormalized,
5555
util::{explicit_item_bounds, explicit_item_self_bounds},
5656
},
57+
ret,
5758
};
5859

5960
use super::{
@@ -1601,12 +1602,12 @@ impl<'db> Interner for DbInterner<'db> {
16011602
def_id.0.trait_items(self.db()).associated_types().map(|id| id.into())
16021603
}
16031604

1604-
fn for_each_relevant_impl(
1605+
fn for_each_relevant_impl<R: VisitorResult>(
16051606
self,
16061607
trait_def_id: Self::TraitId,
16071608
self_ty: Self::Ty,
1608-
mut f: impl FnMut(Self::ImplId),
1609-
) {
1609+
mut f: impl FnMut(Self::ImplId) -> R,
1610+
) -> R {
16101611
let krate = self.krate.expect("trait solving requires setting `DbInterner::krate`");
16111612
let trait_block = trait_def_id.0.loc(self.db).container.block(self.db);
16121613
let mut consider_impls_for_simplified_type = |simp: SimplifiedType<'_>| {
@@ -1641,13 +1642,14 @@ impl<'db> Interner for DbInterner<'db> {
16411642
let (regular_impls, builtin_derive_impls) =
16421643
impls.for_trait_and_self_ty(trait_def_id.0, &simp);
16431644
for &impl_ in regular_impls {
1644-
f(impl_.into());
1645+
ret!(f(impl_.into()));
16451646
}
16461647
for &impl_ in builtin_derive_impls {
1647-
f(impl_.into());
1648+
ret!(f(impl_.into()));
16481649
}
1650+
R::output()
16491651
},
1650-
);
1652+
)
16511653
};
16521654

16531655
match self_ty.kind() {
@@ -1676,7 +1678,7 @@ impl<'db> Interner for DbInterner<'db> {
16761678
let simp =
16771679
fast_reject::simplify_type(self, self_ty, fast_reject::TreatParams::AsRigid)
16781680
.unwrap();
1679-
consider_impls_for_simplified_type(simp);
1681+
ret!(consider_impls_for_simplified_type(simp));
16801682
}
16811683

16821684
// HACK: For integer and float variables we have to manually look at all impls
@@ -1704,7 +1706,7 @@ impl<'db> Interner for DbInterner<'db> {
17041706
SimplifiedType::Uint(Usize),
17051707
];
17061708
for simp in possible_integers {
1707-
consider_impls_for_simplified_type(simp);
1709+
ret!(consider_impls_for_simplified_type(simp));
17081710
}
17091711
}
17101712

@@ -1719,7 +1721,7 @@ impl<'db> Interner for DbInterner<'db> {
17191721
];
17201722

17211723
for simp in possible_floats {
1722-
consider_impls_for_simplified_type(simp);
1724+
ret!(consider_impls_for_simplified_type(simp));
17231725
}
17241726
}
17251727

@@ -1748,15 +1750,22 @@ impl<'db> Interner for DbInterner<'db> {
17481750
self.for_each_blanket_impl(trait_def_id, f)
17491751
}
17501752

1751-
fn for_each_blanket_impl(self, trait_def_id: Self::TraitId, mut f: impl FnMut(Self::ImplId)) {
1752-
let Some(krate) = self.krate else { return };
1753+
fn for_each_blanket_impl<R: VisitorResult>(
1754+
self,
1755+
trait_def_id: Self::TraitId,
1756+
mut f: impl FnMut(Self::ImplId) -> R,
1757+
) -> R {
1758+
let Some(krate) = self.krate else {
1759+
return R::output();
1760+
};
17531761
let block = trait_def_id.0.loc(self.db).container.block(self.db);
17541762

17551763
TraitImpls::for_each_crate_and_block(self.db, krate, block, &mut |impls| {
17561764
for &impl_ in impls.blanket_impls(trait_def_id.0) {
1757-
f(impl_.into());
1765+
ret!(f(impl_.into()));
17581766
}
1759-
});
1767+
R::output()
1768+
})
17601769
}
17611770

17621771
fn has_item_definition(self, _def_id: Self::ImplOrTraitAssocTermId) -> bool {

crates/hir-ty/src/next_solver/util.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,15 @@ pub(crate) fn clauses_as_obligations<'db>(
723723
recursion_depth: 0,
724724
})
725725
}
726+
727+
/// Copied from
728+
/// <https://github.com/jdonszelmann/rust/blob/180725cff61d00dd1b9c35fc720a8befaec5d46b/compiler/rustc_middle/src/ty/context/impl_interner.rs#L534-L541>
729+
#[macro_export]
730+
macro_rules! ret {
731+
($e: expr) => {
732+
match $e.branch() {
733+
::std::ops::ControlFlow::Break(b) => return R::from_residual(b),
734+
::std::ops::ControlFlow::Continue(()) => {}
735+
}
736+
};
737+
}

0 commit comments

Comments
 (0)