You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
traitSomeBound{}// e.g., `Sized`, `Copy`, `Debug`, or w/etraitTrait<'__>{// Notice that in the general case we don't know// if `Assoc : SomeBound` holds.typeAssoc: ?Sized;}implTrait<'_>for(){typeAssoc = u8;}implSomeBoundforu8{}fncheck<T>(_:T)wherefor<'any>T:Trait<'any>,for<'any>
<TasTrait<'any>>::Assoc:SomeBound,{}fnmain(){check::<()>(());// OKcheck::<_>(());// Errorscheck(());// Errors}
I expected to see this happen: Code compiles fine, whether T is inferred to be () or explicitly turbofished
Instead, this happened: when T is inferred (explicitly or implicitly), an error about the trait for<'any> Bound not being satisfied for <_ as Trait<'any>>::Assoc:
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the trait bound `for<'any> <_ asTrait<'any>>::Assoc:SomeBound` is not satisfied
--> src/main.rs:26:5
|
26 | check::<_>(());// Errors
| ^^^^^^^^^^ the trait `for<'any> SomeBound` is not implemented for `<_ as Trait<'any>>::Assoc`
|
note: required by a bound in `check`
--> src/main.rs:20:37
|
14 | fn check<T>(_:T)
| ----- required by a bound in this
...
20 | <TasTrait<'any>>::Assoc:SomeBound
| ^^^^^^^^^ required by this bound in `check`
Have a blanket impl to forward the original implementations that meet the bound to this new trait (this impl is not higher-order, thereby dodging the issue):
Wrap the original function within one which uses this "assoc-type-bounded trait alias" instead, while also adding an equality close in between the two associated types:
// wrapping function
fn check<T>(it: T)
where
T : for<'any> Trait<'any,
+ Assoc = <T as TraitWithBoundOnAssoc<'any>>::Assoc,
>,
for<'any>
- <T as Trait<'any>>::Assoc : SomeBound+ T : TraitWithBoundOnAssoc<'any>
,
{
// original function which can be left untouched:
fn check<T> …
check::<T>(it) // <- turbofish to avoid the issue mentioned in this very issue!
}
I tried this code:
I expected to see this happen: Code compiles fine, whether
T
is inferred to be()
or explicitly turbofishedInstead, this happened: when
T
is inferred (explicitly or implicitly), an error about the traitfor<'any> Bound
not being satisfied for<_ as Trait<'any>>::Assoc
:Demo
This happens on all versions of Rust (up to
1.0.0
!)@rustbot modify labels: A-traits
The text was updated successfully, but these errors were encountered: