Skip to content

syntax::ext: Make type errors in deriving point to the field itself. - #10355

Merged
bors merged 1 commit into
rust-lang:masterfrom
huonw:deriving-field-spans
Nov 8, 2013
Merged

syntax::ext: Make type errors in deriving point to the field itself.#10355
bors merged 1 commit into
rust-lang:masterfrom
huonw:deriving-field-spans

Conversation

@huonw

@huonw huonw commented Nov 8, 2013

Copy link
Copy Markdown
Contributor

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

huonw commented Nov 8, 2013

Copy link
Copy Markdown
Contributor Author

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
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
10434: Allow `Locate parent module` command in Cargo.toml r=Veykril a=rainy-me

close rust-lang#10355

Co-authored-by: rainy-me <github@rainy.me>
Co-authored-by: rainy-me <github@yue.coffee>
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