Skip to content

Commit 1898267

Browse files
committed
trait_sel: resolve vars in host effects
In the standard library, the `Extend` impl for `Iterator` (specialised with `TrustedLen`) has a parameter which is constrained by a projection predicate. This projection predicate provides a value for an inference variable but host effect evaluation wasn't resolving variables first. Adding the extra resolve can the number of errors in some tests when they gain host effect predicates, but this is not unexpected as calls to `resolve_vars_if_possible` can cause more error tainting to happen.
1 parent ad27045 commit 1898267

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

compiler/rustc_trait_selection/src/traits/effects.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub fn evaluate_host_effect_obligation<'tcx>(
3131
);
3232
}
3333

34+
let ref obligation = selcx.infcx.resolve_vars_if_possible(obligation.clone());
35+
3436
// Force ambiguity for infer self ty.
3537
if obligation.predicate.self_ty().is_ty_var() {
3638
return Err(EvaluationFailure::Ambiguous);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ check-pass
2+
//@ compile-flags: --crate-type=lib
3+
#![no_std]
4+
#![allow(internal_features)]
5+
#![feature(rustc_attrs, min_specialization, const_trait_impl)]
6+
7+
// In the default impl below, `A` is constrained by the projection predicate, and if the host effect
8+
// predicate for `const Foo` doesn't resolve vars, then specialization will fail.
9+
10+
#[const_trait]
11+
trait Foo {}
12+
13+
pub trait Extend<A> {}
14+
15+
pub trait Iterator {
16+
type Item;
17+
}
18+
19+
#[rustc_unsafe_specialization_marker]
20+
pub trait MoreSpecificThanIterator: Iterator {}
21+
22+
pub trait Tr {
23+
fn foo();
24+
}
25+
26+
impl<A: const Foo, Iter> Tr for Iter
27+
where
28+
Iter: Iterator<Item = A>,
29+
{
30+
default fn foo() {}
31+
}
32+
33+
impl<A: const Foo, Iter> Tr for Iter
34+
where
35+
Iter: MoreSpecificThanIterator<Item = A>,
36+
{
37+
fn foo() {}
38+
}

0 commit comments

Comments
 (0)