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

error message for @S as @T cast is unclear #5543

Closed
pnkfelix opened this issue Mar 25, 2013 · 8 comments
Closed

error message for @S as @T cast is unclear #5543

pnkfelix opened this issue Mar 25, 2013 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority

Comments

@pnkfelix
Copy link
Member

bar.rs:

use core::io::ReaderUtil;
use core::io::Reader;

fn bar(r:@ReaderUtil) -> ~str { r.read_line() }

fn main() {
    let r : @Reader = io::stdin();
    let _m = bar(r as @ReaderUtil);
}

rustc error message:

/tmp/baz.rs:8:17: 8:33 error: can only cast an @-pointer to an @-object, not a trait core::io::Reader
/tmp/baz.rs:8     let _m = bar(r as @ReaderUtil);
                               ^~~~~~~~~~~~~~~~

I read the above, I say "um... r is an @-pointer, not just an unadorned Reader instance..."

(The poor quality of the error message may or may not be a side-effect of the fact that there is an impl Reader for @Reader implementation in io.rs that might be causing the type checker to first treat r as a Reader before passing it to bar; I am not sure. Either way, the message is confusing.)

@catamorphism
Copy link
Contributor

Reproduced with 0252c30 . Nominating for milestone 5, production-ready

@graydon
Copy link
Contributor

graydon commented Aug 8, 2013

sub-bug of #6308

@pnkfelix
Copy link
Member Author

pnkfelix commented Aug 9, 2013

Note that the phrase "cast an @-pointer to an @-object" has two parses in English, which I suspect is part of my confusion:

  • (cast (an @-pointer) to an @-object)
  • (cast an @-(pointer to an @-object))

@Aatch
Copy link
Contributor

Aatch commented Aug 9, 2013

Actually, this more related to the inability to cast between trait objects.

You don't actually have a @-pointer, you have a trait object.

@graydon
Copy link
Contributor

graydon commented Aug 15, 2013

accepted for production-ready milestone

@pnkfelix
Copy link
Member Author

Assigning P-low. (also we may be able to just close this; I need to look at the current state of the various error messages.)

@alexcrichton
Copy link
Member

This still exists today:

use std::io;

fn bar(r:~Reader) { }

fn main() {
    let r : ~Reader = ~io::stdin();
    let _m = bar(r as ~Reader);
}
foo.rs:7:18: 7:30 error: can only cast an ~-pointer to a ~-object, not a trait std::io::Reader
foo.rs:7     let _m = bar(r as ~Reader);
                          ^~~~~~~~~~~~
error: aborting due to previous error

@arielb1
Copy link
Contributor

arielb1 commented Oct 19, 2014

In 0.12 it gives a better error message:

use std::io;

fn bar(r:Box<Reader>) { }

fn main() {
    let r : Box<Reader> = box io::stdin();
    let _m = bar(r as Box<Reader>);
}

gives

<anon>:8:18: 8:34 error: the trait `std::io::Reader` is not implemented for the type `std::io::Reader`
<anon>:8     let _m = bar(r as Box<Reader>);
                          ^~~~~~~~~~~~~~~~
<anon>:8:18: 8:34 note: the trait `std::io::Reader` must be implemented for the cast to the object type `std::io::Reader`
<anon>:8     let _m = bar(r as Box<Reader>);
                          ^~~~~~~~~~~~~~~~
error: aborting due to previous error

through the identity cast should always be allowed, the error-messages are now good.

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 24, 2014
@bors bors closed this as completed in 5e9a2ab Dec 30, 2014
oli-obk pushed a commit to oli-obk/rust that referenced this issue May 2, 2020
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-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority
Projects
None yet
Development

No branches or pull requests

6 participants