Skip to content

Commit

Permalink
Add error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 12, 2015
1 parent 2e00b31 commit 8b731a5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 216 deletions.
21 changes: 12 additions & 9 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
// Return an error here by looking up the namespace that
// had the duplicate.
let ns = ns.unwrap();
self.resolve_error(sp,
&format!("duplicate definition of {} `{}`",
namespace_error_to_string(duplicate_type),
token::get_name(name)));
resolve_err!(self, sp, E0428,
"duplicate definition of {} `{}`",
namespace_error_to_string(duplicate_type),
token::get_name(name));
{
let r = child.span_for_namespace(ns);
if let Some(sp) = r {
Expand Down Expand Up @@ -304,8 +304,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
full_path.segments.last().unwrap().identifier.name;
if &token::get_name(source_name)[..] == "mod" ||
&token::get_name(source_name)[..] == "self" {
self.resolve_error(view_path.span,
"`self` imports are only allowed within a { } list");
resolve_err!(self, view_path.span, E0429,
"{}",
"`self` imports are only allowed within a { } list");
}

let subclass = SingleImport(binding.name,
Expand All @@ -325,8 +326,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
_ => None
}).collect::<Vec<Span>>();
if mod_spans.len() > 1 {
self.resolve_error(mod_spans[0],
"`self` import can only appear once in the list");
resolve_err!(self, mod_spans[0], E0430,
"{}",
"`self` import can only appear once in the list");
for other_span in mod_spans.iter().skip(1) {
self.session.span_note(*other_span,
"another `self` import appears here");
Expand All @@ -341,7 +343,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
let name = match module_path.last() {
Some(name) => *name,
None => {
self.resolve_error(source_item.span,
resolve_err!(self, source_item.span, E0431,
"{}",
"`self` import can only appear in an import list \
with a non-empty prefix");
continue;
Expand Down
42 changes: 41 additions & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,45 @@ register_diagnostics! {
E0257,
E0258,
E0364, // item is private
E0365 // item is private
E0365, // item is private
E0397, // failed to resolve
E0398, // unresolved import
E0399, // can't capture dynamic environment in a fn item
E0400, // attempt to use a non-constant value in a constant
E0401, // can't use type parameters from outer function
E0402, // cannot use an outer type parameter in this context
E0403, // the name `{}` is already used
E0404, // is not a trait
E0405, // use of undeclared trait name
E0406, // undeclared associated type
E0407, // method is not a member of trait
E0408, // variable from pattern #1 is not bound in pattern #
E0409, // variable is bound with different mode in pattern # than in
// pattern #1
E0410, // variable from pattern is not bound in pattern 1
E0411, // use of `Self` outside of an impl or trait
E0412, // use of undeclared
E0413, // declaration of shadows an enum variant or unit-like struct in
// scope
E0414, // only irrefutable patterns allowed here
E0415, // identifier is bound more than once in this parameter list
E0416, // identifier is bound more than once in the same pattern
E0417, // static variables cannot be referenced in a pattern, use a
// `const` instead
E0418, // is not an enum variant, struct or const
E0419, // unresolved enum variant, struct or const
E0420, // is not an associated const
E0421, // unresolved associated const
E0422, // does not name a structure
E0423, // is a struct variant name, but this expression uses it like a
// function name
E0424, // `self` is not available in a static method.
E0425, // unresolved name
E0426, // use of undeclared label
E0427, // cannot use `ref` binding mode with ...
E0428, // duplicate definition of ...
E0429, // `self` imports are only allowed within a { } list
E0430, // `self` import can only appear once in the list
E0431 // `self` import can only appear in an import list with a non-empty
// prefix
}
Loading

0 comments on commit 8b731a5

Please sign in to comment.