syntax::ext: Make type errors in deriving point to the field itself.
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 commit is contained in:
parent
57d1ed819b
commit
812ea9e169
13 changed files with 410 additions and 312 deletions
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[feature(struct_variant)];
|
||||
|
||||
struct NotEq;
|
||||
|
||||
#[deriving(Eq)]
|
||||
enum Foo {
|
||||
Bar {
|
||||
x: NotEq //~ ERROR mismatched types
|
||||
//~^ ERROR failed to find an implementation of trait std::cmp::Eq for NotEq
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
22
src/test/compile-fail/deriving-field-span-enum.rs
Normal file
22
src/test/compile-fail/deriving-field-span-enum.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[feature(struct_variant)];
|
||||
|
||||
struct NotEq;
|
||||
|
||||
#[deriving(Eq)]
|
||||
enum Foo {
|
||||
Bar(NotEq), //~ ERROR mismatched types
|
||||
//~^ ERROR failed to find an implementation of trait std::cmp::Eq for NotEq
|
||||
Baz { x: NotEq }
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
19
src/test/compile-fail/deriving-field-span-struct.rs
Normal file
19
src/test/compile-fail/deriving-field-span-struct.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
struct NotEq;
|
||||
|
||||
#[deriving(Eq)]
|
||||
struct Foo {
|
||||
x: NotEq //~ ERROR mismatched types
|
||||
//~^ ERROR failed to find an implementation of trait std::cmp::Eq for NotEq
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
19
src/test/compile-fail/deriving-field-span-tuple-struct.rs
Normal file
19
src/test/compile-fail/deriving-field-span-tuple-struct.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
struct NotEq;
|
||||
|
||||
#[deriving(Eq)]
|
||||
struct Foo (
|
||||
NotEq //~ ERROR mismatched types
|
||||
//~^ ERROR failed to find an implementation of trait std::cmp::Eq for NotEq
|
||||
);
|
||||
|
||||
pub fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue