Skip to content

Commit a22dd55

Browse files
Prefer param-env candidates that do no inference
1 parent ac883ef commit a22dd55

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

compiler/rustc_trait_selection/src/solve/assembly.rs

+2
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
565565
) -> bool {
566566
// FIXME: implement this
567567
match (candidate.source, other.source) {
568+
(CandidateSource::ParamEnv(_), CandidateSource::ParamEnv(_)) => false,
569+
(_, CandidateSource::ParamEnv(_)) if other.result.has_only_region_constraints() => true,
568570
(CandidateSource::Impl(_), _)
569571
| (CandidateSource::ParamEnv(_), _)
570572
| (CandidateSource::AliasBound, _)

compiler/rustc_trait_selection/src/solve/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ enum SolverMode {
5252

5353
trait CanonicalResponseExt {
5454
fn has_no_inference_or_external_constraints(&self) -> bool;
55+
56+
fn has_only_region_constraints(&self) -> bool;
5557
}
5658

5759
impl<'tcx> CanonicalResponseExt for Canonical<'tcx, Response<'tcx>> {
@@ -60,6 +62,11 @@ impl<'tcx> CanonicalResponseExt for Canonical<'tcx, Response<'tcx>> {
6062
&& self.value.var_values.is_identity()
6163
&& self.value.external_constraints.opaque_types.is_empty()
6264
}
65+
66+
fn has_only_region_constraints(&self) -> bool {
67+
self.value.var_values.is_identity()
68+
&& self.value.external_constraints.opaque_types.is_empty()
69+
}
6370
}
6471

6572
impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
trait Foo<'a> {}
5+
trait Bar<'a> {}
6+
7+
impl<'a, T: Bar<'a>> Foo<'a> for T {}
8+
impl<T> Bar<'static> for T {}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)