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
traitFooChar{fnfoo(&self,char){}}traitFooInt{fnfoo(&self,int){}}implFooCharforchar{}implFooIntforchar{}traitBar<T>{fnbar(&self,T){}}implBar<char>forchar{}implBar<int>forchar{}fnmain(){'a'.foo('b');//~ error: multiple applicable methods in scope'a'.bar('b');// OK}
Output
conflict.rs:20:9:20:17 error: multiple applicable methods in scope[E0034]
conflict.rs:20'a'.foo('b');//~ error: multiple applicable methods in scope
^~~~~~~~
conflict.rs:2:5:2:24 note: candidate #1 is defined in the trait `FooChar`
conflict.rs:2fnfoo(&self,char){}
^~~~~~~~~~~~~~~~~~~
conflict.rs:6:5:6:23 note: candidate #2 is defined in the trait `FooInt`
conflict.rs:6fnfoo(&self,int){}
^~~~~~~~~~~~~~~~~~
error: aborting due to previous error
I'm under the impression that 'a'.foo('b') should just work, although there are two traits that provide the foo method, it's clear from the signature of the method call that FooChar should be used. After all, it's possible to do something similar using multidispatch (the Bar trait)
I don't think this is expected to work. The way method selection works, it needs to be able to narrow to at least a specific trait, without considering the types of the arguments. In the case of FooChar vs FooInt, we can't narrow to a specific trait based solely on the receiver. (In the case of Bar, we can -- the Bar trait).
STR
Output
Version
I'm under the impression that
'a'.foo('b')
should just work, although there are two traits that provide thefoo
method, it's clear from the signature of the method call thatFooChar
should be used. After all, it's possible to do something similar using multidispatch (theBar
trait)cc @nikomatsakis
The text was updated successfully, but these errors were encountered: