Skip to content

Make error messages from deriving(Foo) point to the deriving declaration as well as the field #10844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::vec;
use syntax::ast_util::*;
use syntax::attr::AttrMetaMethods;
use syntax::attr;
use syntax::codemap::{dummy_sp, Span, ExpnInfo, NameAndSpan};
use syntax::codemap::{dummy_sp, Span, ExpnInfo, NameAndSpan, MacroAttribute};
use syntax::codemap;
use syntax::ext::base::ExtCtxt;
use syntax::fold::ast_fold;
Expand Down Expand Up @@ -158,6 +158,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
call_site: dummy_sp(),
callee: NameAndSpan {
name: @"test",
format: MacroAttribute,
span: None
}
});
Expand Down
16 changes: 15 additions & 1 deletion src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,22 @@ pub struct LocWithOpt {
// used to be structural records. Better names, anyone?
pub struct FileMapAndLine {fm: @FileMap, line: uint}
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}

#[deriving(IterBytes)]
pub struct NameAndSpan {name: @str, span: Option<Span>}
pub enum MacroFormat {
// e.g. #[deriving(...)] <item>
MacroAttribute,
// e.g. `format!()`
MacroBang
}

#[deriving(IterBytes)]
pub struct NameAndSpan {
name: @str,
// the format with which the macro was invoked.
format: MacroFormat,
span: Option<Span>
}

/// Extra information for tracking macro expansion of spans
#[deriving(IterBytes)]
Expand Down
7 changes: 6 additions & 1 deletion src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,13 @@ fn highlight_lines(cm: @codemap::CodeMap,
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: Span) {
for ei in sp.expn_info.iter() {
let ss = ei.callee.span.as_ref().map_default(~"", |span| cm.span_to_str(*span));
let (pre, post) = match ei.callee.format {
codemap::MacroAttribute => ("#[", "]"),
codemap::MacroBang => ("", "!")
};

print_diagnostic(ss, note,
format!("in expansion of {}!", ei.callee.name));
format!("in expansion of {}{}{}", pre, ei.callee.name, post));
let ss = cm.span_to_str(ei.call_site);
print_diagnostic(ss, note, "expansion site");
print_macro_backtrace(cm, ei.call_site);
Expand Down
8 changes: 6 additions & 2 deletions src/libsyntax/ext/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub fn expand_deriving_clone(cx: @ExtCtxt,
in_items: ~[@item])
-> ~[@item] {
let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new(~["std", "clone", "Clone"]),
additional_bounds: ~[],
generics: LifetimeBounds::empty(),
Expand All @@ -37,7 +39,7 @@ pub fn expand_deriving_clone(cx: @ExtCtxt,
]
};

trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}

pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
Expand All @@ -46,6 +48,8 @@ pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
in_items: ~[@item])
-> ~[@item] {
let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new(~["std", "clone", "DeepClone"]),
additional_bounds: ~[],
generics: LifetimeBounds::empty(),
Expand All @@ -65,7 +69,7 @@ pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
]
};

trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}

fn cs_clone(
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/deriving/cmp/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub fn expand_deriving_eq(cx: @ExtCtxt,
);

let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new(~["std", "cmp", "Eq"]),
additional_bounds: ~[],
generics: LifetimeBounds::empty(),
Expand All @@ -53,5 +55,5 @@ pub fn expand_deriving_eq(cx: @ExtCtxt,
md!("ne", cs_ne)
]
};
trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}
4 changes: 3 additions & 1 deletion src/libsyntax/ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
);

let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new(~["std", "cmp", "Ord"]),
additional_bounds: ~[],
generics: LifetimeBounds::empty(),
Expand All @@ -45,7 +47,7 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
md!("ge", false, true)
]
};
trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}

/// Strict inequality.
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/deriving/cmp/totaleq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt,
}

let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new(~["std", "cmp", "TotalEq"]),
additional_bounds: ~[],
generics: LifetimeBounds::empty(),
Expand All @@ -40,5 +42,5 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt,
}
]
};
trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}
4 changes: 3 additions & 1 deletion src/libsyntax/ext/deriving/cmp/totalord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new(~["std", "cmp", "TotalOrd"]),
additional_bounds: ~[],
generics: LifetimeBounds::empty(),
Expand All @@ -38,7 +40,7 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt,
]
};

trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}


Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub fn expand_deriving_decodable(cx: @ExtCtxt,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new_(~["extra", "serialize", "Decodable"], None,
~[~Literal(Path::new_local("__D"))], true),
additional_bounds: ~[],
Expand All @@ -46,7 +48,7 @@ pub fn expand_deriving_decodable(cx: @ExtCtxt,
]
};

trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}

fn decodable_substructure(cx: @ExtCtxt, span: Span,
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub fn expand_deriving_default(cx: @ExtCtxt,
in_items: ~[@item])
-> ~[@item] {
let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new(~["std", "default", "Default"]),
additional_bounds: ~[],
generics: LifetimeBounds::empty(),
Expand All @@ -36,7 +38,7 @@ pub fn expand_deriving_default(cx: @ExtCtxt,
},
]
};
trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}

fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub fn expand_deriving_encodable(cx: @ExtCtxt,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
let trait_def = TraitDef {
cx: cx, span: span,

path: Path::new_(~["extra", "serialize", "Encodable"], None,
~[~Literal(Path::new_local("__E"))], true),
additional_bounds: ~[],
Expand All @@ -108,7 +110,7 @@ pub fn expand_deriving_encodable(cx: @ExtCtxt,
]
};

trait_def.expand(cx, span, mitem, in_items)
trait_def.expand(mitem, in_items)
}

fn encodable_substructure(cx: @ExtCtxt, span: Span,
Expand Down
Loading