-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Dynamic dispatch through traits requires a managed pointer #8804
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
Comments
This may not be so much of a bug with dynamic dispatch, but rather with how
I think what's happening here is that there's no impl of
As an example, I think that this code should compile: trait A {}
trait B { fn foo(&self); }
impl<T: A> B for T {
fn foo(&self) {}
}
fn foo(a: &A) {
a.foo();
}
fn main() {} Basically, if you ignore all the ways in which I think |
Note that |
As @alexcrichton said, this is a bug with |
Rework `only_used_in_recursion` fixes rust-lang#8782 fixes rust-lang#8629 fixes rust-lang#8560 fixes rust-lang#8556 This is a complete rewrite of the lint. This loses some capabilities of the old implementation. Namely the ability to track through tuple and slice patterns, as well as the ability to trace through assignments. The two reported bugs are fixed with this. One was caused by using the name of the method rather than resolving to the `DefId` of the called method. The second was cause by using the existence of a cycle in the dependency graph to determine whether the parameter was used in recursion even though there were other ways to create a cycle in the graph. Implementation wise this switches from using a visitor to walking up the tree from every use of each parameter until it has been determined the parameter is used for something other than recursion. This is likely to perform better as it avoids walking the entire function a second time, and it is unlikely to walk up the HIR tree very much. Some cases would perform worse though. cc `@buttercrab` changelog: Scale back `only_used_in_recursion` to fix false positives changelog: Move `only_used_in_recursion` back to `complexity`
I'm trying to write a function that reads 4 bytes from the reader using Reader trait and dynamic dispatch. This code:
fn readbytes(reader: &std::io::Reader) -> ~[u8] { reader.read_bytes(4) }
results in this error:
<anon>:5:59: 5:81 error: failed to find an implementation of trait std::io::Reader for &std::io::Reader<no-bounds>
The error message is confusing; nevertheless, replacing borrowed pointer with a managed one makes the code compile:
fn readbytes(reader: @std::io::Reader) -> ~[u8] { reader.read_bytes(4) }
However, requiring a managed pointer for dynamic dispatch seems excessive. Is this a bug?
The text was updated successfully, but these errors were encountered: