Skip to content

Commit 67aca9c

Browse files
committed
auto merge of rust-lang#10844 : huonw/rust/deriving-expn-info, r=alexcrichton
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. (includes some cleanup/preparation; the commit view might be nicer, to filter out the noise of the first one.)
2 parents 7c719ec + 0c0e73e commit 67aca9c

18 files changed

+299
-231
lines changed

src/librustc/front/test.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::vec;
1818
use syntax::ast_util::*;
1919
use syntax::attr::AttrMetaMethods;
2020
use syntax::attr;
21-
use syntax::codemap::{dummy_sp, Span, ExpnInfo, NameAndSpan};
21+
use syntax::codemap::{dummy_sp, Span, ExpnInfo, NameAndSpan, MacroAttribute};
2222
use syntax::codemap;
2323
use syntax::ext::base::ExtCtxt;
2424
use syntax::fold::ast_fold;
@@ -158,6 +158,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
158158
call_site: dummy_sp(),
159159
callee: NameAndSpan {
160160
name: @"test",
161+
format: MacroAttribute,
161162
span: None
162163
}
163164
});

src/libsyntax/codemap.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,22 @@ pub struct LocWithOpt {
161161
// used to be structural records. Better names, anyone?
162162
pub struct FileMapAndLine {fm: @FileMap, line: uint}
163163
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
164+
164165
#[deriving(IterBytes)]
165-
pub struct NameAndSpan {name: @str, span: Option<Span>}
166+
pub enum MacroFormat {
167+
// e.g. #[deriving(...)] <item>
168+
MacroAttribute,
169+
// e.g. `format!()`
170+
MacroBang
171+
}
172+
173+
#[deriving(IterBytes)]
174+
pub struct NameAndSpan {
175+
name: @str,
176+
// the format with which the macro was invoked.
177+
format: MacroFormat,
178+
span: Option<Span>
179+
}
166180

167181
/// Extra information for tracking macro expansion of spans
168182
#[deriving(IterBytes)]

src/libsyntax/diagnostic.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,13 @@ fn highlight_lines(cm: @codemap::CodeMap,
342342
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: Span) {
343343
for ei in sp.expn_info.iter() {
344344
let ss = ei.callee.span.as_ref().map_default(~"", |span| cm.span_to_str(*span));
345+
let (pre, post) = match ei.callee.format {
346+
codemap::MacroAttribute => ("#[", "]"),
347+
codemap::MacroBang => ("", "!")
348+
};
349+
345350
print_diagnostic(ss, note,
346-
format!("in expansion of {}!", ei.callee.name));
351+
format!("in expansion of {}{}{}", pre, ei.callee.name, post));
347352
let ss = cm.span_to_str(ei.call_site);
348353
print_diagnostic(ss, note, "expansion site");
349354
print_macro_backtrace(cm, ei.call_site);

src/libsyntax/ext/deriving/clone.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn expand_deriving_clone(cx: @ExtCtxt,
2020
in_items: ~[@item])
2121
-> ~[@item] {
2222
let trait_def = TraitDef {
23+
cx: cx, span: span,
24+
2325
path: Path::new(~["std", "clone", "Clone"]),
2426
additional_bounds: ~[],
2527
generics: LifetimeBounds::empty(),
@@ -37,7 +39,7 @@ pub fn expand_deriving_clone(cx: @ExtCtxt,
3739
]
3840
};
3941

40-
trait_def.expand(cx, span, mitem, in_items)
42+
trait_def.expand(mitem, in_items)
4143
}
4244

4345
pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
@@ -46,6 +48,8 @@ pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
4648
in_items: ~[@item])
4749
-> ~[@item] {
4850
let trait_def = TraitDef {
51+
cx: cx, span: span,
52+
4953
path: Path::new(~["std", "clone", "DeepClone"]),
5054
additional_bounds: ~[],
5155
generics: LifetimeBounds::empty(),
@@ -65,7 +69,7 @@ pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
6569
]
6670
};
6771

68-
trait_def.expand(cx, span, mitem, in_items)
72+
trait_def.expand(mitem, in_items)
6973
}
7074

7175
fn cs_clone(

src/libsyntax/ext/deriving/cmp/eq.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub fn expand_deriving_eq(cx: @ExtCtxt,
4545
);
4646

4747
let trait_def = TraitDef {
48+
cx: cx, span: span,
49+
4850
path: Path::new(~["std", "cmp", "Eq"]),
4951
additional_bounds: ~[],
5052
generics: LifetimeBounds::empty(),
@@ -53,5 +55,5 @@ pub fn expand_deriving_eq(cx: @ExtCtxt,
5355
md!("ne", cs_ne)
5456
]
5557
};
56-
trait_def.expand(cx, span, mitem, in_items)
58+
trait_def.expand(mitem, in_items)
5759
}

