-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Non trait object safe return diagnostic needs improvement #33375
Comments
The error message is correct - the trait Maybe we should use "self-type" instead of "receiver"? |
Again: your declared a perfectly fine trait with a single static method. Then you wrote both a non-matching impl and a non-matching method. rustc reported the method, but not the impl. |
No dispute that the error message is correct (or at least, not incorrect). My feeling is that it is unhelpful - the code, whether in the presence or absence of It is strange to see one error message refer to a receiver and the other refer to a Hope that's clearer as to why I regard this as a bug. Thanks for the reply! |
@hythloday they're different kinds of errors. The first one is reporting the invalid method in the impl, the second error is actually a trait-object error. Moreover, the error is pointing to where the error is occurring, as that should ideally provide more context. The compiler doesn't know that you actually meant to write Anyway, these are two different errors, both are equally correct. They're just reporting different things and one of them isn't being shown. |
The current output points out at the problem: error[E0185]: method `apply` has a `&self` declaration in the impl, but not in the trait
--> <anon>:8:5
|
2 | fn apply() -> i64;
| ------------------ trait declared without `&self`
...
8 | fn apply(&self) -> i64 { 4 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl I believe this can be closed. CC @jonathandturner |
@estebank - the original report I think is talking about the bad error given for: trait Foo {
fn apply() -> i64;
}
struct Baz{}
static BAZ: Baz = Baz{};
impl Foo for Baz {
fn apply(&self) -> i64 { 4 }
}
fn lookup() -> Box<&'static Foo> {
Box::new(&BAZ)
} We still give the same confusing error:
|
|
Current output
|
After #68347 the output would be:
|
Thanks Esteban! That is a lot clearer and exactly what I would expect. |
Here's some illegal code that generates a very reasonable error message:
Adding a function that references this broken trait changes the error message and is imho quite misleading:
The error code has changed from something that pinpoints exactly where I went wrong to something unrelated with advice that won't help me see my problem, and highlights the wrong place (the function that's returning this trait rather than the trait itself). Ideally the error message wouldn't change at all.
(happens on stable and beta too)
The text was updated successfully, but these errors were encountered: