Skip to content

Commit efe8d0c

Browse files
authored
Rollup merge of rust-lang#137604 - davidtwco:host-effect-resolve-vars, r=compiler-errors
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 - if the default bound is `const Sized` instead of `Sized` - host effect evaluation wasn't resolving variables first. Added a test that doesn't depend on a rust-lang/rfcs#3729 implementation. 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.
2 parents 2213c2a + 21d41b0 commit efe8d0c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-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,36 @@
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 Iterator {
14+
type Item;
15+
}
16+
17+
#[rustc_unsafe_specialization_marker]
18+
pub trait MoreSpecificThanIterator: Iterator {}
19+
20+
pub trait Tr {
21+
fn foo();
22+
}
23+
24+
impl<A: const Foo, Iter> Tr for Iter
25+
where
26+
Iter: Iterator<Item = A>,
27+
{
28+
default fn foo() {}
29+
}
30+
31+
impl<A: const Foo, Iter> Tr for Iter
32+
where
33+
Iter: MoreSpecificThanIterator<Item = A>,
34+
{
35+
fn foo() {}
36+
}

0 commit comments

Comments
 (0)