Skip to content
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

By-value self methods on trait objects have bad error messages #9893

Closed
alexcrichton opened this issue Oct 16, 2013 · 7 comments
Closed

By-value self methods on trait objects have bad error messages #9893

alexcrichton opened this issue Oct 16, 2013 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Comments

@alexcrichton
Copy link
Member

If I have ownership of a trait object, I would expect to be able to call a by-value self method defined on the trait. For example:

trait A { fn foo(self) {} }    

fn foo(a: ~A) {                
    a.foo();                   
}    
struct B;                      
impl A for B {}                

fn main() {                    
    foo(~B as ~A);             
}

currently yields the error of:

foo.rs:4:4: 4:12 error: type `~A:Send` does not implement any method in scope named `foo`
foo.rs:4     a.foo();
             ^~~~~~~~
error: aborting due to previous error

Nominating for the backcompat-lang 1.0 milestone.

@thestinger
Copy link
Contributor

This would be difficult because the size of the type stored in the trait is unknown at compile-time. A by-value self parameter is currently implement poorly via indirection, but that shouldn't be relied upon. I don't think this should be attempted before self is passed properly to avoid blocking fixing that issue.

@catamorphism
Copy link
Contributor

The bug is to improve the error message.

@catamorphism
Copy link
Contributor

Not 1.0

@nikomatsakis
Copy link
Contributor

I don't think it is generally possible to codegen this. We should just give a better error msg.

@alexcrichton
Copy link
Member Author

Updating title to no longer reflect that this is a bug in that it should work, but rather it is a bug in that it should have a better error message.

@alexcrichton
Copy link
Member Author

I just realized that you can indeed write fn foo(~self) {} on the trait, so perhaps the error message could include something along the lines of that. It's the only real way to have ownership of a trait object anyway.

@alexcrichton
Copy link
Member Author

Closing in favor of #10672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

4 participants