-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Provide better error reporting for unimplemented traits #19950
Comments
It can be much worse for closures: use std::ptr;
use std::thread::Thread;
mod obscure {
struct Obscure {
ptr: *const ()
}
}
struct A {
inner: obscure::Obscure
}
impl A {
fn new() -> A {
A { inner: obscure::Obscure { ptr: ptr::null() } }
}
}
fn main() {
let me_bad = A::new();
let me_ok = 0i32;
Thread::spawn(|| {
let _guess_where_it_is = (me_bad, me_ok);
});
} Fails compilation with:
|
Triage: The error message seems much better. This code: struct NoCopy;
enum Test {
MyVariant(NoCopy)
}
impl Copy for Test {}
fn main() {} results in (on
However, there may still be room for improvement for @mzabaluev 's example. The updated code seems to be: use std::ptr;
use std::thread;
mod obscure {
struct Obscure {
ptr: *const ()
}
}
struct A {
inner: obscure::Obscure
}
impl A {
fn new() -> A {
A { inner: obscure::Obscure { ptr: ptr::null() } }
}
}
fn main() {
let me_bad = A::new();
let me_ok = 0i32;
thread::spawn(|| {
let _guess_where_it_is = (me_bad, me_ok);
});
} and the error message is now:
|
The closure example currently reports
So I think this it is solved (we could improve this by adding the upvar name, but it seems clear enough).
|
The |
Compiling the above code generates the following error:
The error mentions that
MyVariant
doesn't implementCopy
without pointing to the right type in the constructor that is actually missing the implementationNoCopy
.The text was updated successfully, but these errors were encountered: