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

Better error messages for type-errors due to #[deriving]. #7621

Closed
huonw opened this issue Jul 6, 2013 · 5 comments
Closed

Better error messages for type-errors due to #[deriving]. #7621

huonw opened this issue Jul 6, 2013 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-syntaxext Area: Syntax extensions

Comments

@huonw
Copy link
Member

huonw commented Jul 6, 2013

#[deriving(Trait)] normally relies on the constituent types of the struct or enum also implement Trait, and currently, if they don't, the error messages are unclear. e.g. in the following code, the problem is [f64, .. 3] doesn't implement Clone.

#[deriving(Clone)]
struct V {
    v : [f64, ..3]
}

fn main() {}
tmp.rs:1:11: 1:16 error: mismatched types: expected `[f64, .. 3]` but found `&[f64, .. 3]` (expected vector but found &-ptr)
tmp.rs:1 #[deriving(Clone)]

(This particular error message is because there is a Clone impl for &T, and that one is used if there is no Clone impl for T.)

@alexcrichton
Copy link
Member

Closing as dupes of #7622 and #7724 (mainly 7622, though)

@huonw
Copy link
Member Author

huonw commented Aug 7, 2013

I disagree that this is a dup of those two; #7622 is only tangentially related to #[deriving], and just provides a convenient example for this issue. And #7724 is just to put the span on a more informative place, the error message is still wrong.

The specific problem here is every field gets pattern matched with ref, and so x: T has type &T when being used in the body of the derived method; thus any trait that is implemented for <T> ... &T (like Clone) but not T "works", but uses the impl for &T. This means that Clone returns &T, which tries to go in to a field with type T: bam, type error.

This would be resolved if there was a way to specify exactly which instance was desired (so it'd be an proper error message if that instance didn't exist).

@Kimundi
Copy link
Member

Kimundi commented Jan 26, 2014

See #11818

bors added a commit that referenced this issue Jan 28, 2014
cc #7621.

See the commit message. I'm not sure if we should merge this now, or wait until we can write `Clone::clone(x)` which will directly solve the above issue with perfect error messages.
@steveklabnik
Copy link
Member

@huonw with #11826 merged, is this fixed?

@huonw
Copy link
Member Author

huonw commented Jan 21, 2015

Looks like it:

#[derive(Clone)]
struct V {
    v : [f64; 100]
}

fn main() {}
<anon>:3:5: 3:19 error: the trait `core::clone::Clone` is not implemented for the type `[f64; 100]`
<anon>:3     v : [f64; 100]
             ^~~~~~~~~~~~~~
note: in expansion of #[derive]
<anon>:1:1: 1:17 note: expansion site

Although it was almost certainly #18578 that got them to be that clear.

@huonw huonw closed this as completed Jan 21, 2015
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 28, 2021
Allow giving reasons for `disallowed_methods`

Fixes rust-lang#7609.

This permits writing the config for `disallowed-methods` as either a list of strings (like before) or a list of tables, where each table gives the path to the disallowed method and an optional reason for why the method is disallowed.

changelog: Allow giving reasons for [`disallowed_methods`]
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 A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

4 participants