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);
+pub enum ResolutionError<'b, 'a:'b, 'tcx:'a> {
+ /// error: static variables cannot be referenced in a pattern
+ StaticVariableReference(&'b Resolver<'a, 'tcx>, syntax::codemap::Span),
+ /// error: does not name a struct
+ DoesNotNameAStruct(&'b Resolver<'a, 'tcx>, syntax::codemap::Span),
+ /// error: is a struct variant name, but this expression uses it like a function name
+ StructVariantUsedAsFunction(&'a Resolver<'a, 'tcx>, syntax::codemap::Span),
+ /// error: unresolved import
+ UnresolvedImport(&'b Resolver<'a, 'tcx>, syntax::codemap::Span),
+ /// error: failed to resolve
+ FailedToResolve(&'b Resolver<'a, 'tcx>, syntax::codemap::Span),
}
-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);
+fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolution_error: &ResolutionError<'b, 'a, 'tcx>, formatted: &str) {
+ match resolution_error {
+ &ResolutionError::StaticVariableReference(resolver, span) => {
+ resolve_err!(resolver, span, E0417, "{}", formatted);
+ },
+ &ResolutionError::DoesNotNameAStruct(resolver, span) => {
+ resolve_err!(resolver, span, E0422, "{}", formatted);
+ },
+ &ResolutionError::StructVariantUsedAsFunction(resolver, span) => {
+ resolve_err!(resolver, span, E0423, "{}", formatted);
+ },
+ &ResolutionError::UnresolvedImport(resolver, span) => {
+ resolve_err!(resolver, span, E0432, "{}", formatted);
+ },
+ &ResolutionError::FailedToResolve(resolver, span) => {
+ resolve_err!(resolver, span, E0433, "{}", formatted);
+ },
+ }
}
#[derive(Copy, Clone)]
PathSearch,
true) {
Failed(Some((span, msg))) => {
- resolve_err_433(self, span, &*format!("failed to resolve. {}", msg));
+ resolve_error(&ResolutionError::FailedToResolve(self, span),
+ &*format!("failed to resolve. {}",
+ msg)
+ );
},
Failed(None) => (), // Continue up the search chain.
Indeterminate => {
.span_to_snippet((*imports)[index].span)
.unwrap();
if sn.contains("::") {
- resolve_err_432(self, (*imports)[index].span, "unresolved import");
+ resolve_error(&ResolutionError::UnresolvedImport(self, (*imports)[index].span),
+ "unresolved import");
} else {
- resolve_err_432(self, (*imports)[index].span,
- &*format!("unresolved import (maybe you meant `{}::*`?)",
- sn)
- );
+ resolve_error(&ResolutionError::UnresolvedImport(self, (*imports)[index].span),
+ &*format!("unresolved import (maybe you meant `{}::*`?)",
+ sn)
+ );
}
}
self.record_def(pattern.id, path_res);
}
DefStatic(..) => {
- resolve_err_417(self, path.span,
- "static variables cannot be \
- referenced in a pattern, \
- use a `const` instead");
+ resolve_error(&ResolutionError::StaticVariableReference(&self, path.span),
+ "static variables cannot be \
+ referenced in a pattern, \
+ use a `const` instead");
}
_ => {
// If anything ends up here entirely resolved,
result => {
debug!("(resolving pattern) didn't find struct \
def: {:?}", result);
- resolve_err_422(self, path.span,
+ resolve_error(&ResolutionError::DoesNotNameAStruct(self, path.span),
&*format!("`{}` does not name a structure",
path_names_to_string(path, 0)));
}
return FoundConst(def, LastMod(AllPublic));
}
DefStatic(..) => {
- resolve_err_417(self, span,
- "static variables cannot be \
- referenced in a pattern, \
- use a `const` instead");
+ resolve_error(&ResolutionError::StaticVariableReference(self, span),
+ "static variables cannot be \
+ referenced in a pattern, \
+ use a `const` instead");
return BareIdentifierPatternUnresolved;
}
_ => {
Failed(err) => {
match err {
Some((span, msg)) => {
- resolve_err_433(self, span,
- &*format!("failed to resolve: {}",
- msg));
+ resolve_error(&ResolutionError::FailedToResolve(self, span),
+ &*format!("failed to resolve. {}",
+ msg)
+ );
}
None => ()
}
}
};
- resolve_err_433(self, span,
- &*format!("failed to resolve: {}",
- msg));
+ resolve_error(&ResolutionError::FailedToResolve(self, span),
+ &*format!("failed to resolve. {}",
+ msg)
+ );
return None;
}
Indeterminate => panic!("indeterminate unexpected"),
}
};
- /*self.resolve_error(span, &format!("failed to resolve. {}",
- msg));*/
- resolve_err_433(self, span,
- &*format!("failed to resolve: {}",
- msg));
+ resolve_error(&ResolutionError::FailedToResolve(self, span),
+ &*format!("failed to resolve. {}",
+ msg)
+ );
return None;
}
failed to resolve {}", name);
if let Some((span, msg)) = err {
- resolve_err_433(self, span,
- &*format!("failed to resolve: {}",
- msg))
+ resolve_error(&ResolutionError::FailedToResolve(self, span),
+ &*format!("failed to resolve. {}",
+ msg)
+ )
}
return None;
// Check if struct variant
if let DefVariant(_, _, true) = path_res.base_def {
let path_name = path_names_to_string(path, 0);
- resolve_err_423(self, expr.span,
- &*format!("`{}` is a struct variant name, but \
- this expression \
- uses it like a function name",
- path_name));
+
+ resolve_error(&ResolutionError::StructVariantUsedAsFunction(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 */ }}`?",
match type_res.map(|r| r.base_def) {
Some(DefTy(struct_id, _))
if self.structs.contains_key(&struct_id) => {
- resolve_err_423(self, expr.span,
- &*format!("{}` is a structure name, but \
- this expression \
- uses it like a function name",
- path_name));
+ resolve_error(&ResolutionError::StructVariantUsedAsFunction(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 */ }}`?",
Some(definition) => self.record_def(expr.id, definition),
None => {
debug!("(resolving expression) didn't find struct def",);
- resolve_err_422(self, path.span,
+
+ resolve_error(&ResolutionError::DoesNotNameAStruct(self, path.span),
&*format!("`{}` does not name a structure",
path_names_to_string(path, 0)));
}