Skip to content

Commit 0c0e73e

Browse files
committed
syntax::deriving: indicate from which trait type errors (etc) arise
using the expansion info. Previously something like struct NotEq; #[deriving(Eq)] struct Error { foo: NotEq } would just point to the `foo` field, with no mention of the `deriving(Eq)`. With this patch, the compiler creates a note saying "in expansion of #[deriving(Eq)]" pointing to the Eq.
1 parent 3ef9336 commit 0c0e73e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/libsyntax/ext/deriving/generic.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,9 @@ impl<'self> MethodDef<'self> {
899899
let summary = enum_def.variants.map(|v| {
900900
let ident = v.node.name;
901901
let summary = match v.node.kind {
902-
ast::tuple_variant_kind(ref args) => Unnamed(args.map(|va| va.ty.span)),
902+
ast::tuple_variant_kind(ref args) => {
903+
Unnamed(args.map(|va| trait_.set_expn_info(va.ty.span)))
904+
}
903905
ast::struct_variant_kind(struct_def) => {
904906
trait_.summarise_struct(struct_def)
905907
}
@@ -919,11 +921,27 @@ enum StructType {
919921

920922
// general helper methods.
921923
impl<'a> TraitDef<'a> {
924+
fn set_expn_info(&self, mut to_set: Span) -> Span {
925+
let trait_name = match self.path.path.last_opt() {
926+
None => self.cx.span_bug(self.span, "trait with empty path in generic `deriving`"),
927+
Some(name) => *name
928+
};
929+
to_set.expn_info = Some(@codemap::ExpnInfo {
930+
call_site: to_set,
931+
callee: codemap::NameAndSpan {
932+
name: format!("deriving({})", trait_name).to_managed(),
933+
format: codemap::MacroAttribute,
934+
span: Some(self.span)
935+
}
936+
});
937+
to_set
938+
}
939+
922940
fn summarise_struct(&self, struct_def: &struct_def) -> StaticFields {
923941
let mut named_idents = ~[];
924942
let mut just_spans = ~[];
925943
for field in struct_def.fields.iter(){
926-
let sp = field.span;
944+
let sp = self.set_expn_info(field.span);
927945
match field.node.kind {
928946
ast::named_field(ident, _) => named_idents.push((ident, sp)),
929947
ast::unnamed_field => just_spans.push(sp),
@@ -973,7 +991,7 @@ impl<'a> TraitDef<'a> {
973991
let mut struct_type = Unknown;
974992

975993
for (i, struct_field) in struct_def.fields.iter().enumerate() {
976-
let sp = struct_field.span;
994+
let sp = self.set_expn_info(struct_field.span);
977995
let opt_id = match struct_field.node.kind {
978996
ast::named_field(ident, _) if (struct_type == Unknown ||
979997
struct_type == Record) => {
@@ -1031,7 +1049,7 @@ impl<'a> TraitDef<'a> {
10311049
let mut paths = ~[];
10321050
let mut ident_expr = ~[];
10331051
for (i, va) in variant_args.iter().enumerate() {
1034-
let sp = va.ty.span;
1052+
let sp = self.set_expn_info(va.ty.span);
10351053
let path = cx.path_ident(sp, cx.ident_of(format!("{}_{}", prefix, i)));
10361054

10371055
paths.push(path.clone());

0 commit comments

Comments
 (0)