src/libsyntax/ext/deriving/cmp/ord.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
3535
);
3636

3737
let trait_def = TraitDef {
38+
cx: cx, span: span,
39+
3840
path: Path::new(~["std", "cmp", "Ord"]),
3941
additional_bounds: ~[],
4042
generics: LifetimeBounds::empty(),
@@ -45,7 +47,7 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
4547
md!("ge", false, true)
4648
]
4749
};
48-
trait_def.expand(cx, span, mitem, in_items)
50+
trait_def.expand(mitem, in_items)
4951
}
5052

5153
/// Strict inequality.

src/libsyntax/ext/deriving/cmp/totaleq.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt,
2424
}
2525

2626
let trait_def = TraitDef {
27+
cx: cx, span: span,
28+
2729
path: Path::new(~["std", "cmp", "TotalEq"]),
2830
additional_bounds: ~[],
2931
generics: LifetimeBounds::empty(),
@@ -40,5 +42,5 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt,
4042
}
4143
]
4244
};
43-
trait_def.expand(cx, span, mitem, in_items)
45+
trait_def.expand(mitem, in_items)
4446
}

src/libsyntax/ext/deriving/cmp/totalord.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt,
2121
mitem: @MetaItem,
2222
in_items: ~[@item]) -> ~[@item] {
2323
let trait_def = TraitDef {
24+
cx: cx, span: span,
25+
2426
path: Path::new(~["std", "cmp", "TotalOrd"]),
2527
additional_bounds: ~[],
2628
generics: LifetimeBounds::empty(),
@@ -38,7 +40,7 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt,
3840
]
3941
};
4042

41-
trait_def.expand(cx, span, mitem, in_items)
43+
trait_def.expand(mitem, in_items)
4244
}
4345

4446

src/libsyntax/ext/deriving/decodable.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub fn expand_deriving_decodable(cx: @ExtCtxt,
2424
mitem: @MetaItem,
2525
in_items: ~[@item]) -> ~[@item] {
2626
let trait_def = TraitDef {
27+
cx: cx, span: span,
28+
2729
path: Path::new_(~["extra", "serialize", "Decodable"], None,
2830
~[~Literal(Path::new_local("__D"))], true),
2931
additional_bounds: ~[],
@@ -46,7 +48,7 @@ pub fn expand_deriving_decodable(cx: @ExtCtxt,
4648
]
4749
};
4850

49-
trait_def.expand(cx, span, mitem, in_items)
51+
trait_def.expand(mitem, in_items)
5052
}
5153

5254
fn decodable_substructure(cx: @ExtCtxt, span: Span,

src/libsyntax/ext/deriving/default.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn expand_deriving_default(cx: @ExtCtxt,
2020
in_items: ~[@item])
2121
-> ~[@item] {
2222
let trait_def = TraitDef {
23+
cx: cx, span: span,
24+
2325
path: Path::new(~["std", "default", "Default"]),
2426
additional_bounds: ~[],
2527
generics: LifetimeBounds::empty(),
@@ -36,7 +38,7 @@ pub fn expand_deriving_default(cx: @ExtCtxt,
3638
},
3739
]
3840
};
39-
trait_def.expand(cx, span, mitem, in_items)
41+
trait_def.expand(mitem, in_items)
4042
}
4143

4244
fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {

src/libsyntax/ext/deriving/encodable.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ pub fn expand_deriving_encodable(cx: @ExtCtxt,
8686
mitem: @MetaItem,
8787
in_items: ~[@item]) -> ~[@item] {
8888
let trait_def = TraitDef {
89+
cx: cx, span: span,
90+
8991
path: Path::new_(~["extra", "serialize", "Encodable"], None,
9092
~[~Literal(Path::new_local("__E"))], true),
9193
additional_bounds: ~[],
@@ -108,7 +110,7 @@ pub fn expand_deriving_encodable(cx: @ExtCtxt,
108110
]
109111
};
110112

111-
trait_def.expand(cx, span, mitem, in_items)
113+
trait_def.expand(mitem, in_items)
112114
}
113115

114116
fn encodable_substructure(cx: @ExtCtxt, span: Span,

0 commit comments

Comments
 (0)