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
Do trait method signatures have to match exactly, or is there some subtyping relationship that is supposed to hold between an impl's methods and the methods of the trait definition itself?
If there is a subtyping relationship, then I would expect the following to compile:
#![crate_type="lib"]// illustrating subtype relationship: typeof(g) <: typeof(f) ...fnfoo<'a,'b>(ignored:Option<&'a&'b()>, f: || -> &'a int){unimplemented!()}fnbar<'a,'b>(ignored:Option<&'a&'b()>, g: || -> &'b int){foo(ignored, g)}// ... but does that subtype relationship apply to the return types here?traitT{fnm<'a,'b>(self,ignored:Option<&'a&'b()>) -> &'aint;}implTfor(){fnm<'a,'b>(self,ignored:Option<&'a&'b()>) -> &'bint{unimplemented!()}}
(it currently does not compile; it complains of the mismatch between the lifetime parameters.)
If there is not a subtyping relationship, then I would not expect the following to compile:
Note that the latter case seems sound to me, but the fact that this works in the latter case but does not for the former case just makes me worry about what the rules actually are that we are enforcing with respect to how much an impl needs to conform with its corresponding trait.
The text was updated successfully, but these errors were encountered:
((The semi-good news is that whatever the oddity is that leads us to accept the second example in the description, whatever that oddity is, I have not yet been able to construct an example via that oddity that breaks type soundness. Not yet.))
I think @pnkfelix's confusion may in fact be #18937, which I am supposed to be fixing. In any case, I'm going to close this issue, since I think the big question (must impl signatures match exactly) is basically de facto settled to "no, some amount of subtyping is permitted".
Do trait method signatures have to match exactly, or is there some subtyping relationship that is supposed to hold between an impl's methods and the methods of the trait definition itself?
If there is a subtyping relationship, then I would expect the following to compile:
(it currently does not compile; it complains of the mismatch between the lifetime parameters.)
If there is not a subtyping relationship, then I would not expect the following to compile:
(it currently does compile.)
Note that the latter case seems sound to me, but the fact that this works in the latter case but does not for the former case just makes me worry about what the rules actually are that we are enforcing with respect to how much an
impl
needs to conform with its correspondingtrait
.The text was updated successfully, but these errors were encountered: