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

Poor error message for pointer patterns with trait objects #11469

Closed
huonw opened this issue Jan 11, 2014 · 2 comments
Closed

Poor error message for pointer patterns with trait objects #11469

huonw opened this issue Jan 11, 2014 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@huonw
Copy link
Member

huonw commented Jan 11, 2014

trait Foo {}
impl Foo for int {}

fn main() {
    let ~x = ~1 as ~Foo;
    let &x = &1 as &Foo;
}
trait-object-pattern.rs:5:9: 5:11 error: mismatched types: expected `~Foo:Send` but found a ~-box pattern
trait-object-pattern.rs:5     let ~x = ~1 as ~Foo;
                                  ^~
trait-object-pattern.rs:6:9: 6:11 error: mismatched types: expected `&Foo<no-bounds>` but found an &-pointer pattern
trait-object-pattern.rs:6     let &x = &1 as &Foo;
                                  ^~

The error message doesn't make it obvious what the type mismatch is, since ~Foo:Send certainly appears to satisfy a ~-box pattern.

@jfager
Copy link
Contributor

jfager commented Jul 26, 2014

~ is gone; the updated version

trait Foo {}
impl Foo for int {}

fn main() {
    let box x = box 1i as Box<Foo>;
    let &x = &1i as &Foo;
}

now errors with

$ rustc r11469.rs 
r11469.rs:5:9: 5:14 error: type `Box<Foo>` cannot be dereferenced [E0033]
r11469.rs:5     let box x = box 1i as Box<Foo>;
                    ^~~~~
r11469.rs:6:9: 6:11 error: type `&Foo` cannot be dereferenced [E0033]
r11469.rs:6     let &x = &1i as &Foo;
                    ^~
error: aborting due to 2 previous errors

@ghost
Copy link

ghost commented Oct 25, 2014

@jfager Thanks, this has indeed improved and it's tested (src/test/compile-fail/destructure-trait-ref.rs) so I'm closing the issue.

@ghost ghost closed this as completed Oct 25, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 7, 2023
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 12, 2023
This issue was closed.
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
Projects
None yet
Development

No branches or pull requests

2 participants