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
implAnalyzer{/// Validates and store errors if required.pubfncheck<T,O>(&mutself,node:&T) -> Option<O>whereSelf:Validate<T,Output = Result<O,Error>>,{let res:Result<O,_> = self.validate(node);match res {Ok(v) => Some(v),Err(..) => {// handle errorNone}}}}
However, it works if type annotation is provided
fnmain(){letmut a = Analyzer;let expr = Expr;// Uncomment this to see impl for [T] explodes// a.check(&expr);// This works without error
a.check::<Expr,()>(&expr);}
The text was updated successfully, but these errors were encountered:
as soon as any specialization exists, type inference coerces everything thats covered by the blanket default impl to that specialization, regardless of compatibility. workaround is to avoid type inference via explicit type annotation
#![feature(min_specialization)]traitConsume<T>{fnconsume(_:T);}//blanket default impl without any specializationsstructConsumer1;impl<T>Consume<T>forConsumer1{defaultfnconsume(_:T){//...}}//blanket default impl with 1 specializationstructConsumer2;impl<T>Consume<T>forConsumer2{defaultfnconsume(_:T){//...}}implConsume<i32>forConsumer2{fnconsume(_:i32){//...}}fnmain(){Consumer1::consume(true);//okConsumer1::consume(42);//okConsumer2::consume(true);//error: expected `i32`, found `bool`Consumer2::consume(42);//ok//workaround:
<Consumer2asConsume<bool>>::consume(true);//ok}
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a26a9e2af3acda5b9911458a6f54a72d
This trait implementation
does not like a method defined as
However, it works if type annotation is provided
The text was updated successfully, but these errors were encountered: