Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_trait_selection/src/traits/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub fn evaluate_host_effect_obligation<'tcx>(
);
}

let ref obligation = selcx.infcx.resolve_vars_if_possible(obligation.clone());

// Force ambiguity for infer self ty.
if obligation.predicate.self_ty().is_ty_var() {
return Err(EvaluationFailure::Ambiguous);
Expand Down
36 changes: 36 additions & 0 deletions tests/ui/traits/const-traits/unconstrained-var-specialization.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On nightly this emits

error[E0283]: type annotations needed: cannot satisfy `Iter: Tr`
  --> src/lib.rs:31:33
   |
31 | impl<A: const Foo, Iter> Tr for Iter
   |                                 ^^^^
   |
note: multiple `impl`s satisfying `Iter: Tr` found
  --> src/lib.rs:24:1
   |
24 | / impl<A: const Foo, Iter> Tr for Iter
25 | |     where
26 | |         Iter: Iterator<Item = A>,
   | |_________________________________^
...
31 | / impl<A: const Foo, Iter> Tr for Iter
32 | |     where
33 | |         Iter: MoreSpecificThanIterator<Item = A>,
   | |_________________________________________________^

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//@ check-pass
//@ compile-flags: --crate-type=lib
#![no_std]
#![allow(internal_features)]
#![feature(rustc_attrs, min_specialization, const_trait_impl)]

// In the default impl below, `A` is constrained by the projection predicate, and if the host effect
// predicate for `const Foo` doesn't resolve vars, then specialization will fail.

#[const_trait]
trait Foo {}

pub trait Iterator {
type Item;
}

#[rustc_unsafe_specialization_marker]
pub trait MoreSpecificThanIterator: Iterator {}

pub trait Tr {
fn foo();
}

impl<A: const Foo, Iter> Tr for Iter
where
Iter: Iterator<Item = A>,
{
default fn foo() {}
}

impl<A: const Foo, Iter> Tr for Iter
where
Iter: MoreSpecificThanIterator<Item = A>,
{
fn foo() {}
}
Loading