-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem replacing dummy trait methods #5673
Comments
I don't know if this is the solution for this problem, but for my PR I solved this with: be3cc06#diff-35d4b64f583b6ae57aa8095e3d3049788690e178702af2aaf6443030818b74c8R707 |
So this seems to be a problem with trait constraints and our replace decls machinery. Me and @esdrubal been looking at this and found a workaround, if you move the where clauses to the method then it seems to work fine. script;
trait AbiEncode2 {
fn abi_encode2(self, ref mut buffer: Buffer);
}
impl AbiEncode2 for u64 { fn abi_encode2(self, ref mut buffer: Buffer) { } }
impl AbiEncode2 for u32 { fn abi_encode2(self, ref mut buffer: Buffer) { } }
impl AbiEncode2 for u16 { fn abi_encode2(self, ref mut buffer: Buffer) { } }
impl AbiEncode2 for u8 { fn abi_encode2(self, ref mut buffer: Buffer) { } }
struct GenericBimbam<U> {
val: U,
}
impl<U> AbiEncode2 for GenericBimbam<U>
{
fn abi_encode2(self, ref mut buffer: Buffer) where U: AbiEncode2 {
self.val.abi_encode2(buffer);
}
}
struct GenericSnack<T, V> {
twix: GenericBimbam<T>,
mars: V,
}
impl<T, V> AbiEncode2 for GenericSnack<T, V>
{
fn abi_encode2(self, ref mut buffer: Buffer) where T: AbiEncode2, V: AbiEncode2 {
self.twix.abi_encode2(buffer);
self.mars.abi_encode2(buffer);
}
}
fn encode2<T>(item: T) -> raw_slice where T: AbiEncode2 {
let mut buffer = Buffer::new();
item.abi_encode2(buffer);
buffer.as_raw_slice()
}
fn main() {
encode2(GenericSnack { twix: GenericBimbam { val: 0u64 }, mars: 2u32 });
} The proper bugfix for this will probably take a bit of time to get done, so hopefully this is a workable workaround so we can get this feature out ASAP. |
But should this supported? Rust correctly complains that the
|
Rust is right here, the signature of a trait method implementation should be the same as the trait method including the constraints. So this is exploiting a bug. Looks like we didn't include those in the signature check when we implemented trait constraints. But we should. |
When using nested generic methods, as in the use case added, the lower method would not be properly replaced and would remain as a trait dummy method. The fix was to do find_method_for_type in the ReplaceDecls of FunctionAplication, this allows the replacement of the function aplication dummy method with a proper method implementation. Fixes #5673
## Description When using nested generic methods, as in the use case added, the lower method would not be properly replaced and would remain as a trait dummy method. The fix was to do find_method_for_type in the ReplaceDecls of FunctionAplication, this allows the replacement of the function application dummy method with a proper method implementation. Fixes #5673 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
The code below is triggering the following error:
The code. This is a simplified version of the new encoding that is being implemented.
This blocks: #5427
The text was updated successfully, but these errors were encountered: