Remove warnings by centralizing error codes usage

This commit is contained in:
Guillaume Gomez 2015-07-13 02:05:02 +02:00
parent 48ee57e656
commit cbf0b1b399
2 changed files with 63 additions and 42 deletions

View file

@ -116,6 +116,26 @@ mod record_exports;
mod build_reduced_graph;
mod resolve_imports;
fn resolve_err_417<'a, 'tcx>(this: &Resolver<'a, 'tcx>, span: syntax::codemap::Span, formatted: &str) {
resolve_err!(this, span, E0417, "{}", formatted);
}
fn resolve_err_422<'a, 'tcx>(this: &Resolver<'a, 'tcx>, span: syntax::codemap::Span, formatted: &str) {
resolve_err!(this, span, E0422, "{}", formatted);
}
fn resolve_err_423<'a, 'tcx>(this: &Resolver<'a, 'tcx>, span: syntax::codemap::Span, formatted: &str) {
resolve_err!(this, span, E0423, "{}", formatted);
}
fn resolve_err_432<'a, 'tcx>(this: &Resolver<'a, 'tcx>, span: syntax::codemap::Span, formatted: &str) {
resolve_err!(this, span, E0432, "{}", formatted);
}
fn resolve_err_433<'a, 'tcx>(this: &Resolver<'a, 'tcx>, span: syntax::codemap::Span, formatted: &str) {
resolve_err!(this, span, E0433, "{}", formatted);
}
#[derive(Copy, Clone)]
struct BindingInfo {
span: Span,
@ -1310,7 +1330,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
PathSearch,
true) {
Failed(Some((span, msg))) => {
resolve_err!(self, span, E0433, "failed to resolve. {}", msg);
resolve_err_433(self, span, &*format!("failed to resolve. {}", msg));
},
Failed(None) => (), // Continue up the search chain.
Indeterminate => {
@ -1568,11 +1588,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
.span_to_snippet((*imports)[index].span)
.unwrap();
if sn.contains("::") {
resolve_err!(self, (*imports)[index].span, E0432,
"{}", "unresolved import");
resolve_err_432(self, (*imports)[index].span, "unresolved import");
} else {
resolve_err!(self, (*imports)[index].span, E0432,
"unresolved import (maybe you meant `{}::*`?)", sn);
resolve_err_432(self, (*imports)[index].span,
&*format!("unresolved import (maybe you meant `{}::*`?)",
sn)
);
}
}
@ -2528,7 +2549,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
self.record_def(pattern.id, path_res);
}
DefStatic(..) => {
resolve_err!(self, path.span, E0417, "{}",
resolve_err_417(self, path.span,
"static variables cannot be \
referenced in a pattern, \
use a `const` instead");
@ -2609,9 +2630,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
result => {
debug!("(resolving pattern) didn't find struct \
def: {:?}", result);
resolve_err!(self, path.span, E0422,
"`{}` does not name a structure",
path_names_to_string(path, 0));
resolve_err_422(self, path.span,
&*format!("`{}` does not name a structure",
path_names_to_string(path, 0)));
}
}
visit::walk_path(self, path);
@ -2657,8 +2678,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
return FoundConst(def, LastMod(AllPublic));
}
DefStatic(..) => {
resolve_err!(self, span, E0417,
"{}",
resolve_err_417(self, span,
"static variables cannot be \
referenced in a pattern, \
use a `const` instead");
@ -2678,9 +2698,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
Failed(err) => {
match err {
Some((span, msg)) => {
resolve_err!(self, span, E0433,
"failed to resolve: {}",
msg);
resolve_err_433(self, span,
&*format!("failed to resolve: {}",
msg));
}
None => ()
}
@ -2909,9 +2929,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
};
resolve_err!(self, span, E0433,
"failed to resolve: {}",
msg);
resolve_err_433(self, span,
&*format!("failed to resolve: {}",
msg));
return None;
}
Indeterminate => panic!("indeterminate unexpected"),
@ -2972,9 +2992,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
/*self.resolve_error(span, &format!("failed to resolve. {}",
msg));*/
resolve_err!(self, span, E0433,
"failed to resolve: {}",
msg);
resolve_err_433(self, span,
&*format!("failed to resolve: {}",
msg));
return None;
}
@ -3070,9 +3090,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
failed to resolve {}", name);
if let Some((span, msg)) = err {
resolve_err!(self, span, E0433,
"failed to resolve: {}",
msg)
resolve_err_433(self, span,
&*format!("failed to resolve: {}",
msg))
}
return None;
@ -3274,11 +3294,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// Check if struct variant
if let DefVariant(_, _, true) = path_res.base_def {
let path_name = path_names_to_string(path, 0);
resolve_err!(self, expr.span, E0423,
"`{}` is a struct variant name, but \
this expression \
uses it like a function name",
path_name);
resolve_err_423(self, expr.span,
&*format!("`{}` is a struct variant name, but \
this expression \
uses it like a function name",
path_name));
let msg = format!("did you mean to write: \
`{} {{ /* fields */ }}`?",
@ -3315,11 +3335,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
match type_res.map(|r| r.base_def) {
Some(DefTy(struct_id, _))
if self.structs.contains_key(&struct_id) => {
resolve_err!(self, expr.span, E0423,
"{}` is a structure name, but \
this expression \
uses it like a function name",
path_name);
resolve_err_423(self, expr.span,
&*format!("{}` is a structure name, but \
this expression \
uses it like a function name",
path_name));
let msg = format!("did you mean to write: \
`{} {{ /* fields */ }}`?",
@ -3394,9 +3414,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
Some(definition) => self.record_def(expr.id, definition),
None => {
debug!("(resolving expression) didn't find struct def",);
resolve_err!(self, path.span, E0422,
"`{}` does not name a structure",
path_names_to_string(path, 0));
resolve_err_422(self, path.span,
&*format!("`{}` does not name a structure",
path_names_to_string(path, 0)));
}
}

View file

@ -272,12 +272,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
Some((span, msg)) => (span, format!(". {}", msg)),
None => (import_directive.span, String::new())
};
resolve_err!(self.resolver, span, E0432,
"unresolved import `{}`{}",
import_path_to_string(
&import_directive.module_path,
import_directive.subclass),
help);
::resolve_err_432(self.resolver, span,
&*format!("unresolved import `{}`{}",
import_path_to_string(
&import_directive.module_path,
import_directive.subclass),
help)
);
}
ResolveResult::Indeterminate => break, // Bail out. We'll come around next time.
ResolveResult::Success(()) => () // Good. Continue.