Skip to content

Conversation

huonw
Copy link
Contributor

@huonw huonw commented Nov 8, 2013

This rearranges the deriving code so that #[deriving] a trait on a field
that doesn't implement that trait will point to the field in question,
e.g.

struct NotEq; // doesn't implement Eq

#[deriving(Eq)]
struct Foo {
    ok: int,
    also_ok: ~str,
    bad: NotEq // error points here.
}

Unfortunately, this means the error is disconnected from the deriving
itself but there's no current way to pass that information through to
rustc except via the spans, at the moment.

Fixes #7724.

This rearranges the deriving code so that #[deriving] a trait on a field
that doesn't implement that trait will point to the field in question,
e.g.

    struct NotEq; // doesn't implement Eq

    #[deriving(Eq)]
    struct Foo {
        ok: int,
        also_ok: ~str,
        bad: NotEq // error points here.
    }

Unfortunately, this means the error is disconnected from the `deriving`
itself but there's no current way to pass that information through to
rustc except via the spans, at the moment.

Fixes rust-lang#7724.
@huonw
Copy link
Contributor Author

huonw commented Nov 8, 2013

Summary: this reuses the spans from the variant and struct_field (ast types) in expand_static_enum_body, summarise_struct, create_struct_pattern and create_enum_pattern to create the span field in the new FieldInfo struct (and the Span parts of StaticFields) which can then be used "downstream" (example) to associate the span of the constructed Exprs with the fields, so any type errors get displayed as if they were caused by that field.

(Sorry for the noise with the span -> trait_span.)

bors added a commit that referenced this pull request Nov 8, 2013
This rearranges the deriving code so that #[deriving] a trait on a field
that doesn't implement that trait will point to the field in question,
e.g.

    struct NotEq; // doesn't implement Eq

    #[deriving(Eq)]
    struct Foo {
        ok: int,
        also_ok: ~str,
        bad: NotEq // error points here.
    }

Unfortunately, this means the error is disconnected from the `deriving`
itself but there's no current way to pass that information through to
rustc except via the spans, at the moment.

Fixes #7724.
@bors bors closed this Nov 8, 2013
@bors bors merged commit 812ea9e into rust-lang:master Nov 8, 2013
@huonw huonw deleted the deriving-field-spans branch November 8, 2013 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deriving error should point to field which caused the error
3 participants