From c3fd0e12297d9e535f8e8e70eb942babfc11901d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 8 Jul 2015 22:55:22 +0200 Subject: Remove token::get_name when unneeded --- src/librustc_resolve/lib.rs | 80 ++++++++++++++++++--------------- src/librustc_resolve/resolve_imports.rs | 30 ++++++------- 2 files changed, 60 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 5d10b0d9a57..f879f1c09f6 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -109,6 +109,14 @@ mod record_exports; mod build_reduced_graph; mod resolve_imports; +macro_rules! resolve_err { + ($this:expr, $($rest:tt)*) => { + if $this.emit_errors { + span_err!($this.session, $($rest)*); + } + } +} + #[derive(Copy, Clone)] struct BindingInfo { span: Span, @@ -947,8 +955,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if module.external_module_children.borrow().contains_key(&name) { span_err!(self.session, span, E0259, "an external crate named `{}` has already \ - been imported into this module", - &token::get_name(name)); + been imported into this module", + name); } } @@ -960,9 +968,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if module.external_module_children.borrow().contains_key(&name) { span_err!(self.session, span, E0260, "the name `{}` conflicts with an external \ - crate that has been imported into this \ - module", - &token::get_name(name)); + crate that has been imported into this \ + module", + name); } } @@ -1041,7 +1049,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Indeterminate => { debug!("(resolving module path for import) module \ resolution is indeterminate: {}", - token::get_name(name)); + name); return Indeterminate; } Success((target, used_proxy)) => { @@ -1052,7 +1060,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { match type_def.module_def { None => { let msg = format!("Not a module `{}`", - token::get_name(name)); + name); return Failed(Some((span, msg))); } @@ -1078,7 +1086,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { None => { // There are no type bindings at all. let msg = format!("Not a module `{}`", - token::get_name(name)); + name); return Failed(Some((span, msg))); } } @@ -1200,7 +1208,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { -> ResolveResult<(Target, bool)> { debug!("(resolving item in lexical scope) resolving `{}` in \ namespace {:?} in `{}`", - token::get_name(name), + name, namespace, module_to_string(&*module_)); @@ -1302,9 +1310,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { namespace, PathSearch, true) { - Failed(Some((span, msg))) => - self.resolve_error(span, &format!("failed to resolve. {}", - msg)), + Failed(Some((span, msg))) => { + self.resolve_error(span, + &format!("failed to resolve. {}", + msg)); + }, Failed(None) => (), // Continue up the search chain. Indeterminate => { // We couldn't see through the higher scope because of an @@ -1469,7 +1479,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { allow_private_imports: bool) -> ResolveResult<(Target, bool)> { debug!("(resolving name in module) resolving `{}` in `{}`", - &token::get_name(name), + name, module_to_string(&*module_)); // First, check the direct children of the module. @@ -1547,7 +1557,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // We're out of luck. debug!("(resolving name in module) failed to resolve `{}`", - &token::get_name(name)); + name); return Failed(None); } @@ -1623,7 +1633,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { match orig_module.children.borrow().get(&name) { None => { debug!("!!! (with scope) didn't find `{}` in `{}`", - token::get_name(name), + name, module_to_string(&*orig_module)); } Some(name_bindings) => { @@ -1631,7 +1641,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { None => { debug!("!!! (with scope) didn't find module \ for `{}` in `{}`", - token::get_name(name), + name, module_to_string(&*orig_module)); } Some(module_) => { @@ -1795,7 +1805,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let name = item.ident.name; debug!("(resolving item) resolving {}", - token::get_name(name)); + name); match item.node { ItemEnum(_, ref generics) | @@ -1931,7 +1941,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { used for a type \ parameter in this type \ parameter list", - token::get_name(name))) + name)) } seen_bindings.insert(name); @@ -2177,7 +2187,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let path_str = path_names_to_string(&trait_ref.path, 0); self.resolve_error(span, &format!("method `{}` is not a member of trait `{}`", - token::get_name(name), + name, path_str)); } } @@ -2229,7 +2239,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { p.span, &format!("variable `{}` from pattern #1 is \ not bound in pattern #{}", - token::get_name(key), + key, i + 1)); } Some(binding_i) => { @@ -2238,7 +2248,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { binding_i.span, &format!("variable `{}` is bound with different \ mode in pattern #{} than in pattern #1", - token::get_name(key), + key, i + 1)); } } @@ -2251,7 +2261,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { binding.span, &format!("variable `{}` from pattern {}{} is \ not bound in pattern {}1", - token::get_name(key), + key, "#", i + 1, "#")); } } @@ -2410,7 +2420,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if mode == RefutableMode => { debug!("(resolving pattern) resolving `{}` to \ struct or enum variant", - token::get_name(renamed)); + renamed); self.enforce_default_binding_mode( pattern, @@ -2428,12 +2438,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &format!("declaration of `{}` shadows an enum \ variant or unit-like struct in \ scope", - token::get_name(renamed))); + renamed)); } FoundConst(def, lp) if mode == RefutableMode => { debug!("(resolving pattern) resolving `{}` to \ constant", - token::get_name(renamed)); + renamed); self.enforce_default_binding_mode( pattern, @@ -2452,7 +2462,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } BareIdentifierPatternUnresolved => { debug!("(resolving pattern) binding `{}`", - token::get_name(renamed)); + renamed); let def = DefLocal(pattern.id); @@ -2639,7 +2649,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Success((target, _)) => { debug!("(resolve bare identifier pattern) succeeded in \ finding {} at {:?}", - token::get_name(name), + name, target.bindings.value_def.borrow()); match *target.bindings.value_def.borrow() { None => { @@ -2685,7 +2695,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } debug!("(resolve bare identifier pattern) failed to find {}", - token::get_name(name)); + name); return BareIdentifierPatternUnresolved; } } @@ -3043,13 +3053,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // found a module instead. Modules don't have defs. debug!("(resolving item path by identifier in lexical \ scope) failed to resolve {} after success...", - token::get_name(name)); + name); return None; } Some(def) => { debug!("(resolving item path in lexical scope) \ resolved `{}` to item", - token::get_name(name)); + name); // This lookup is "all public" because it only searched // for one identifier in the current module (couldn't // have passed through reexports or anything like that. @@ -3062,7 +3072,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } Failed(err) => { debug!("(resolving item path by identifier in lexical scope) \ - failed to resolve {}", token::get_name(name)); + failed to resolve {}", name); if let Some((span, msg)) = err { self.resolve_error(span, &format!("failed to resolve. {}", msg)) @@ -3472,7 +3482,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { fn get_traits_containing_item(&mut self, name: Name) -> Vec { debug!("(getting traits containing item) looking for '{}'", - token::get_name(name)); + name); fn add_trait_info(found_traits: &mut Vec, trait_def_id: DefId, @@ -3480,7 +3490,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("(adding trait info) found trait {}:{} for method '{}'", trait_def_id.krate, trait_def_id.node, - token::get_name(name)); + name); found_traits.push(trait_def_id); } @@ -3591,7 +3601,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("Children:"); build_reduced_graph::populate_module_if_necessary(self, &module_); for (&name, _) in module_.children.borrow().iter() { - debug!("* {}", token::get_name(name)); + debug!("* {}", name); } debug!("Import resolutions:"); @@ -3615,7 +3625,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } - debug!("* {}:{}{}", token::get_name(name), value_repr, type_repr); + debug!("* {}:{}{}", name, value_repr, type_repr); } } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index e77e7116b9f..a08d022ffcd 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -394,9 +394,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { -> ResolveResult<()> { debug!("(resolving single import) resolving `{}` = `{}::{}` from \ `{}` id {}, last private {:?}", - token::get_name(target), + target, module_to_string(&*target_module), - token::get_name(source), + source, module_to_string(module_), directive.id, lp); @@ -431,7 +431,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { value_result = BoundResult(target_module.clone(), (*child_name_bindings).clone()); if directive.is_public && !child_name_bindings.is_public(ValueNS) { - let msg = format!("`{}` is private", token::get_name(source)); + let msg = format!("`{}` is private", source); span_err!(self.resolver.session, directive.span, E0364, "{}", &msg); pub_err = true; } @@ -441,7 +441,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { type_result = BoundResult(target_module.clone(), (*child_name_bindings).clone()); if !pub_err && directive.is_public && !child_name_bindings.is_public(TypeNS) { - let msg = format!("`{}` is private", token::get_name(source)); + let msg = format!("`{}` is private", source); span_err!(self.resolver.session, directive.span, E0365, "{}", &msg); } } @@ -655,7 +655,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { if value_result.is_unbound() && type_result.is_unbound() { let msg = format!("There is no `{}` in `{}`", - token::get_name(source), + source, module_to_string(&target_module)); return ResolveResult::Failed(Some((directive.span, msg))); } @@ -736,7 +736,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { for (ident, target_import_resolution) in import_resolutions.iter() { debug!("(resolving glob import) writing module resolution \ {} into `{}`", - token::get_name(*ident), + *ident, module_to_string(module_)); if !target_import_resolution.is_public { @@ -842,7 +842,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { debug!("(resolving glob import) writing resolution `{}` in `{}` \ to `{}`", - &token::get_name(name), + name, module_to_string(&*containing_module), module_to_string(module_)); @@ -861,7 +861,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { let msg = format!("a {} named `{}` has already been imported \ in this module", namespace_name, - &token::get_name(name)); + name); span_err!(self.resolver.session, import_directive.span, E0251, "{}", msg); } else { let target = Target::new(containing_module.clone(), @@ -894,7 +894,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { namespace: Namespace) { let target = import_resolution.target_for_namespace(namespace); debug!("check_for_conflicting_import: {}; target exists: {}", - &token::get_name(name), + name, target.is_some()); match target { @@ -918,13 +918,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { span_err!(self.resolver.session, import_span, E0252, "a {} named `{}` has already been imported \ in this module", ns_word, - &token::get_name(name)); + name); let use_id = import_resolution.id(namespace); let item = self.resolver.ast_map.expect_item(use_id); // item is syntax::ast::Item; span_note!(self.resolver.session, item.span, "previous import of `{}` here", - token::get_name(name)); + name); } Some(_) | None => {} } @@ -938,7 +938,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { namespace: Namespace) { if !name_bindings.defined_in_namespace_with(namespace, DefModifiers::IMPORTABLE) { let msg = format!("`{}` is not directly importable", - token::get_name(name)); + name); span_err!(self.resolver.session, import_span, E0253, "{}", &msg[..]); } } @@ -959,7 +959,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { let msg = format!("import `{0}` conflicts with imported \ crate in this module \ (maybe you meant `use {0}::*`?)", - &token::get_name(name)); + name); span_err!(self.resolver.session, import_span, E0254, "{}", &msg[..]); } Some(_) | None => {} @@ -981,7 +981,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { if let Some(ref value) = *name_bindings.value_def.borrow() { span_err!(self.resolver.session, import_span, E0255, "import `{}` conflicts with value in this module", - &token::get_name(name)); + name); if let Some(span) = value.value_span { self.resolver.session.span_note(span, "conflicting value here"); } @@ -1004,7 +1004,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { }; span_err!(self.resolver.session, import_span, E0256, "import `{}` conflicts with {}", - &token::get_name(name), what); + name, what); if let Some(span) = ty.type_span { self.resolver.session.span_note(span, note); } -- cgit 1.4.1-3-g733a5 From 2e00b3177001dd8281038930f4a5d0f214420bc4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 11 Jul 2015 21:46:06 +0200 Subject: We just have to replace error codes but code is good now --- src/librustc_resolve/diagnostics.rs | 4 +- src/librustc_resolve/lib.rs | 295 +++++++++++++++++++++++++++--------- 2 files changed, 222 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 15ddcbc8074..06019b96f6f 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -202,8 +202,8 @@ http://doc.rust-lang.org/reference.html#types } register_diagnostics! { - E0157, - E0153, + E0153, // called no where + E0157, // called from no where E0253, // not directly importable E0254, // import conflicts with imported crate in this module E0257, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index f879f1c09f6..b314772c8cb 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -109,10 +109,17 @@ mod record_exports; mod build_reduced_graph; mod resolve_imports; +macro_rules! span_err { + ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ + __diagnostic_used!($code); + $session.span_err_with_code($span, &format!($($message)*), stringify!($code)) + }) +} + macro_rules! resolve_err { - ($this:expr, $($rest:tt)*) => { + ($this:expr, $span:expr, $code:ident, $($rest:tt)*) => { if $this.emit_errors { - span_err!($this.session, $($rest)*); + span_err!($this.session, $span, $code, $($rest)*); } } } @@ -1311,9 +1318,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { PathSearch, true) { Failed(Some((span, msg))) => { - self.resolve_error(span, + /*self.resolve_error(span, &format!("failed to resolve. {}", - msg)); + msg));*/ + resolve_err!(self, span, E0253, "failed to resolve. {}", msg); }, Failed(None) => (), // Continue up the search chain. Indeterminate => { @@ -1571,12 +1579,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .span_to_snippet((*imports)[index].span) .unwrap(); if sn.contains("::") { - self.resolve_error((*imports)[index].span, - "unresolved import"); + /*self.resolve_error((*imports)[index].span, + "unresolved import");*/ + resolve_err!(self, (*imports)[index].span, E0253, + "{}", "unresolved import"); } else { - let err = format!("unresolved import (maybe you meant `{}::*`?)", + /*let err = format!("unresolved import (maybe you meant `{}::*`?)", sn); - self.resolve_error((*imports)[index].span, &err[..]); + self.resolve_error((*imports)[index].span, &err[..]);*/ + resolve_err!(self, (*imports)[index].span, E0253, + "unresolved import (maybe you meant `{}::*`?)", sn); } } @@ -1703,16 +1715,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // named function item. This is not allowed, so we // report an error. - self.resolve_error(span, + /*self.resolve_error(span, "can't capture dynamic environment in a fn item; \ - use the || { ... } closure form instead"); + use the || { ... } closure form instead");*/ + resolve_err!(self, span, E0253, "{}", + "can't capture dynamic environment in a fn item; \ + use the || { ... } closure form instead"); return None; } ConstantItemRibKind => { // Still doesn't deal with upvars - self.resolve_error(span, + /*self.resolve_error(span, "attempt to use a non-constant \ - value in a constant"); + value in a constant");*/ + resolve_err!(self, span, E0253, "{}", + "attempt to use a non-constant \ + value in a constant"); return None; } } @@ -1728,17 +1746,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // This was an attempt to use a type parameter outside // its scope. - self.resolve_error(span, + /*self.resolve_error(span, "can't use type parameters from \ outer function; try using a local \ - type parameter instead"); + type parameter instead");*/ + resolve_err!(self, span, E0253, "{}", + "can't use type parameters from \ + outer function; try using a local \ + type parameter instead"); return None; } ConstantItemRibKind => { // see #9186 - self.resolve_error(span, + /*self.resolve_error(span, "cannot use an outer type \ - parameter in this context"); + parameter in this context");*/ + resolve_err!(self, span, E0253, "{}", + "cannot use an outer type \ + parameter in this context"); return None; } } @@ -1936,12 +1961,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("with_type_parameter_rib: {}", type_parameter.id); if seen_bindings.contains(&name) { - self.resolve_error(type_parameter.span, + /*self.resolve_error(type_parameter.span, &format!("the name `{}` is already \ used for a type \ parameter in this type \ parameter list", - name)) + name))*/ + resolve_err!(self, type_parameter.span, E0253, + "the name `{}` is already \ + used for a type \ + parameter in this type \ + parameter list", + name) } seen_bindings.insert(name); @@ -2028,9 +2059,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("(resolving trait) found trait def: {:?}", path_res); Ok(path_res) } else { - self.resolve_error(trait_path.span, + /*self.resolve_error(trait_path.span, &format!("`{}` is not a trait", - path_names_to_string(trait_path, path_depth))); + path_names_to_string(trait_path, path_depth)));*/ + resolve_err!(self, trait_path.span, E0253, + "`{}` is not a trait", + path_names_to_string(trait_path, path_depth)); // If it's a typedef, give a note if let DefTy(..) = path_res.base_def { @@ -2040,9 +2074,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Err(()) } } else { - let msg = format!("use of undeclared trait name `{}`", + /*let msg = format!("use of undeclared trait name `{}`", path_names_to_string(trait_path, path_depth)); - self.resolve_error(trait_path.span, &msg); + self.resolve_error(trait_path.span, &msg);*/ + resolve_err!(self, trait_path.span, E0253, + "use of undeclared trait name `{}`", + path_names_to_string(trait_path, path_depth)); Err(()) } } @@ -2060,7 +2097,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(PathResolution { base_def: DefTyParam(..), .. }) = path_res { self.record_def(eq_pred.id, path_res.unwrap()); } else { - self.resolve_error(eq_pred.path.span, "undeclared associated type"); + //self.resolve_error(eq_pred.path.span, "undeclared associated type"); + resolve_err!(self, eq_pred.span, E0253, "{}", + "undeclared associated type"); } } } @@ -2185,10 +2224,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some((did, ref trait_ref)) = self.current_trait_ref { if !self.trait_item_map.contains_key(&(name, did)) { let path_str = path_names_to_string(&trait_ref.path, 0); - self.resolve_error(span, + /*self.resolve_error(span, &format!("method `{}` is not a member of trait `{}`", name, - path_str)); + path_str));*/ + resolve_err!(self, span, E0253, "method `{}` is not a member of trait `{}`", + name, path_str); } } } @@ -2235,21 +2276,31 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding_0) in &map_0 { match map_i.get(&key) { None => { - self.resolve_error( + /*self.resolve_error( p.span, &format!("variable `{}` from pattern #1 is \ not bound in pattern #{}", key, - i + 1)); + i + 1));*/ + resolve_err!(self, p.span, E0253, + "variable `{}` from pattern #1 is \ + not bound in pattern #{}", + key, + i + 1); } Some(binding_i) => { if binding_0.binding_mode != binding_i.binding_mode { - self.resolve_error( + /*self.resolve_error( binding_i.span, &format!("variable `{}` is bound with different \ mode in pattern #{} than in pattern #1", key, - i + 1)); + i + 1));*/ + resolve_err!(self, binding_i.span, E0253, + "variable `{}` is bound with different \ + mode in pattern #{} than in pattern #1", + key, + i + 1); } } } @@ -2257,12 +2308,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding) in &map_i { if !map_0.contains_key(&key) { - self.resolve_error( + /*self.resolve_error( binding.span, &format!("variable `{}` from pattern {}{} is \ not bound in pattern {}1", key, - "#", i + 1, "#")); + "#", i + 1, "#"));*/ + resolve_err!(self, binding.span, E0253, + "variable `{}` from pattern {}{} is \ + not bound in pattern {}1", + key, + "#", i + 1, "#"); } } } @@ -2382,7 +2438,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { kind, path_names_to_string(path, 0)) }; - self.resolve_error(ty.span, &msg[..]); + //self.resolve_error(ty.span, &msg[..]); + resolve_err!(self, ty.span, E0253, + "{}", msg); } } } @@ -2433,12 +2491,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); } FoundStructOrEnumVariant(..) => { - self.resolve_error( + /*self.resolve_error( pattern.span, &format!("declaration of `{}` shadows an enum \ variant or unit-like struct in \ scope", - renamed)); + renamed));*/ + resolve_err!(self, pattern.span, E0253, + "declaration of `{}` shadows an enum \ + variant or unit-like struct in \ + scope", + renamed); } FoundConst(def, lp) if mode == RefutableMode => { debug!("(resolving pattern) resolving `{}` to \ @@ -2456,9 +2519,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); } FoundConst(..) => { - self.resolve_error(pattern.span, + /*self.resolve_error(pattern.span, "only irrefutable patterns \ - allowed here"); + allowed here");*/ + resolve_err!(self, pattern.span, E0253, + "{}", + "only irrefutable patterns \ + allowed here"); } BareIdentifierPatternUnresolved => { debug!("(resolving pattern) binding `{}`", @@ -2490,7 +2557,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { bindings_list.contains_key(&renamed) { // Forbid duplicate bindings in the same // parameter list. - self.resolve_error(pattern.span, + /*self.resolve_error(pattern.span, &format!("identifier `{}` \ is bound more \ than once in \ @@ -2498,16 +2565,28 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { list", token::get_ident( ident)) - ) + )*/ + resolve_err!(self, pattern.span, E0253, + "identifier `{}` \ + is bound more \ + than once in \ + this parameter \ + list", + token::get_ident(ident)); } else if bindings_list.get(&renamed) == Some(&pat_id) { // Then this is a duplicate variable in the // same disjunction, which is an error. - self.resolve_error(pattern.span, + /*self.resolve_error(pattern.span, &format!("identifier `{}` is bound \ more than once in the same \ pattern", - token::get_ident(ident))); + token::get_ident(ident)));*/ + resolve_err!(self, pattern.span, E0253, + "identifier `{}` is bound \ + more than once in the same \ + pattern", + token::get_ident(ident)); } // Else, not bound in the same pattern: do // nothing. @@ -2538,10 +2617,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.record_def(pattern.id, path_res); } DefStatic(..) => { - self.resolve_error(path.span, + /*self.resolve_error(path.span, "static variables cannot be \ referenced in a pattern, \ - use a `const` instead"); + use a `const` instead");*/ + resolve_err!(self, path.span, E0253, "{}", + "static variables cannot be \ + referenced in a pattern, \ + use a `const` instead"); } _ => { // If anything ends up here entirely resolved, @@ -2549,11 +2632,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // partially resolved, that's OK, because it may // be a `T::CONST` that typeck will resolve. if path_res.depth == 0 { - self.resolve_error( + /*self.resolve_error( path.span, &format!("`{}` is not an enum variant, struct or const", token::get_ident( - path.segments.last().unwrap().identifier))); + path.segments.last().unwrap().identifier)));*/ + resolve_err!(self, path.span, E0253, + "`{}` is not an enum variant, struct or const", + token::get_ident( + path.segments.last().unwrap().identifier)); } else { let const_name = path.segments.last().unwrap() .identifier.name; @@ -2564,9 +2651,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } } else { - self.resolve_error(path.span, + /*self.resolve_error(path.span, &format!("unresolved enum variant, struct or const `{}`", - token::get_ident(path.segments.last().unwrap().identifier))); + token::get_ident(path.segments.last().unwrap().identifier)));*/ + resolve_err!(self, path.span, E0253, + "unresolved enum variant, struct or const `{}`", + token::get_ident(path.segments.last().unwrap().identifier)); } visit::walk_path(self, path); } @@ -2598,16 +2688,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.record_def(pattern.id, path_res); } _ => { - self.resolve_error(path.span, + /*self.resolve_error(path.span, &format!("`{}` is not an associated const", token::get_ident( - path.segments.last().unwrap().identifier))); + path.segments.last().unwrap().identifier)));*/ + resolve_err!(self, path.span, E0253, + "`{}` is not an associated const", + token::get_ident( + path.segments.last().unwrap().identifier)); } } } else { - self.resolve_error(path.span, + /*self.resolve_error(path.span, &format!("unresolved associated const `{}`", - token::get_ident(path.segments.last().unwrap().identifier))); + token::get_ident(path.segments.last().unwrap().identifier)));*/ + resolve_err!(self, path.span, E0253, + "unresolved associated const `{}`", + token::get_ident(path.segments.last().unwrap().identifier)); } visit::walk_pat(self, pattern); } @@ -2620,9 +2717,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { result => { debug!("(resolving pattern) didn't find struct \ def: {:?}", result); - let msg = format!("`{}` does not name a structure", + /*let msg = format!("`{}` does not name a structure", path_names_to_string(path, 0)); - self.resolve_error(path.span, &msg[..]); + self.resolve_error(path.span, &msg[..]);*/ + resolve_err!(self, path.span, E0253, + "`{}` does not name a structure", + path_names_to_string(path, 0)); } } visit::walk_path(self, path); @@ -2668,10 +2768,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { return FoundConst(def, LastMod(AllPublic)); } DefStatic(..) => { - self.resolve_error(span, + /*self.resolve_error(span, "static variables cannot be \ referenced in a pattern, \ - use a `const` instead"); + use a `const` instead");*/ + resolve_err!(self, span, E0253, + "{}", + "static variables cannot be \ + referenced in a pattern, \ + use a `const` instead"); return BareIdentifierPatternUnresolved; } _ => { @@ -2688,8 +2793,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Failed(err) => { match err { Some((span, msg)) => { - self.resolve_error(span, &format!("failed to resolve: {}", - msg)); + /*self.resolve_error(span, &format!("failed to resolve: {}", + msg));*/ + resolve_err!(self, span, E0253, + "failed to resolve: {}", + msg); } None => () } @@ -2918,8 +3026,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - self.resolve_error(span, &format!("failed to resolve. {}", - msg)); + /*self.resolve_error(span, &format!("failed to resolve. {}", + msg));*/ + resolve_err!(self, span, E0253, + "failed to resolve: {}", + msg); return None; } Indeterminate => panic!("indeterminate unexpected"), @@ -2978,8 +3089,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - self.resolve_error(span, &format!("failed to resolve. {}", - msg)); + /*self.resolve_error(span, &format!("failed to resolve. {}", + msg));*/ + resolve_err!(self, span, E0253, + "failed to resolve: {}", + msg); return None; } @@ -3075,7 +3189,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { failed to resolve {}", name); if let Some((span, msg)) = err { - self.resolve_error(span, &format!("failed to resolve. {}", msg)) + //self.resolve_error(span, &format!("failed to resolve. {}", msg)) + resolve_err!(self, span, E0253, + "failed to resolve: {}", + msg) } return None; @@ -3283,11 +3400,16 @@ 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); - self.resolve_error(expr.span, + /*self.resolve_error(expr.span, &format!("`{}` is a struct variant name, but \ this expression \ uses it like a function name", - path_name)); + path_name));*/ + resolve_err!(self, expr.span, E0253, + "`{}` 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 */ }}`?", @@ -3324,11 +3446,16 @@ 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) => { - self.resolve_error(expr.span, + /*self.resolve_error(expr.span, &format!("`{}` is a structure name, but \ this expression \ uses it like a function name", - path_name)); + path_name));*/ + resolve_err!(self, expr.span, E0253, + "{}` is a structure name, but \ + this expression \ + uses it like a function name", + path_name); let msg = format!("did you mean to write: \ `{} {{ /* fields */ }}`?", @@ -3355,11 +3482,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if method_scope && &token::get_name(special_names::self_)[..] == path_name { - self.resolve_error( + /*self.resolve_error( expr.span, "`self` is not available \ in a static method. Maybe a \ - `self` argument is missing?"); + `self` argument is missing?");*/ + resolve_err!(self, expr.span, E0253, + "{}", + "`self` is not available \ + in a static method. Maybe a \ + `self` argument is missing?"); } else { let last_name = path.segments.last().unwrap().identifier.name; let mut msg = match self.find_fallback_in_self_type(last_name) { @@ -3383,10 +3515,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { msg = format!(". Did you mean {}?", msg) } - self.resolve_error( + /*self.resolve_error( expr.span, &format!("unresolved name `{}`{}", - path_name, msg)); + path_name, msg));*/ + resolve_err!(self, expr.span, E0253, + "unresolved name `{}`{}", + path_name, + msg); } } } @@ -3403,9 +3539,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Some(definition) => self.record_def(expr.id, definition), None => { debug!("(resolving expression) didn't find struct def",); - let msg = format!("`{}` does not name a structure", + /*let msg = format!("`{}` does not name a structure", path_names_to_string(path, 0)); - self.resolve_error(path.span, &msg[..]); + self.resolve_error(path.span, &msg[..]);*/ + resolve_err!(self, path.span, E0253, + "`{}` does not name a structure", + path_names_to_string(path, 0)); } } @@ -3430,10 +3569,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let renamed = mtwt::resolve(label); match self.search_label(renamed) { None => { - self.resolve_error( + /*self.resolve_error( expr.span, &format!("use of undeclared label `{}`", - token::get_ident(label))) + token::get_ident(label)))*/ + resolve_err!(self, expr.span, E0253, + "use of undeclared label `{}`", + token::get_ident(label)) } Some(DlDef(def @ DefLabel(_))) => { // Since this def is a label, it is never read. @@ -3579,10 +3721,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { match pat_binding_mode { BindByValue(_) => {} BindByRef(..) => { - self.resolve_error(pat.span, + /*self.resolve_error(pat.span, &format!("cannot use `ref` binding mode \ with {}", - descr)); + descr));*/ + resolve_err!(self, pat.span, E0253, + "cannot use `ref` binding mode with {}", + descr); } } } -- cgit 1.4.1-3-g733a5 From 8b731a5cac22f37d3709c889e4de342ca851e3ff Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Jul 2015 00:31:09 +0200 Subject: Add error codes --- src/librustc_resolve/build_reduced_graph.rs | 21 ++- src/librustc_resolve/diagnostics.rs | 42 ++++- src/librustc_resolve/lib.rs | 258 ++++++---------------------- src/librustc_resolve/resolve_imports.rs | 8 +- 4 files changed, 113 insertions(+), 216 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 30d5a4f111b..00745136eef 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -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 { @@ -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, @@ -325,8 +326,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { _ => None }).collect::>(); 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"); @@ -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; diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 06019b96f6f..34cd6ef002e 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -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 } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b314772c8cb..c0e42f269ee 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -26,6 +26,16 @@ #![feature(slice_extras)] #![feature(staged_api)] +#![macro_use] + +macro_rules! resolve_err { + ($this:expr, $span:expr, $code:ident, $($rest:tt)*) => { + if $this.emit_errors { + span_err!($this.session, $span, $code, $($rest)*); + } + } +} + #[macro_use] extern crate log; #[macro_use] extern crate syntax; #[macro_use] #[no_link] extern crate rustc_bitflags; @@ -109,21 +119,6 @@ mod record_exports; mod build_reduced_graph; mod resolve_imports; -macro_rules! span_err { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - __diagnostic_used!($code); - $session.span_err_with_code($span, &format!($($message)*), stringify!($code)) - }) -} - -macro_rules! resolve_err { - ($this:expr, $span:expr, $code:ident, $($rest:tt)*) => { - if $this.emit_errors { - span_err!($this.session, $span, $code, $($rest)*); - } - } -} - #[derive(Copy, Clone)] struct BindingInfo { span: Span, @@ -1318,10 +1313,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { PathSearch, true) { Failed(Some((span, msg))) => { - /*self.resolve_error(span, - &format!("failed to resolve. {}", - msg));*/ - resolve_err!(self, span, E0253, "failed to resolve. {}", msg); + resolve_err!(self, span, E0397, "failed to resolve. {}", msg); }, Failed(None) => (), // Continue up the search chain. Indeterminate => { @@ -1579,15 +1571,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .span_to_snippet((*imports)[index].span) .unwrap(); if sn.contains("::") { - /*self.resolve_error((*imports)[index].span, - "unresolved import");*/ - resolve_err!(self, (*imports)[index].span, E0253, + resolve_err!(self, (*imports)[index].span, E0398, "{}", "unresolved import"); } else { - /*let err = format!("unresolved import (maybe you meant `{}::*`?)", - sn); - self.resolve_error((*imports)[index].span, &err[..]);*/ - resolve_err!(self, (*imports)[index].span, E0253, + resolve_err!(self, (*imports)[index].span, E0398, "unresolved import (maybe you meant `{}::*`?)", sn); } } @@ -1714,21 +1701,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we // report an error. - - /*self.resolve_error(span, - "can't capture dynamic environment in a fn item; \ - use the || { ... } closure form instead");*/ - resolve_err!(self, span, E0253, "{}", + resolve_err!(self, span, E0399, "{}", "can't capture dynamic environment in a fn item; \ use the || { ... } closure form instead"); return None; } ConstantItemRibKind => { // Still doesn't deal with upvars - /*self.resolve_error(span, - "attempt to use a non-constant \ - value in a constant");*/ - resolve_err!(self, span, E0253, "{}", + resolve_err!(self, span, E0400, "{}", "attempt to use a non-constant \ value in a constant"); return None; @@ -1746,11 +1726,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // This was an attempt to use a type parameter outside // its scope. - /*self.resolve_error(span, - "can't use type parameters from \ - outer function; try using a local \ - type parameter instead");*/ - resolve_err!(self, span, E0253, "{}", + resolve_err!(self, span, E0401, "{}", "can't use type parameters from \ outer function; try using a local \ type parameter instead"); @@ -1758,10 +1734,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } ConstantItemRibKind => { // see #9186 - /*self.resolve_error(span, - "cannot use an outer type \ - parameter in this context");*/ - resolve_err!(self, span, E0253, "{}", + resolve_err!(self, span, E0402, "{}", "cannot use an outer type \ parameter in this context"); return None; @@ -1961,13 +1934,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("with_type_parameter_rib: {}", type_parameter.id); if seen_bindings.contains(&name) { - /*self.resolve_error(type_parameter.span, - &format!("the name `{}` is already \ - used for a type \ - parameter in this type \ - parameter list", - name))*/ - resolve_err!(self, type_parameter.span, E0253, + resolve_err!(self, type_parameter.span, E0403, "the name `{}` is already \ used for a type \ parameter in this type \ @@ -2059,10 +2026,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("(resolving trait) found trait def: {:?}", path_res); Ok(path_res) } else { - /*self.resolve_error(trait_path.span, - &format!("`{}` is not a trait", - path_names_to_string(trait_path, path_depth)));*/ - resolve_err!(self, trait_path.span, E0253, + resolve_err!(self, trait_path.span, E0404, "`{}` is not a trait", path_names_to_string(trait_path, path_depth)); @@ -2074,10 +2038,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Err(()) } } else { - /*let msg = format!("use of undeclared trait name `{}`", - path_names_to_string(trait_path, path_depth)); - self.resolve_error(trait_path.span, &msg);*/ - resolve_err!(self, trait_path.span, E0253, + resolve_err!(self, trait_path.span, E0405, "use of undeclared trait name `{}`", path_names_to_string(trait_path, path_depth)); Err(()) @@ -2097,8 +2058,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(PathResolution { base_def: DefTyParam(..), .. }) = path_res { self.record_def(eq_pred.id, path_res.unwrap()); } else { - //self.resolve_error(eq_pred.path.span, "undeclared associated type"); - resolve_err!(self, eq_pred.span, E0253, "{}", + resolve_err!(self, eq_pred.span, E0406, "{}", "undeclared associated type"); } } @@ -2224,11 +2184,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some((did, ref trait_ref)) = self.current_trait_ref { if !self.trait_item_map.contains_key(&(name, did)) { let path_str = path_names_to_string(&trait_ref.path, 0); - /*self.resolve_error(span, - &format!("method `{}` is not a member of trait `{}`", - name, - path_str));*/ - resolve_err!(self, span, E0253, "method `{}` is not a member of trait `{}`", + resolve_err!(self, span, E0407, "method `{}` is not a member of trait `{}`", name, path_str); } } @@ -2276,13 +2232,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding_0) in &map_0 { match map_i.get(&key) { None => { - /*self.resolve_error( - p.span, - &format!("variable `{}` from pattern #1 is \ - not bound in pattern #{}", - key, - i + 1));*/ - resolve_err!(self, p.span, E0253, + resolve_err!(self, p.span, E0408, "variable `{}` from pattern #1 is \ not bound in pattern #{}", key, @@ -2290,13 +2240,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } Some(binding_i) => { if binding_0.binding_mode != binding_i.binding_mode { - /*self.resolve_error( - binding_i.span, - &format!("variable `{}` is bound with different \ - mode in pattern #{} than in pattern #1", - key, - i + 1));*/ - resolve_err!(self, binding_i.span, E0253, + resolve_err!(self, binding_i.span, E0409, "variable `{}` is bound with different \ mode in pattern #{} than in pattern #1", key, @@ -2308,13 +2252,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding) in &map_i { if !map_0.contains_key(&key) { - /*self.resolve_error( - binding.span, - &format!("variable `{}` from pattern {}{} is \ - not bound in pattern {}1", - key, - "#", i + 1, "#"));*/ - resolve_err!(self, binding.span, E0253, + resolve_err!(self, binding.span, E0410, "variable `{}` from pattern {}{} is \ not bound in pattern {}1", key, @@ -2431,16 +2369,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { path.segments.len() > 0 && maybe_qself.is_none() && path.segments[0].identifier.name == self_type_name; - let msg = if is_invalid_self_type_name { - "use of `Self` outside of an impl or trait".to_string() + if is_invalid_self_type_name { + resolve_err!(self, ty.span, E0411, + "{}", + "use of `Self` outside of an impl or trait"); } else { - format!("use of undeclared {} `{}`", - kind, path_names_to_string(path, 0)) - }; - - //self.resolve_error(ty.span, &msg[..]); - resolve_err!(self, ty.span, E0253, - "{}", msg); + resolve_err!(self, ty.span, E0412, + "use of undeclared {} `{}`", + kind, + path_names_to_string(path, 0)); + } } } } @@ -2491,13 +2429,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); } FoundStructOrEnumVariant(..) => { - /*self.resolve_error( - pattern.span, - &format!("declaration of `{}` shadows an enum \ - variant or unit-like struct in \ - scope", - renamed));*/ - resolve_err!(self, pattern.span, E0253, + resolve_err!(self, pattern.span, E0413, "declaration of `{}` shadows an enum \ variant or unit-like struct in \ scope", @@ -2519,10 +2451,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); } FoundConst(..) => { - /*self.resolve_error(pattern.span, - "only irrefutable patterns \ - allowed here");*/ - resolve_err!(self, pattern.span, E0253, + resolve_err!(self, pattern.span, E0414, "{}", "only irrefutable patterns \ allowed here"); @@ -2557,16 +2486,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { bindings_list.contains_key(&renamed) { // Forbid duplicate bindings in the same // parameter list. - /*self.resolve_error(pattern.span, - &format!("identifier `{}` \ - is bound more \ - than once in \ - this parameter \ - list", - token::get_ident( - ident)) - )*/ - resolve_err!(self, pattern.span, E0253, + resolve_err!(self, pattern.span, E0415, "identifier `{}` \ is bound more \ than once in \ @@ -2577,12 +2497,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Some(&pat_id) { // Then this is a duplicate variable in the // same disjunction, which is an error. - /*self.resolve_error(pattern.span, - &format!("identifier `{}` is bound \ - more than once in the same \ - pattern", - token::get_ident(ident)));*/ - resolve_err!(self, pattern.span, E0253, + resolve_err!(self, pattern.span, E0416, "identifier `{}` is bound \ more than once in the same \ pattern", @@ -2617,11 +2532,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.record_def(pattern.id, path_res); } DefStatic(..) => { - /*self.resolve_error(path.span, - "static variables cannot be \ - referenced in a pattern, \ - use a `const` instead");*/ - resolve_err!(self, path.span, E0253, "{}", + resolve_err!(self, path.span, E0417, "{}", "static variables cannot be \ referenced in a pattern, \ use a `const` instead"); @@ -2632,12 +2543,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // partially resolved, that's OK, because it may // be a `T::CONST` that typeck will resolve. if path_res.depth == 0 { - /*self.resolve_error( - path.span, - &format!("`{}` is not an enum variant, struct or const", - token::get_ident( - path.segments.last().unwrap().identifier)));*/ - resolve_err!(self, path.span, E0253, + resolve_err!(self, path.span, E0418, "`{}` is not an enum variant, struct or const", token::get_ident( path.segments.last().unwrap().identifier)); @@ -2651,10 +2557,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } } else { - /*self.resolve_error(path.span, - &format!("unresolved enum variant, struct or const `{}`", - token::get_ident(path.segments.last().unwrap().identifier)));*/ - resolve_err!(self, path.span, E0253, + resolve_err!(self, path.span, E0419, "unresolved enum variant, struct or const `{}`", token::get_ident(path.segments.last().unwrap().identifier)); } @@ -2688,21 +2591,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.record_def(pattern.id, path_res); } _ => { - /*self.resolve_error(path.span, - &format!("`{}` is not an associated const", - token::get_ident( - path.segments.last().unwrap().identifier)));*/ - resolve_err!(self, path.span, E0253, + resolve_err!(self, path.span, E0420, "`{}` is not an associated const", token::get_ident( path.segments.last().unwrap().identifier)); } } } else { - /*self.resolve_error(path.span, - &format!("unresolved associated const `{}`", - token::get_ident(path.segments.last().unwrap().identifier)));*/ - resolve_err!(self, path.span, E0253, + resolve_err!(self, path.span, E0421, "unresolved associated const `{}`", token::get_ident(path.segments.last().unwrap().identifier)); } @@ -2717,10 +2613,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { result => { debug!("(resolving pattern) didn't find struct \ def: {:?}", result); - /*let msg = format!("`{}` does not name a structure", - path_names_to_string(path, 0)); - self.resolve_error(path.span, &msg[..]);*/ - resolve_err!(self, path.span, E0253, + resolve_err!(self, path.span, E0422, "`{}` does not name a structure", path_names_to_string(path, 0)); } @@ -2768,11 +2661,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { return FoundConst(def, LastMod(AllPublic)); } DefStatic(..) => { - /*self.resolve_error(span, - "static variables cannot be \ - referenced in a pattern, \ - use a `const` instead");*/ - resolve_err!(self, span, E0253, + resolve_err!(self, span, E0417, "{}", "static variables cannot be \ referenced in a pattern, \ @@ -2793,9 +2682,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Failed(err) => { match err { Some((span, msg)) => { - /*self.resolve_error(span, &format!("failed to resolve: {}", - msg));*/ - resolve_err!(self, span, E0253, + resolve_err!(self, span, E0397, "failed to resolve: {}", msg); } @@ -3026,9 +2913,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - /*self.resolve_error(span, &format!("failed to resolve. {}", - msg));*/ - resolve_err!(self, span, E0253, + resolve_err!(self, span, E0397, "failed to resolve: {}", msg); return None; @@ -3091,7 +2976,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /*self.resolve_error(span, &format!("failed to resolve. {}", msg));*/ - resolve_err!(self, span, E0253, + resolve_err!(self, span, E0397, "failed to resolve: {}", msg); return None; @@ -3189,8 +3074,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { failed to resolve {}", name); if let Some((span, msg)) = err { - //self.resolve_error(span, &format!("failed to resolve. {}", msg)) - resolve_err!(self, span, E0253, + resolve_err!(self, span, E0397, "failed to resolve: {}", msg) } @@ -3400,12 +3284,7 @@ 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); - /*self.resolve_error(expr.span, - &format!("`{}` is a struct variant name, but \ - this expression \ - uses it like a function name", - path_name));*/ - resolve_err!(self, expr.span, E0253, + resolve_err!(self, expr.span, E0423, "`{}` is a struct variant name, but \ this expression \ uses it like a function name", @@ -3446,12 +3325,7 @@ 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) => { - /*self.resolve_error(expr.span, - &format!("`{}` is a structure name, but \ - this expression \ - uses it like a function name", - path_name));*/ - resolve_err!(self, expr.span, E0253, + resolve_err!(self, expr.span, E0423, "{}` is a structure name, but \ this expression \ uses it like a function name", @@ -3482,12 +3356,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if method_scope && &token::get_name(special_names::self_)[..] == path_name { - /*self.resolve_error( - expr.span, - "`self` is not available \ - in a static method. Maybe a \ - `self` argument is missing?");*/ - resolve_err!(self, expr.span, E0253, + resolve_err!(self, expr.span, E0424, "{}", "`self` is not available \ in a static method. Maybe a \ @@ -3515,11 +3384,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { msg = format!(". Did you mean {}?", msg) } - /*self.resolve_error( - expr.span, - &format!("unresolved name `{}`{}", - path_name, msg));*/ - resolve_err!(self, expr.span, E0253, + resolve_err!(self, expr.span, E0425, "unresolved name `{}`{}", path_name, msg); @@ -3539,10 +3404,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Some(definition) => self.record_def(expr.id, definition), None => { debug!("(resolving expression) didn't find struct def",); - /*let msg = format!("`{}` does not name a structure", - path_names_to_string(path, 0)); - self.resolve_error(path.span, &msg[..]);*/ - resolve_err!(self, path.span, E0253, + resolve_err!(self, path.span, E0422, "`{}` does not name a structure", path_names_to_string(path, 0)); } @@ -3569,11 +3431,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let renamed = mtwt::resolve(label); match self.search_label(renamed) { None => { - /*self.resolve_error( - expr.span, - &format!("use of undeclared label `{}`", - token::get_ident(label)))*/ - resolve_err!(self, expr.span, E0253, + resolve_err!(self, expr.span, E0426, "use of undeclared label `{}`", token::get_ident(label)) } @@ -3721,11 +3579,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { match pat_binding_mode { BindByValue(_) => {} BindByRef(..) => { - /*self.resolve_error(pat.span, - &format!("cannot use `ref` binding mode \ - with {}", - descr));*/ - resolve_err!(self, pat.span, E0253, + resolve_err!(self, pat.span, E0427, "cannot use `ref` binding mode with {}", descr); } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index a08d022ffcd..cbaa96c4334 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -272,12 +272,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { Some((span, msg)) => (span, format!(". {}", msg)), None => (import_directive.span, String::new()) }; - let msg = format!("unresolved import `{}`{}", - import_path_to_string( + resolve_err!(self.resolver, span, E0398, + "unresolved import `{}`{}", + import_path_to_string( &import_directive.module_path, import_directive.subclass), - help); - self.resolver.resolve_error(span, &msg[..]); + help); } ResolveResult::Indeterminate => break, // Bail out. We'll come around next time. ResolveResult::Success(()) => () // Good. Continue. -- cgit 1.4.1-3-g733a5 From f1b231dd714cb0edb0a632a5bd804b53423b3d4c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Jul 2015 00:40:54 +0200 Subject: Remove unused method --- src/librustc_resolve/lib.rs | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c0e42f269ee..b0cff1406c5 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -26,16 +26,6 @@ #![feature(slice_extras)] #![feature(staged_api)] -#![macro_use] - -macro_rules! resolve_err { - ($this:expr, $span:expr, $code:ident, $($rest:tt)*) => { - if $this.emit_errors { - span_err!($this.session, $span, $code, $($rest)*); - } - } -} - #[macro_use] extern crate log; #[macro_use] extern crate syntax; #[macro_use] #[no_link] extern crate rustc_bitflags; @@ -109,11 +99,18 @@ use std::usize; use resolve_imports::{Target, ImportDirective, ImportResolution}; use resolve_imports::Shadowable; - // NB: This module needs to be declared first so diagnostics are // registered before they are used. pub mod diagnostics; +macro_rules! resolve_err { + ($this:expr, $span:expr, $code:ident, $($rest:tt)*) => { + if $this.emit_errors { + span_err!($this.session, $span, $code, $($rest)*); + } + } +} + mod check_unused; mod record_exports; mod build_reduced_graph; @@ -2253,10 +2250,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding) in &map_i { if !map_0.contains_key(&key) { resolve_err!(self, binding.span, E0410, - "variable `{}` from pattern {}{} is \ - not bound in pattern {}1", + "variable `{}` from pattern #{} is \ + not bound in pattern #1", key, - "#", i + 1, "#"); + i + 1); } } } @@ -2371,7 +2368,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { path.segments[0].identifier.name == self_type_name; if is_invalid_self_type_name { resolve_err!(self, ty.span, E0411, - "{}", "use of `Self` outside of an impl or trait"); } else { resolve_err!(self, ty.span, E0412, @@ -3093,12 +3089,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { rs } - fn resolve_error(&self, span: Span, s: &str) { - if self.emit_errors { - self.session.span_err(span, s); - } - } - fn find_fallback_in_self_type(&mut self, name: Name) -> FallbackSuggestion { fn extract_path_and_node_id(t: &Ty, allow: FallbackChecks) -> Option<(Path, NodeId, FallbackChecks)> { -- cgit 1.4.1-3-g733a5 From 48ee57e656ea955fe634df7c7e9f37c27c65580a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Jul 2015 00:57:16 +0200 Subject: Update error codes --- src/librustc_resolve/diagnostics.rs | 10 +++++----- src/librustc_resolve/lib.rs | 18 +++++++++--------- src/librustc_resolve/resolve_imports.rs | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 34cd6ef002e..939991da203 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -210,10 +210,6 @@ register_diagnostics! { E0258, E0364, // 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 @@ -248,6 +244,10 @@ register_diagnostics! { 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 + E0431, // `self` import can only appear in an import list with a non-empty // prefix + E0432, // unresolved import + E0433, // failed to resolve + E0434, // can't capture dynamic environment in a fn item + E0435 // attempt to use a non-constant value in a constant } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b0cff1406c5..58c91aa81c7 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1310,7 +1310,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { PathSearch, true) { Failed(Some((span, msg))) => { - resolve_err!(self, span, E0397, "failed to resolve. {}", msg); + resolve_err!(self, span, E0433, "failed to resolve. {}", msg); }, Failed(None) => (), // Continue up the search chain. Indeterminate => { @@ -1568,10 +1568,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .span_to_snippet((*imports)[index].span) .unwrap(); if sn.contains("::") { - resolve_err!(self, (*imports)[index].span, E0398, + resolve_err!(self, (*imports)[index].span, E0432, "{}", "unresolved import"); } else { - resolve_err!(self, (*imports)[index].span, E0398, + resolve_err!(self, (*imports)[index].span, E0432, "unresolved import (maybe you meant `{}::*`?)", sn); } } @@ -1698,14 +1698,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we // report an error. - resolve_err!(self, span, E0399, "{}", + resolve_err!(self, span, E0434, "{}", "can't capture dynamic environment in a fn item; \ use the || { ... } closure form instead"); return None; } ConstantItemRibKind => { // Still doesn't deal with upvars - resolve_err!(self, span, E0400, "{}", + resolve_err!(self, span, E0435, "{}", "attempt to use a non-constant \ value in a constant"); return None; @@ -2678,7 +2678,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Failed(err) => { match err { Some((span, msg)) => { - resolve_err!(self, span, E0397, + resolve_err!(self, span, E0433, "failed to resolve: {}", msg); } @@ -2909,7 +2909,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - resolve_err!(self, span, E0397, + resolve_err!(self, span, E0433, "failed to resolve: {}", msg); return None; @@ -2972,7 +2972,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /*self.resolve_error(span, &format!("failed to resolve. {}", msg));*/ - resolve_err!(self, span, E0397, + resolve_err!(self, span, E0433, "failed to resolve: {}", msg); return None; @@ -3070,7 +3070,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { failed to resolve {}", name); if let Some((span, msg)) = err { - resolve_err!(self, span, E0397, + resolve_err!(self, span, E0433, "failed to resolve: {}", msg) } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index cbaa96c4334..162dc4bd381 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -272,7 +272,7 @@ 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, E0398, + resolve_err!(self.resolver, span, E0432, "unresolved import `{}`{}", import_path_to_string( &import_directive.module_path, -- cgit 1.4.1-3-g733a5 From cbf0b1b399e884cff01393e817738da48bab64fd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Jul 2015 02:05:02 +0200 Subject: Remove warnings by centralizing error codes usage --- src/librustc_resolve/lib.rs | 92 ++++++++++++++++++++------------- src/librustc_resolve/resolve_imports.rs | 13 ++--- 2 files changed, 63 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 58c91aa81c7..82e5df77281 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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))); } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 162dc4bd381..c5f451e5649 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -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. -- cgit 1.4.1-3-g733a5 From f52a87c44e84a0089819e77ad85ea24b88d547e7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Jul 2015 19:32:45 +0200 Subject: Centralize error spaning and add an enum to make this treatment easier --- src/librustc_resolve/lib.rs | 133 ++++++++++++++++++-------------- src/librustc_resolve/resolve_imports.rs | 6 +- 2 files changed, 80 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 82e5df77281..1fa8e63f57e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -116,24 +116,37 @@ 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); +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)] @@ -1330,7 +1343,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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 => { @@ -1588,12 +1604,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .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) + ); } } @@ -2549,10 +2566,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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, @@ -2630,7 +2647,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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))); } @@ -2678,10 +2695,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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; } _ => { @@ -2698,9 +2715,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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 => () } @@ -2929,9 +2947,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - 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"), @@ -2990,11 +3009,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - /*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; } @@ -3090,9 +3108,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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; @@ -3294,11 +3313,12 @@ 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_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 */ }}`?", @@ -3335,11 +3355,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_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 */ }}`?", @@ -3414,7 +3434,8 @@ 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_422(self, path.span, + + resolve_error(&ResolutionError::DoesNotNameAStruct(self, path.span), &*format!("`{}` does not name a structure", path_names_to_string(path, 0))); } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index c5f451e5649..196de63bfd9 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -272,13 +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_432(self.resolver, span, - &*format!("unresolved import `{}`{}", + ::resolve_error(&::ResolutionError::UnresolvedImport(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. -- cgit 1.4.1-3-g733a5 From c5f7c19cf274f510b48d6835f5677ae22e978d6d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 14 Jul 2015 15:37:52 +0200 Subject: End of error code spanning centralization --- src/librustc_resolve/build_reduced_graph.rs | 36 +- src/librustc_resolve/lib.rs | 572 ++++++++++++++++++++-------- src/librustc_resolve/resolve_imports.rs | 11 +- 3 files changed, 430 insertions(+), 189 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 00745136eef..782e0a3660b 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -208,10 +208,13 @@ 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(); - resolve_err!(self, sp, E0428, - "duplicate definition of {} `{}`", - namespace_error_to_string(duplicate_type), - token::get_name(name)); + ::resolve_error( + &::ResolutionError::DuplicateDefinition( + self, + sp, + namespace_error_to_string(duplicate_type), + &*token::get_name(name)) + ); { let r = child.span_for_namespace(ns); if let Some(sp) = r { @@ -304,9 +307,10 @@ 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" { - resolve_err!(self, view_path.span, E0429, - "{}", - "`self` imports are only allowed within a { } list"); + ::resolve_error(&::ResolutionError::SelfImportsOnlyAllowedWithin( + self, + view_path.span) + ); } let subclass = SingleImport(binding.name, @@ -326,9 +330,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { _ => None }).collect::>(); if mod_spans.len() > 1 { - resolve_err!(self, mod_spans[0], E0430, - "{}", - "`self` import can only appear once in the list"); + ::resolve_error( + &::ResolutionError::SelfImportCanOnlyAppearOnceInTheList( + self, + mod_spans[0]) + ); for other_span in mod_spans.iter().skip(1) { self.session.span_note(*other_span, "another `self` import appears here"); @@ -343,10 +349,12 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let name = match module_path.last() { Some(name) => *name, None => { - resolve_err!(self, source_item.span, E0431, - "{}", - "`self` import can only appear in an import list \ - with a non-empty prefix"); + ::resolve_error( + &::ResolutionError:: + SelfImportOnlyInImportListWithNonEmptyPrefix( + self, + source_item.span) + ); continue; } }; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 1fa8e63f57e..850a5d1db26 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -117,34 +117,266 @@ mod build_reduced_graph; mod resolve_imports; pub enum ResolutionError<'b, 'a:'b, 'tcx:'a> { - /// error: static variables cannot be referenced in a pattern + /// error E0401: can't use type parameters from outer function + TypeParametersFromOuterFunction(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0402: cannot use an outer type parameter in this context + OuterTypeParameterContext(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0403: the name is already used for a type parameter in this type parameter list + NameAlreadyUsedInTypeParameterList(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, + syntax::ast::Name), + /// error E0404: is not a trait + IsNotATrait(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0405: use of undeclared trait name + UndeclaredTraitName(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0406: undeclared associated type + UndeclaredAssociatedType(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0407: method is not a member of trait + MethodNotMemberOfTrait(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, syntax::ast::Name, + &'b str), + /// error E0408: variable `{}` from pattern #1 is not bound in pattern + VariableNotBoundInPattern(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, syntax::ast::Name, + usize), + /// error E0409: variable is bound with different mode in pattern #{} than in pattern #1 + VariableBoundWithDifferentMode(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, + syntax::ast::Name, usize), + /// error E0410: variable from pattern is not bound in pattern #1 + VariableNotBoundInParentPattern(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, + syntax::ast::Name, usize), + /// error E0411: use of `Self` outside of an impl or trait + SelfUsedOutsideImplOrTrait(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0412: use of undeclared + UseOfUndeclared(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str, &'b str), + /// error E0413: declaration shadows an enum variant or unit-like struct in scope + DeclarationShadowsEnumVariantOrUnitLikeStruct(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, + syntax::ast::Name), + /// error E0414: only irrefutable patterns allowed here + OnlyIrrefutablePatternsAllowedHere(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0415: identifier is bound more than once in this parameter list + IdentifierBoundMoreThanOnceInParameterList(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, + &'b str), + /// error E0416: identifier is bound more than once in the same pattern + IdentifierBoundMoreThanOnceInSamePattern(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, + &'b str), + /// error E0417: 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), + /// error E0418: is not an enum variant, struct or const + NotAnEnumVariantStructOrConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0419: unresolved enum variant, struct or const + UnresolvedEnumVariantStructOrConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0420: is not an associated const + NotAnAssociatedConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0421: unresolved associated const + UnresolvedAssociatedConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0422: does not name a struct + DoesNotNameAStruct(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0423: is a struct variant name, but this expression uses it like a function name + StructVariantUsedAsFunction(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0424: `self` is not available in a static method + SelfNotAvailableInStaticMethod(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0425: unresolved name + UnresolvedName(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str, &'b str), + /// error E0426: use of undeclared label + UndeclaredLabel(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0427: cannot use `ref` binding mode with ... + CannotUseRefBindingModeWith(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0428: duplicate definition + DuplicateDefinition(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str, &'b str), + /// error E0429: `self` imports are only allowed within a { } list + SelfImportsOnlyAllowedWithin(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0430: `self` import can only appear once in the list + SelfImportCanOnlyAppearOnceInTheList(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0431: `self` import can only appear in an import list with a non-empty prefix + SelfImportOnlyInImportListWithNonEmptyPrefix(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0432: unresolved import + UnresolvedImport(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, + Option<(&'b str, Option<&'b str>)>), + /// error E0433: failed to resolve + FailedToResolve(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + /// error E0434: can't capture dynamic environment in a fn item + CannotCaptureDynamicEnvironmentInFnItem(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + /// error E0435: attempt to use a non-constant value in a constant + AttemptToUseNonConstantValueInConstant(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), } -fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolution_error: &ResolutionError<'b, 'a, 'tcx>, formatted: &str) { +fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolution_error: &ResolutionError<'b, 'a, 'tcx>) { match resolution_error { + &ResolutionError::TypeParametersFromOuterFunction(resolver, span) => { + resolve_err!(resolver, span, E0401, "can't use type parameters from \ + outer function; try using a local \ + type parameter instead"); + }, + &ResolutionError::OuterTypeParameterContext(resolver, span) => { + resolve_err!(resolver, span, E0402, + "cannot use an outer type parameter in this context"); + }, + &ResolutionError::NameAlreadyUsedInTypeParameterList(resolver, span, name) => { + resolve_err!(resolver, span, E0403, + "the name `{}` is already used for a type \ + parameter in this type parameter list", name); + }, + &ResolutionError::IsNotATrait(resolver, span, name) => { + resolve_err!(resolver, span, E0404, + "`{}` is not a trait", + name); + }, + &ResolutionError::UndeclaredTraitName(resolver, span, name) => { + resolve_err!(resolver, span, E0405, + "use of undeclared trait name `{}`", + name); + }, + &ResolutionError::UndeclaredAssociatedType(resolver, span) => { + resolve_err!(resolver, span, E0406, "undeclared associated type"); + }, + &ResolutionError::MethodNotMemberOfTrait(resolver, span, method, trait_) => { + resolve_err!(resolver, span, E0407, + "method `{}` is not a member of trait `{}`", + method, + trait_); + }, + &ResolutionError::VariableNotBoundInPattern(resolver, span, variable_name, + pattern_number) => { + resolve_err!(resolver, span, E0408, + "variable `{}` from pattern #1 is not bound in pattern #{}", + variable_name, + pattern_number); + }, + &ResolutionError::VariableBoundWithDifferentMode(resolver, span, variable_name, + pattern_number) => { + resolve_err!(resolver, span, E0409, + "variable `{}` is bound with different \ + mode in pattern #{} than in pattern #1", + variable_name, + pattern_number); + }, + &ResolutionError::VariableNotBoundInParentPattern(resolver, span, variable_name, + pattern_number) => { + resolve_err!(resolver, span, E0410, + "variable `{}` from pattern #{} is not bound in pattern #1", + variable_name, + pattern_number); + }, + &ResolutionError::SelfUsedOutsideImplOrTrait(resolver, span) => { + resolve_err!(resolver, span, E0411, "use of `Self` outside of an impl or trait"); + }, + &ResolutionError::UseOfUndeclared(resolver, span, kind, name) => { + resolve_err!(resolver, span, E0412, + "use of undeclared {} `{}`", + kind, + name); + }, + &ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(resolver, span, name) => { + resolve_err!(resolver, span, E0413, + "declaration of `{}` shadows an enum variant or unit-like struct in \ + scope", + name); + }, + &ResolutionError::OnlyIrrefutablePatternsAllowedHere(resolver, span) => { + resolve_err!(resolver, span, E0414, "only irrefutable patterns allowed here"); + }, + &ResolutionError::IdentifierBoundMoreThanOnceInParameterList(resolver, span, + identifier) => { + resolve_err!(resolver, span, E0415, + "identifier `{}` is bound more than once in this parameter list", + identifier); + }, + &ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(resolver, span, identifier) => { + resolve_err!(resolver, span, E0416, + "identifier `{}` is bound more than once in the same pattern", + identifier); + }, &ResolutionError::StaticVariableReference(resolver, span) => { - resolve_err!(resolver, span, E0417, "{}", formatted); + resolve_err!(resolver, span, E0417, "static variables cannot be \ + referenced in a pattern, \ + use a `const` instead"); + }, + &ResolutionError::NotAnEnumVariantStructOrConst(resolver, span, name) => { + resolve_err!(resolver, span, E0418, + "`{}` is not an enum variant, struct or const", + name); + }, + &ResolutionError::UnresolvedEnumVariantStructOrConst(resolver, span, name) => { + resolve_err!(resolver, span, E0419, + "unresolved enum variant, struct or const `{}`", + name); + }, + &ResolutionError::NotAnAssociatedConst(resolver, span, name) => { + resolve_err!(resolver, span, E0420, + "`{}` is not an associated const", + name); }, - &ResolutionError::DoesNotNameAStruct(resolver, span) => { - resolve_err!(resolver, span, E0422, "{}", formatted); + &ResolutionError::UnresolvedAssociatedConst(resolver, span, name) => { + resolve_err!(resolver, span, E0421, + "unresolved associated const `{}`", + name); }, - &ResolutionError::StructVariantUsedAsFunction(resolver, span) => { - resolve_err!(resolver, span, E0423, "{}", formatted); + &ResolutionError::DoesNotNameAStruct(resolver, span, name) => { + resolve_err!(resolver, span, E0422, "`{}` does not name a structure", name); }, - &ResolutionError::UnresolvedImport(resolver, span) => { - resolve_err!(resolver, span, E0432, "{}", formatted); + &ResolutionError::StructVariantUsedAsFunction(resolver, span, path_name) => { + resolve_err!(resolver, span, E0423, + "`{}` is a struct variant name, but \ + this expression \ + uses it like a function name", + path_name); }, - &ResolutionError::FailedToResolve(resolver, span) => { - resolve_err!(resolver, span, E0433, "{}", formatted); + &ResolutionError::SelfNotAvailableInStaticMethod(resolver, span) => { + resolve_err!(resolver, span, E0424, "`self` is not available in a static method. \ + Maybe a `self` argument is missing?"); + }, + &ResolutionError::UnresolvedName(resolver, span, path, name) => { + resolve_err!(resolver, span, E0425, + "unresolved name `{}`{}", + path, + name); + }, + &ResolutionError::UndeclaredLabel(resolver, span, name) => { + resolve_err!(resolver, span, E0426, + "use of undeclared label `{}`", + name); + }, + &ResolutionError::CannotUseRefBindingModeWith(resolver, span, descr) => { + resolve_err!(resolver, span, E0427, + "cannot use `ref` binding mode with {}", + descr); + }, + &ResolutionError::DuplicateDefinition(resolver, span, namespace, name) => { + resolve_err!(resolver, span, E0428, + "duplicate definition of {} `{}`", + namespace, + name); + }, + &ResolutionError::SelfImportsOnlyAllowedWithin(resolver, span) => { + resolve_err!(resolver, span, E0429, "{}", + "`self` imports are only allowed within a { } list"); + }, + &ResolutionError::SelfImportCanOnlyAppearOnceInTheList(resolver, span) => { + resolve_err!(resolver, span, E0430, + "`self` import can only appear once in the list"); + }, + &ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix(resolver, span) => { + resolve_err!(resolver, span, E0431, + "`self` import can only appear in an import list with a \ + non-empty prefix"); + } + &ResolutionError::UnresolvedImport(resolver, span, name) => { + let msg = match name { + Some((n, Some(p))) => format!("unresolved import `{}`{}", n, p), + Some((n, None)) => format!("unresolved import (maybe you meant `{}::*`?)", n), + None => "unresolved import".to_owned() + }; + resolve_err!(resolver, span, E0432, "{}", msg); + }, + &ResolutionError::FailedToResolve(resolver, span, msg) => { + resolve_err!(resolver, span, E0433, "failed to resolve. {}", msg); + }, + &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem(resolver, span) => { + resolve_err!(resolver, span, E0434, "{}", + "can't capture dynamic environment in a fn item; \ + use the || { ... } closure form instead"); + }, + &ResolutionError::AttemptToUseNonConstantValueInConstant(resolver, span) =>{ + resolve_err!(resolver, span, E0435, + "attempt to use a non-constant value in a constant"); }, } } @@ -1343,10 +1575,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { PathSearch, true) { Failed(Some((span, msg))) => { - resolve_error(&ResolutionError::FailedToResolve(self, span), - &*format!("failed to resolve. {}", - msg) - ); + resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); }, Failed(None) => (), // Continue up the search chain. Indeterminate => { @@ -1604,13 +1833,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .span_to_snippet((*imports)[index].span) .unwrap(); if sn.contains("::") { - resolve_error(&ResolutionError::UnresolvedImport(self, (*imports)[index].span), - "unresolved import"); + resolve_error(&ResolutionError::UnresolvedImport(self, + (*imports)[index].span, + None)); } else { - resolve_error(&ResolutionError::UnresolvedImport(self, (*imports)[index].span), - &*format!("unresolved import (maybe you meant `{}::*`?)", - sn) - ); + resolve_error(&ResolutionError::UnresolvedImport(self, + (*imports)[index].span, + Some((&*sn, None)))); } } @@ -1736,16 +1965,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we // report an error. - resolve_err!(self, span, E0434, "{}", - "can't capture dynamic environment in a fn item; \ - use the || { ... } closure form instead"); + resolve_error( + &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem( + self, + span) + ); return None; } ConstantItemRibKind => { // Still doesn't deal with upvars - resolve_err!(self, span, E0435, "{}", - "attempt to use a non-constant \ - value in a constant"); + resolve_error( + &ResolutionError::AttemptToUseNonConstantValueInConstant( + self, + span) + ); return None; } } @@ -1761,17 +1994,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // This was an attempt to use a type parameter outside // its scope. - resolve_err!(self, span, E0401, "{}", - "can't use type parameters from \ - outer function; try using a local \ - type parameter instead"); + resolve_error(&ResolutionError::TypeParametersFromOuterFunction(self, + span)); return None; } ConstantItemRibKind => { // see #9186 - resolve_err!(self, span, E0402, "{}", - "cannot use an outer type \ - parameter in this context"); + resolve_error(&ResolutionError::OuterTypeParameterContext(self, span)); return None; } } @@ -1969,12 +2198,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("with_type_parameter_rib: {}", type_parameter.id); if seen_bindings.contains(&name) { - resolve_err!(self, type_parameter.span, E0403, - "the name `{}` is already \ - used for a type \ - parameter in this type \ - parameter list", - name) + resolve_error(&ResolutionError::NameAlreadyUsedInTypeParameterList( + self, + type_parameter.span, + name)); } seen_bindings.insert(name); @@ -2061,9 +2288,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("(resolving trait) found trait def: {:?}", path_res); Ok(path_res) } else { - resolve_err!(self, trait_path.span, E0404, - "`{}` is not a trait", - path_names_to_string(trait_path, path_depth)); + resolve_error(&ResolutionError::IsNotATrait(self, trait_path.span, + &*path_names_to_string(trait_path, + path_depth)) + ); // If it's a typedef, give a note if let DefTy(..) = path_res.base_def { @@ -2073,9 +2301,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Err(()) } } else { - resolve_err!(self, trait_path.span, E0405, - "use of undeclared trait name `{}`", - path_names_to_string(trait_path, path_depth)); + resolve_error(&ResolutionError::UndeclaredTraitName(self, + trait_path.span, + &*path_names_to_string(trait_path, + path_depth))); Err(()) } } @@ -2093,8 +2322,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(PathResolution { base_def: DefTyParam(..), .. }) = path_res { self.record_def(eq_pred.id, path_res.unwrap()); } else { - resolve_err!(self, eq_pred.span, E0406, "{}", - "undeclared associated type"); + resolve_error(&ResolutionError::UndeclaredAssociatedType(self, + eq_pred.span)); } } } @@ -2219,8 +2448,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some((did, ref trait_ref)) = self.current_trait_ref { if !self.trait_item_map.contains_key(&(name, did)) { let path_str = path_names_to_string(&trait_ref.path, 0); - resolve_err!(self, span, E0407, "method `{}` is not a member of trait `{}`", - name, path_str); + resolve_error(&ResolutionError::MethodNotMemberOfTrait(self, + span, + name, + &*path_str)); } } } @@ -2267,19 +2498,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding_0) in &map_0 { match map_i.get(&key) { None => { - resolve_err!(self, p.span, E0408, - "variable `{}` from pattern #1 is \ - not bound in pattern #{}", - key, - i + 1); + resolve_error(&ResolutionError::VariableNotBoundInPattern(self, + p.span, + key, + i + 1)); } Some(binding_i) => { if binding_0.binding_mode != binding_i.binding_mode { - resolve_err!(self, binding_i.span, E0409, - "variable `{}` is bound with different \ - mode in pattern #{} than in pattern #1", - key, - i + 1); + resolve_error(&ResolutionError::VariableBoundWithDifferentMode( + self, + binding_i.span, + key, + i + 1) + ); } } } @@ -2287,11 +2518,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding) in &map_i { if !map_0.contains_key(&key) { - resolve_err!(self, binding.span, E0410, - "variable `{}` from pattern #{} is \ - not bound in pattern #1", - key, - i + 1); + resolve_error(&ResolutionError::VariableNotBoundInParentPattern(self, + binding.span, + key, + i + 1)); } } } @@ -2405,13 +2635,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { maybe_qself.is_none() && path.segments[0].identifier.name == self_type_name; if is_invalid_self_type_name { - resolve_err!(self, ty.span, E0411, - "use of `Self` outside of an impl or trait"); + resolve_error(&ResolutionError::SelfUsedOutsideImplOrTrait(self, + ty.span)); } else { - resolve_err!(self, ty.span, E0412, - "use of undeclared {} `{}`", - kind, - path_names_to_string(path, 0)); + resolve_error(&ResolutionError::UseOfUndeclared( + self, + ty.span, + kind, + &*path_names_to_string(path, + 0)) + ); } } } @@ -2463,11 +2696,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); } FoundStructOrEnumVariant(..) => { - resolve_err!(self, pattern.span, E0413, - "declaration of `{}` shadows an enum \ - variant or unit-like struct in \ - scope", - renamed); + resolve_error( + &ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct( + self, + pattern.span, + renamed) + ); } FoundConst(def, lp) if mode == RefutableMode => { debug!("(resolving pattern) resolving `{}` to \ @@ -2485,10 +2719,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); } FoundConst(..) => { - resolve_err!(self, pattern.span, E0414, - "{}", - "only irrefutable patterns \ - allowed here"); + resolve_error( + &ResolutionError::OnlyIrrefutablePatternsAllowedHere( + self, + pattern.span) + ); } BareIdentifierPatternUnresolved => { debug!("(resolving pattern) binding `{}`", @@ -2520,22 +2755,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { bindings_list.contains_key(&renamed) { // Forbid duplicate bindings in the same // parameter list. - resolve_err!(self, pattern.span, E0415, - "identifier `{}` \ - is bound more \ - than once in \ - this parameter \ - list", - token::get_ident(ident)); + resolve_error( + &ResolutionError::IdentifierBoundMoreThanOnceInParameterList( + self, + pattern.span, + &*token::get_ident(ident)) + ); } else if bindings_list.get(&renamed) == Some(&pat_id) { // Then this is a duplicate variable in the // same disjunction, which is an error. - resolve_err!(self, pattern.span, E0416, - "identifier `{}` is bound \ - more than once in the same \ - pattern", - token::get_ident(ident)); + resolve_error( + &ResolutionError::IdentifierBoundMoreThanOnceInSamePattern( + self, + pattern.span, + &*token::get_ident(ident)) + ); } // Else, not bound in the same pattern: do // nothing. @@ -2566,10 +2801,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.record_def(pattern.id, path_res); } DefStatic(..) => { - resolve_error(&ResolutionError::StaticVariableReference(&self, path.span), - "static variables cannot be \ - referenced in a pattern, \ - use a `const` instead"); + resolve_error(&ResolutionError::StaticVariableReference(&self, + path.span)); } _ => { // If anything ends up here entirely resolved, @@ -2577,10 +2810,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // partially resolved, that's OK, because it may // be a `T::CONST` that typeck will resolve. if path_res.depth == 0 { - resolve_err!(self, path.span, E0418, - "`{}` is not an enum variant, struct or const", - token::get_ident( - path.segments.last().unwrap().identifier)); + resolve_error( + &ResolutionError::NotAnEnumVariantStructOrConst( + self, + path.span, + &*token::get_ident( + path.segments.last().unwrap().identifier) + ) + ); } else { let const_name = path.segments.last().unwrap() .identifier.name; @@ -2591,9 +2828,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } } else { - resolve_err!(self, path.span, E0419, - "unresolved enum variant, struct or const `{}`", - token::get_ident(path.segments.last().unwrap().identifier)); + resolve_error( + &ResolutionError::UnresolvedEnumVariantStructOrConst( + self, + path.span, + &*token::get_ident(path.segments.last().unwrap().identifier)) + ); } visit::walk_path(self, path); } @@ -2625,16 +2865,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.record_def(pattern.id, path_res); } _ => { - resolve_err!(self, path.span, E0420, - "`{}` is not an associated const", - token::get_ident( - path.segments.last().unwrap().identifier)); + resolve_error( + &ResolutionError::NotAnAssociatedConst( + self, + path.span, + &*token::get_ident( + path.segments.last().unwrap().identifier) + ) + ); } } } else { - resolve_err!(self, path.span, E0421, - "unresolved associated const `{}`", - token::get_ident(path.segments.last().unwrap().identifier)); + resolve_error( + &ResolutionError::UnresolvedAssociatedConst( + self, + path.span, + &*token::get_ident(path.segments.last().unwrap().identifier) + ) + ); } visit::walk_pat(self, pattern); } @@ -2647,9 +2895,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { result => { debug!("(resolving pattern) didn't find struct \ def: {:?}", result); - resolve_error(&ResolutionError::DoesNotNameAStruct(self, path.span), - &*format!("`{}` does not name a structure", - path_names_to_string(path, 0))); + resolve_error(&ResolutionError::DoesNotNameAStruct( + self, + path.span, + &*path_names_to_string(path, 0)) + ); } } visit::walk_path(self, path); @@ -2695,10 +2945,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { return FoundConst(def, LastMod(AllPublic)); } DefStatic(..) => { - resolve_error(&ResolutionError::StaticVariableReference(self, span), - "static variables cannot be \ - referenced in a pattern, \ - use a `const` instead"); + resolve_error(&ResolutionError::StaticVariableReference(self, + span)); return BareIdentifierPatternUnresolved; } _ => { @@ -2715,10 +2963,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Failed(err) => { match err { Some((span, msg)) => { - resolve_error(&ResolutionError::FailedToResolve(self, span), - &*format!("failed to resolve. {}", - msg) - ); + resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); } None => () } @@ -2947,10 +3192,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - resolve_error(&ResolutionError::FailedToResolve(self, span), - &*format!("failed to resolve. {}", - msg) - ); + resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); return None; } Indeterminate => panic!("indeterminate unexpected"), @@ -3009,10 +3251,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - resolve_error(&ResolutionError::FailedToResolve(self, span), - &*format!("failed to resolve. {}", - msg) - ); + resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); return None; } @@ -3108,10 +3347,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { failed to resolve {}", name); if let Some((span, msg)) = err { - resolve_error(&ResolutionError::FailedToResolve(self, span), - &*format!("failed to resolve. {}", - msg) - ) + resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)) } return None; @@ -3314,11 +3550,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let DefVariant(_, _, true) = path_res.base_def { let path_name = path_names_to_string(path, 0); - resolve_error(&ResolutionError::StructVariantUsedAsFunction(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, + &*path_name)); let msg = format!("did you mean to write: \ `{} {{ /* fields */ }}`?", @@ -3355,11 +3589,9 @@ 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_error(&ResolutionError::StructVariantUsedAsFunction(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, + &*path_name)); let msg = format!("did you mean to write: \ `{} {{ /* fields */ }}`?", @@ -3386,11 +3618,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if method_scope && &token::get_name(special_names::self_)[..] == path_name { - resolve_err!(self, expr.span, E0424, - "{}", - "`self` is not available \ - in a static method. Maybe a \ - `self` argument is missing?"); + resolve_error( + &ResolutionError::SelfNotAvailableInStaticMethod( + self, + expr.span) + ); } else { let last_name = path.segments.last().unwrap().identifier.name; let mut msg = match self.find_fallback_in_self_type(last_name) { @@ -3414,10 +3646,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { msg = format!(". Did you mean {}?", msg) } - resolve_err!(self, expr.span, E0425, - "unresolved name `{}`{}", - path_name, - msg); + resolve_error(&ResolutionError::UnresolvedName(self, + expr.span, + &*path_name, + &*msg)); } } } @@ -3435,9 +3667,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { None => { debug!("(resolving expression) didn't find struct def",); - resolve_error(&ResolutionError::DoesNotNameAStruct(self, path.span), - &*format!("`{}` does not name a structure", - path_names_to_string(path, 0))); + resolve_error(&ResolutionError::DoesNotNameAStruct( + self, + path.span, + &*path_names_to_string(path, 0)) + ); } } @@ -3462,9 +3696,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let renamed = mtwt::resolve(label); match self.search_label(renamed) { None => { - resolve_err!(self, expr.span, E0426, - "use of undeclared label `{}`", - token::get_ident(label)) + resolve_error(&ResolutionError::UndeclaredLabel(self, + expr.span, + &*token::get_ident(label))) } Some(DlDef(def @ DefLabel(_))) => { // Since this def is a label, it is never read. @@ -3610,9 +3844,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { match pat_binding_mode { BindByValue(_) => {} BindByRef(..) => { - resolve_err!(self, pat.span, E0427, - "cannot use `ref` binding mode with {}", - descr); + resolve_error(&ResolutionError::CannotUseRefBindingModeWith(self, + pat.span, + descr)); } } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 196de63bfd9..3b06eab8cf2 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -272,12 +272,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { Some((span, msg)) => (span, format!(". {}", msg)), None => (import_directive.span, String::new()) }; - ::resolve_error(&::ResolutionError::UnresolvedImport(self.resolver, span), - &*format!("unresolved import `{}`{}", - import_path_to_string( - &import_directive.module_path, - import_directive.subclass), - help) + ::resolve_error(&::ResolutionError::UnresolvedImport(self.resolver, span, + Some((&*import_path_to_string( + &import_directive.module_path, + import_directive.subclass), + Some(&*help)))) ); } ResolveResult::Indeterminate => break, // Bail out. We'll come around next time. -- cgit 1.4.1-3-g733a5 From 31262c206e9d0152610572859092132555c7d492 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 14 Jul 2015 16:32:43 +0200 Subject: Arguments are now passed directly to the function instead of the enum variants --- src/librustc_resolve/build_reduced_graph.rs | 22 +- src/librustc_resolve/lib.rs | 367 ++++++++++++++-------------- src/librustc_resolve/resolve_imports.rs | 4 +- 3 files changed, 197 insertions(+), 196 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 782e0a3660b..67eeb19e6fd 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -209,9 +209,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { // had the duplicate. let ns = ns.unwrap(); ::resolve_error( + self, + sp, &::ResolutionError::DuplicateDefinition( - self, - sp, namespace_error_to_string(duplicate_type), &*token::get_name(name)) ); @@ -307,9 +307,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" { - ::resolve_error(&::ResolutionError::SelfImportsOnlyAllowedWithin( - self, - view_path.span) + ::resolve_error(self, + view_path.span, + &::ResolutionError::SelfImportsOnlyAllowedWithin ); } @@ -331,9 +331,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { }).collect::>(); if mod_spans.len() > 1 { ::resolve_error( - &::ResolutionError::SelfImportCanOnlyAppearOnceInTheList( - self, - mod_spans[0]) + self, + mod_spans[0], + &::ResolutionError::SelfImportCanOnlyAppearOnceInTheList ); for other_span in mod_spans.iter().skip(1) { self.session.span_note(*other_span, @@ -350,10 +350,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { Some(name) => *name, None => { ::resolve_error( + self, + source_item.span, &::ResolutionError:: - SelfImportOnlyInImportListWithNonEmptyPrefix( - self, - source_item.span) + SelfImportOnlyInImportListWithNonEmptyPrefix ); continue; } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 850a5d1db26..6a8022341b0 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -116,249 +116,237 @@ mod record_exports; mod build_reduced_graph; mod resolve_imports; -pub enum ResolutionError<'b, 'a:'b, 'tcx:'a> { +pub enum ResolutionError<'b> { /// error E0401: can't use type parameters from outer function - TypeParametersFromOuterFunction(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + TypeParametersFromOuterFunction, /// error E0402: cannot use an outer type parameter in this context - OuterTypeParameterContext(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + OuterTypeParameterContext, /// error E0403: the name is already used for a type parameter in this type parameter list - NameAlreadyUsedInTypeParameterList(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, - syntax::ast::Name), + NameAlreadyUsedInTypeParameterList(syntax::ast::Name), /// error E0404: is not a trait - IsNotATrait(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + IsNotATrait(&'b str), /// error E0405: use of undeclared trait name - UndeclaredTraitName(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + UndeclaredTraitName(&'b str), /// error E0406: undeclared associated type - UndeclaredAssociatedType(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + UndeclaredAssociatedType, /// error E0407: method is not a member of trait - MethodNotMemberOfTrait(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, syntax::ast::Name, - &'b str), + MethodNotMemberOfTrait(syntax::ast::Name, &'b str), /// error E0408: variable `{}` from pattern #1 is not bound in pattern - VariableNotBoundInPattern(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, syntax::ast::Name, - usize), + VariableNotBoundInPattern(syntax::ast::Name, usize), /// error E0409: variable is bound with different mode in pattern #{} than in pattern #1 - VariableBoundWithDifferentMode(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, - syntax::ast::Name, usize), + VariableBoundWithDifferentMode(syntax::ast::Name, usize), /// error E0410: variable from pattern is not bound in pattern #1 - VariableNotBoundInParentPattern(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, - syntax::ast::Name, usize), + VariableNotBoundInParentPattern(syntax::ast::Name, usize), /// error E0411: use of `Self` outside of an impl or trait - SelfUsedOutsideImplOrTrait(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + SelfUsedOutsideImplOrTrait, /// error E0412: use of undeclared - UseOfUndeclared(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str, &'b str), + UseOfUndeclared(&'b str, &'b str), /// error E0413: declaration shadows an enum variant or unit-like struct in scope - DeclarationShadowsEnumVariantOrUnitLikeStruct(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, - syntax::ast::Name), + DeclarationShadowsEnumVariantOrUnitLikeStruct(syntax::ast::Name), /// error E0414: only irrefutable patterns allowed here - OnlyIrrefutablePatternsAllowedHere(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + OnlyIrrefutablePatternsAllowedHere, /// error E0415: identifier is bound more than once in this parameter list - IdentifierBoundMoreThanOnceInParameterList(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, - &'b str), + IdentifierBoundMoreThanOnceInParameterList(&'b str), /// error E0416: identifier is bound more than once in the same pattern - IdentifierBoundMoreThanOnceInSamePattern(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, - &'b str), + IdentifierBoundMoreThanOnceInSamePattern(&'b str), /// error E0417: static variables cannot be referenced in a pattern - StaticVariableReference(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + StaticVariableReference, /// error E0418: is not an enum variant, struct or const - NotAnEnumVariantStructOrConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + NotAnEnumVariantStructOrConst(&'b str), /// error E0419: unresolved enum variant, struct or const - UnresolvedEnumVariantStructOrConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + UnresolvedEnumVariantStructOrConst(&'b str), /// error E0420: is not an associated const - NotAnAssociatedConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + NotAnAssociatedConst(&'b str), /// error E0421: unresolved associated const - UnresolvedAssociatedConst(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + UnresolvedAssociatedConst(&'b str), /// error E0422: does not name a struct - DoesNotNameAStruct(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + DoesNotNameAStruct(&'b str), /// error E0423: is a struct variant name, but this expression uses it like a function name - StructVariantUsedAsFunction(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + StructVariantUsedAsFunction(&'b str), /// error E0424: `self` is not available in a static method - SelfNotAvailableInStaticMethod(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + SelfNotAvailableInStaticMethod, /// error E0425: unresolved name - UnresolvedName(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str, &'b str), + UnresolvedName(&'b str, &'b str), /// error E0426: use of undeclared label - UndeclaredLabel(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + UndeclaredLabel(&'b str), /// error E0427: cannot use `ref` binding mode with ... - CannotUseRefBindingModeWith(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + CannotUseRefBindingModeWith(&'b str), /// error E0428: duplicate definition - DuplicateDefinition(&'a Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str, &'b str), + DuplicateDefinition(&'b str, &'b str), /// error E0429: `self` imports are only allowed within a { } list - SelfImportsOnlyAllowedWithin(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + SelfImportsOnlyAllowedWithin, /// error E0430: `self` import can only appear once in the list - SelfImportCanOnlyAppearOnceInTheList(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + SelfImportCanOnlyAppearOnceInTheList, /// error E0431: `self` import can only appear in an import list with a non-empty prefix - SelfImportOnlyInImportListWithNonEmptyPrefix(&'a Resolver<'a, 'tcx>, syntax::codemap::Span), + SelfImportOnlyInImportListWithNonEmptyPrefix, /// error E0432: unresolved import - UnresolvedImport(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, - Option<(&'b str, Option<&'b str>)>), + UnresolvedImport(Option<(&'b str, Option<&'b str>)>), /// error E0433: failed to resolve - FailedToResolve(&'b Resolver<'a, 'tcx>, syntax::codemap::Span, &'b str), + FailedToResolve(&'b str), /// error E0434: can't capture dynamic environment in a fn item - CannotCaptureDynamicEnvironmentInFnItem(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + CannotCaptureDynamicEnvironmentInFnItem, /// error E0435: attempt to use a non-constant value in a constant - AttemptToUseNonConstantValueInConstant(&'b Resolver<'a, 'tcx>, syntax::codemap::Span), + AttemptToUseNonConstantValueInConstant, } -fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolution_error: &ResolutionError<'b, 'a, 'tcx>) { +fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syntax::codemap::Span, + resolution_error: &ResolutionError<'b>) { match resolution_error { - &ResolutionError::TypeParametersFromOuterFunction(resolver, span) => { + &ResolutionError::TypeParametersFromOuterFunction => { resolve_err!(resolver, span, E0401, "can't use type parameters from \ outer function; try using a local \ type parameter instead"); }, - &ResolutionError::OuterTypeParameterContext(resolver, span) => { + &ResolutionError::OuterTypeParameterContext => { resolve_err!(resolver, span, E0402, "cannot use an outer type parameter in this context"); }, - &ResolutionError::NameAlreadyUsedInTypeParameterList(resolver, span, name) => { + &ResolutionError::NameAlreadyUsedInTypeParameterList(name) => { resolve_err!(resolver, span, E0403, "the name `{}` is already used for a type \ parameter in this type parameter list", name); }, - &ResolutionError::IsNotATrait(resolver, span, name) => { + &ResolutionError::IsNotATrait(name) => { resolve_err!(resolver, span, E0404, "`{}` is not a trait", name); }, - &ResolutionError::UndeclaredTraitName(resolver, span, name) => { + &ResolutionError::UndeclaredTraitName(name) => { resolve_err!(resolver, span, E0405, "use of undeclared trait name `{}`", name); }, - &ResolutionError::UndeclaredAssociatedType(resolver, span) => { + &ResolutionError::UndeclaredAssociatedType => { resolve_err!(resolver, span, E0406, "undeclared associated type"); }, - &ResolutionError::MethodNotMemberOfTrait(resolver, span, method, trait_) => { + &ResolutionError::MethodNotMemberOfTrait(method, trait_) => { resolve_err!(resolver, span, E0407, "method `{}` is not a member of trait `{}`", method, trait_); }, - &ResolutionError::VariableNotBoundInPattern(resolver, span, variable_name, - pattern_number) => { + &ResolutionError::VariableNotBoundInPattern(variable_name, pattern_number) => { resolve_err!(resolver, span, E0408, "variable `{}` from pattern #1 is not bound in pattern #{}", variable_name, pattern_number); }, - &ResolutionError::VariableBoundWithDifferentMode(resolver, span, variable_name, - pattern_number) => { + &ResolutionError::VariableBoundWithDifferentMode(variable_name, pattern_number) => { resolve_err!(resolver, span, E0409, "variable `{}` is bound with different \ mode in pattern #{} than in pattern #1", variable_name, pattern_number); }, - &ResolutionError::VariableNotBoundInParentPattern(resolver, span, variable_name, - pattern_number) => { + &ResolutionError::VariableNotBoundInParentPattern(variable_name, pattern_number) => { resolve_err!(resolver, span, E0410, "variable `{}` from pattern #{} is not bound in pattern #1", variable_name, pattern_number); }, - &ResolutionError::SelfUsedOutsideImplOrTrait(resolver, span) => { + &ResolutionError::SelfUsedOutsideImplOrTrait => { resolve_err!(resolver, span, E0411, "use of `Self` outside of an impl or trait"); }, - &ResolutionError::UseOfUndeclared(resolver, span, kind, name) => { + &ResolutionError::UseOfUndeclared(kind, name) => { resolve_err!(resolver, span, E0412, "use of undeclared {} `{}`", kind, name); }, - &ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(resolver, span, name) => { + &ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(name) => { resolve_err!(resolver, span, E0413, "declaration of `{}` shadows an enum variant or unit-like struct in \ scope", name); }, - &ResolutionError::OnlyIrrefutablePatternsAllowedHere(resolver, span) => { + &ResolutionError::OnlyIrrefutablePatternsAllowedHere => { resolve_err!(resolver, span, E0414, "only irrefutable patterns allowed here"); }, - &ResolutionError::IdentifierBoundMoreThanOnceInParameterList(resolver, span, - identifier) => { + &ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => { resolve_err!(resolver, span, E0415, "identifier `{}` is bound more than once in this parameter list", identifier); }, - &ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(resolver, span, identifier) => { + &ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => { resolve_err!(resolver, span, E0416, "identifier `{}` is bound more than once in the same pattern", identifier); }, - &ResolutionError::StaticVariableReference(resolver, span) => { + &ResolutionError::StaticVariableReference => { resolve_err!(resolver, span, E0417, "static variables cannot be \ referenced in a pattern, \ use a `const` instead"); }, - &ResolutionError::NotAnEnumVariantStructOrConst(resolver, span, name) => { + &ResolutionError::NotAnEnumVariantStructOrConst(name) => { resolve_err!(resolver, span, E0418, "`{}` is not an enum variant, struct or const", name); }, - &ResolutionError::UnresolvedEnumVariantStructOrConst(resolver, span, name) => { + &ResolutionError::UnresolvedEnumVariantStructOrConst(name) => { resolve_err!(resolver, span, E0419, "unresolved enum variant, struct or const `{}`", name); }, - &ResolutionError::NotAnAssociatedConst(resolver, span, name) => { + &ResolutionError::NotAnAssociatedConst(name) => { resolve_err!(resolver, span, E0420, "`{}` is not an associated const", name); }, - &ResolutionError::UnresolvedAssociatedConst(resolver, span, name) => { + &ResolutionError::UnresolvedAssociatedConst(name) => { resolve_err!(resolver, span, E0421, "unresolved associated const `{}`", name); }, - &ResolutionError::DoesNotNameAStruct(resolver, span, name) => { + &ResolutionError::DoesNotNameAStruct(name) => { resolve_err!(resolver, span, E0422, "`{}` does not name a structure", name); }, - &ResolutionError::StructVariantUsedAsFunction(resolver, span, path_name) => { + &ResolutionError::StructVariantUsedAsFunction(path_name) => { resolve_err!(resolver, span, E0423, "`{}` is a struct variant name, but \ this expression \ uses it like a function name", path_name); }, - &ResolutionError::SelfNotAvailableInStaticMethod(resolver, span) => { + &ResolutionError::SelfNotAvailableInStaticMethod => { resolve_err!(resolver, span, E0424, "`self` is not available in a static method. \ Maybe a `self` argument is missing?"); }, - &ResolutionError::UnresolvedName(resolver, span, path, name) => { + &ResolutionError::UnresolvedName(path, name) => { resolve_err!(resolver, span, E0425, "unresolved name `{}`{}", path, name); }, - &ResolutionError::UndeclaredLabel(resolver, span, name) => { + &ResolutionError::UndeclaredLabel(name) => { resolve_err!(resolver, span, E0426, "use of undeclared label `{}`", name); }, - &ResolutionError::CannotUseRefBindingModeWith(resolver, span, descr) => { + &ResolutionError::CannotUseRefBindingModeWith(descr) => { resolve_err!(resolver, span, E0427, "cannot use `ref` binding mode with {}", descr); }, - &ResolutionError::DuplicateDefinition(resolver, span, namespace, name) => { + &ResolutionError::DuplicateDefinition(namespace, name) => { resolve_err!(resolver, span, E0428, "duplicate definition of {} `{}`", namespace, name); }, - &ResolutionError::SelfImportsOnlyAllowedWithin(resolver, span) => { + &ResolutionError::SelfImportsOnlyAllowedWithin => { resolve_err!(resolver, span, E0429, "{}", "`self` imports are only allowed within a { } list"); }, - &ResolutionError::SelfImportCanOnlyAppearOnceInTheList(resolver, span) => { + &ResolutionError::SelfImportCanOnlyAppearOnceInTheList => { resolve_err!(resolver, span, E0430, "`self` import can only appear once in the list"); }, - &ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix(resolver, span) => { + &ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => { resolve_err!(resolver, span, E0431, "`self` import can only appear in an import list with a \ non-empty prefix"); } - &ResolutionError::UnresolvedImport(resolver, span, name) => { + &ResolutionError::UnresolvedImport(name) => { let msg = match name { Some((n, Some(p))) => format!("unresolved import `{}`{}", n, p), Some((n, None)) => format!("unresolved import (maybe you meant `{}::*`?)", n), @@ -366,15 +354,15 @@ fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolution_error: &ResolutionError<'b, 'a, }; resolve_err!(resolver, span, E0432, "{}", msg); }, - &ResolutionError::FailedToResolve(resolver, span, msg) => { + &ResolutionError::FailedToResolve(msg) => { resolve_err!(resolver, span, E0433, "failed to resolve. {}", msg); }, - &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem(resolver, span) => { + &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => { resolve_err!(resolver, span, E0434, "{}", "can't capture dynamic environment in a fn item; \ use the || { ... } closure form instead"); }, - &ResolutionError::AttemptToUseNonConstantValueInConstant(resolver, span) =>{ + &ResolutionError::AttemptToUseNonConstantValueInConstant =>{ resolve_err!(resolver, span, E0435, "attempt to use a non-constant value in a constant"); }, @@ -1575,7 +1563,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { PathSearch, true) { Failed(Some((span, msg))) => { - resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); + resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); }, Failed(None) => (), // Continue up the search chain. Indeterminate => { @@ -1833,13 +1821,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .span_to_snippet((*imports)[index].span) .unwrap(); if sn.contains("::") { - resolve_error(&ResolutionError::UnresolvedImport(self, - (*imports)[index].span, - None)); + resolve_error(self, + (*imports)[index].span, + &ResolutionError::UnresolvedImport(None)); } else { - resolve_error(&ResolutionError::UnresolvedImport(self, - (*imports)[index].span, - Some((&*sn, None)))); + resolve_error(self, + (*imports)[index].span, + &ResolutionError::UnresolvedImport(Some((&*sn, None)))); } } @@ -1966,18 +1954,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // named function item. This is not allowed, so we // report an error. resolve_error( - &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem( - self, - span) + self, + span, + &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem ); return None; } ConstantItemRibKind => { // Still doesn't deal with upvars resolve_error( - &ResolutionError::AttemptToUseNonConstantValueInConstant( - self, - span) + self, + span, + &ResolutionError::AttemptToUseNonConstantValueInConstant ); return None; } @@ -1994,13 +1982,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // This was an attempt to use a type parameter outside // its scope. - resolve_error(&ResolutionError::TypeParametersFromOuterFunction(self, - span)); + resolve_error(self, + span, + &ResolutionError::TypeParametersFromOuterFunction); return None; } ConstantItemRibKind => { // see #9186 - resolve_error(&ResolutionError::OuterTypeParameterContext(self, span)); + resolve_error(self, span, &ResolutionError::OuterTypeParameterContext); return None; } } @@ -2198,10 +2187,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("with_type_parameter_rib: {}", type_parameter.id); if seen_bindings.contains(&name) { - resolve_error(&ResolutionError::NameAlreadyUsedInTypeParameterList( - self, - type_parameter.span, - name)); + resolve_error(self, + type_parameter.span, + &ResolutionError::NameAlreadyUsedInTypeParameterList( + name) + ); } seen_bindings.insert(name); @@ -2288,9 +2278,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { debug!("(resolving trait) found trait def: {:?}", path_res); Ok(path_res) } else { - resolve_error(&ResolutionError::IsNotATrait(self, trait_path.span, - &*path_names_to_string(trait_path, - path_depth)) + resolve_error(self, + trait_path.span, + &ResolutionError::IsNotATrait(&*path_names_to_string(trait_path, + path_depth)) ); // If it's a typedef, give a note @@ -2301,10 +2292,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Err(()) } } else { - resolve_error(&ResolutionError::UndeclaredTraitName(self, - trait_path.span, - &*path_names_to_string(trait_path, - path_depth))); + resolve_error(self, + trait_path.span, + &ResolutionError::UndeclaredTraitName( + &*path_names_to_string(trait_path, path_depth)) + ); Err(()) } } @@ -2322,8 +2314,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(PathResolution { base_def: DefTyParam(..), .. }) = path_res { self.record_def(eq_pred.id, path_res.unwrap()); } else { - resolve_error(&ResolutionError::UndeclaredAssociatedType(self, - eq_pred.span)); + resolve_error(self, + eq_pred.span, + &ResolutionError::UndeclaredAssociatedType); } } } @@ -2448,9 +2441,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some((did, ref trait_ref)) = self.current_trait_ref { if !self.trait_item_map.contains_key(&(name, did)) { let path_str = path_names_to_string(&trait_ref.path, 0); - resolve_error(&ResolutionError::MethodNotMemberOfTrait(self, - span, - name, + resolve_error(self, + span, + &ResolutionError::MethodNotMemberOfTrait(name, &*path_str)); } } @@ -2498,18 +2491,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding_0) in &map_0 { match map_i.get(&key) { None => { - resolve_error(&ResolutionError::VariableNotBoundInPattern(self, - p.span, - key, + resolve_error(self, + p.span, + &ResolutionError::VariableNotBoundInPattern(key, i + 1)); } Some(binding_i) => { if binding_0.binding_mode != binding_i.binding_mode { - resolve_error(&ResolutionError::VariableBoundWithDifferentMode( - self, - binding_i.span, - key, - i + 1) + resolve_error(self, + binding_i.span, + &ResolutionError::VariableBoundWithDifferentMode(key, + i + 1) ); } } @@ -2518,9 +2510,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { for (&key, &binding) in &map_i { if !map_0.contains_key(&key) { - resolve_error(&ResolutionError::VariableNotBoundInParentPattern(self, - binding.span, - key, + resolve_error(self, + binding.span, + &ResolutionError::VariableNotBoundInParentPattern(key, i + 1)); } } @@ -2635,12 +2627,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { maybe_qself.is_none() && path.segments[0].identifier.name == self_type_name; if is_invalid_self_type_name { - resolve_error(&ResolutionError::SelfUsedOutsideImplOrTrait(self, - ty.span)); + resolve_error(self, + ty.span, + &ResolutionError::SelfUsedOutsideImplOrTrait); } else { - resolve_error(&ResolutionError::UseOfUndeclared( - self, - ty.span, + resolve_error(self, + ty.span, + &ResolutionError::UseOfUndeclared( kind, &*path_names_to_string(path, 0)) @@ -2697,9 +2690,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } FoundStructOrEnumVariant(..) => { resolve_error( + self, + pattern.span, &ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct( - self, - pattern.span, renamed) ); } @@ -2720,9 +2713,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } FoundConst(..) => { resolve_error( - &ResolutionError::OnlyIrrefutablePatternsAllowedHere( - self, - pattern.span) + self, + pattern.span, + &ResolutionError::OnlyIrrefutablePatternsAllowedHere ); } BareIdentifierPatternUnresolved => { @@ -2756,9 +2749,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // Forbid duplicate bindings in the same // parameter list. resolve_error( + self, + pattern.span, &ResolutionError::IdentifierBoundMoreThanOnceInParameterList( - self, - pattern.span, &*token::get_ident(ident)) ); } else if bindings_list.get(&renamed) == @@ -2766,9 +2759,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // Then this is a duplicate variable in the // same disjunction, which is an error. resolve_error( + self, + pattern.span, &ResolutionError::IdentifierBoundMoreThanOnceInSamePattern( - self, - pattern.span, &*token::get_ident(ident)) ); } @@ -2801,8 +2794,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.record_def(pattern.id, path_res); } DefStatic(..) => { - resolve_error(&ResolutionError::StaticVariableReference(&self, - path.span)); + resolve_error(&self, + path.span, + &ResolutionError::StaticVariableReference); } _ => { // If anything ends up here entirely resolved, @@ -2811,9 +2805,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // be a `T::CONST` that typeck will resolve. if path_res.depth == 0 { resolve_error( + self, + path.span, &ResolutionError::NotAnEnumVariantStructOrConst( - self, - path.span, &*token::get_ident( path.segments.last().unwrap().identifier) ) @@ -2829,9 +2823,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } else { resolve_error( + self, + path.span, &ResolutionError::UnresolvedEnumVariantStructOrConst( - self, - path.span, &*token::get_ident(path.segments.last().unwrap().identifier)) ); } @@ -2866,9 +2860,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } _ => { resolve_error( + self, + path.span, &ResolutionError::NotAnAssociatedConst( - self, - path.span, &*token::get_ident( path.segments.last().unwrap().identifier) ) @@ -2877,9 +2871,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } else { resolve_error( + self, + path.span, &ResolutionError::UnresolvedAssociatedConst( - self, - path.span, &*token::get_ident(path.segments.last().unwrap().identifier) ) ); @@ -2895,11 +2889,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { result => { debug!("(resolving pattern) didn't find struct \ def: {:?}", result); - resolve_error(&ResolutionError::DoesNotNameAStruct( - self, - path.span, - &*path_names_to_string(path, 0)) - ); + resolve_error( + self, + path.span, + &ResolutionError::DoesNotNameAStruct( + &*path_names_to_string(path, 0)) + ); } } visit::walk_path(self, path); @@ -2945,8 +2940,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { return FoundConst(def, LastMod(AllPublic)); } DefStatic(..) => { - resolve_error(&ResolutionError::StaticVariableReference(self, - span)); + resolve_error(self, + span, + &ResolutionError::StaticVariableReference); return BareIdentifierPatternUnresolved; } _ => { @@ -2963,7 +2959,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Failed(err) => { match err { Some((span, msg)) => { - resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); + resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); } None => () } @@ -3192,7 +3188,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); + resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); return None; } Indeterminate => panic!("indeterminate unexpected"), @@ -3251,7 +3247,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)); + resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); return None; } @@ -3347,7 +3343,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { failed to resolve {}", name); if let Some((span, msg)) = err { - resolve_error(&ResolutionError::FailedToResolve(self, span, &*msg)) + resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)) } return None; @@ -3550,9 +3546,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let DefVariant(_, _, true) = path_res.base_def { let path_name = path_names_to_string(path, 0); - resolve_error(&ResolutionError::StructVariantUsedAsFunction(self, - expr.span, - &*path_name)); + resolve_error(self, + expr.span, + &ResolutionError::StructVariantUsedAsFunction(&*path_name)); let msg = format!("did you mean to write: \ `{} {{ /* fields */ }}`?", @@ -3589,9 +3585,12 @@ 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_error(&ResolutionError::StructVariantUsedAsFunction(self, - expr.span, - &*path_name)); + resolve_error( + self, + expr.span, + &ResolutionError::StructVariantUsedAsFunction( + &*path_name) + ); let msg = format!("did you mean to write: \ `{} {{ /* fields */ }}`?", @@ -3619,9 +3618,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if method_scope && &token::get_name(special_names::self_)[..] == path_name { resolve_error( - &ResolutionError::SelfNotAvailableInStaticMethod( - self, - expr.span) + self, + expr.span, + &ResolutionError::SelfNotAvailableInStaticMethod ); } else { let last_name = path.segments.last().unwrap().identifier.name; @@ -3646,9 +3645,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { msg = format!(". Did you mean {}?", msg) } - resolve_error(&ResolutionError::UnresolvedName(self, - expr.span, - &*path_name, + resolve_error(self, + expr.span, + &ResolutionError::UnresolvedName(&*path_name, &*msg)); } } @@ -3667,9 +3666,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { None => { debug!("(resolving expression) didn't find struct def",); - resolve_error(&ResolutionError::DoesNotNameAStruct( - self, - path.span, + resolve_error(self, + path.span, + &ResolutionError::DoesNotNameAStruct( &*path_names_to_string(path, 0)) ); } @@ -3696,9 +3695,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let renamed = mtwt::resolve(label); match self.search_label(renamed) { None => { - resolve_error(&ResolutionError::UndeclaredLabel(self, - expr.span, - &*token::get_ident(label))) + resolve_error(self, + expr.span, + &ResolutionError::UndeclaredLabel(&*token::get_ident(label))) } Some(DlDef(def @ DefLabel(_))) => { // Since this def is a label, it is never read. @@ -3844,9 +3843,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { match pat_binding_mode { BindByValue(_) => {} BindByRef(..) => { - resolve_error(&ResolutionError::CannotUseRefBindingModeWith(self, - pat.span, - descr)); + resolve_error(self, + pat.span, + &ResolutionError::CannotUseRefBindingModeWith(descr)); } } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 3b06eab8cf2..080c99b07d6 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -272,7 +272,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { Some((span, msg)) => (span, format!(". {}", msg)), None => (import_directive.span, String::new()) }; - ::resolve_error(&::ResolutionError::UnresolvedImport(self.resolver, span, + ::resolve_error(self.resolver, + span, + &::ResolutionError::UnresolvedImport( Some((&*import_path_to_string( &import_directive.module_path, import_directive.subclass), -- cgit 1.4.1-3-g733a5 From 60133aa6dd4bf288cacbaba72368f80c131d252c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 14 Jul 2015 19:42:38 +0200 Subject: Remove macro, import function and enum --- src/librustc_resolve/build_reduced_graph.rs | 19 +- src/librustc_resolve/lib.rs | 289 ++++++++++++++-------------- src/librustc_resolve/resolve_imports.rs | 5 +- 3 files changed, 155 insertions(+), 158 deletions(-) (limited to 'src') diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 67eeb19e6fd..f8ccbe4cecd 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -26,6 +26,7 @@ use ParentLink::{self, ModuleParentLink, BlockParentLink}; use Resolver; use resolve_imports::Shadowable; use TypeNsDef; +use {resolve_error, ResolutionError}; use self::DuplicateCheckingMode::*; use self::NamespaceError::*; @@ -208,12 +209,12 @@ 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(); - ::resolve_error( + resolve_error( self, sp, - &::ResolutionError::DuplicateDefinition( + ResolutionError::DuplicateDefinition( namespace_error_to_string(duplicate_type), - &*token::get_name(name)) + name) ); { let r = child.span_for_namespace(ns); @@ -307,9 +308,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" { - ::resolve_error(self, + resolve_error(self, view_path.span, - &::ResolutionError::SelfImportsOnlyAllowedWithin + ResolutionError::SelfImportsOnlyAllowedWithin ); } @@ -330,10 +331,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { _ => None }).collect::>(); if mod_spans.len() > 1 { - ::resolve_error( + resolve_error( self, mod_spans[0], - &::ResolutionError::SelfImportCanOnlyAppearOnceInTheList + ResolutionError::SelfImportCanOnlyAppearOnceInTheList ); for other_span in mod_spans.iter().skip(1) { self.session.span_note(*other_span, @@ -349,10 +350,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let name = match module_path.last() { Some(name) => *name, None => { - ::resolve_error( + resolve_error( self, source_item.span, - &::ResolutionError:: + ResolutionError:: SelfImportOnlyInImportListWithNonEmptyPrefix ); continue; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 6a8022341b0..2d48f322724 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -103,76 +103,68 @@ use resolve_imports::Shadowable; // registered before they are used. pub mod diagnostics; -macro_rules! resolve_err { - ($this:expr, $span:expr, $code:ident, $($rest:tt)*) => { - if $this.emit_errors { - span_err!($this.session, $span, $code, $($rest)*); - } - } -} - mod check_unused; mod record_exports; mod build_reduced_graph; mod resolve_imports; -pub enum ResolutionError<'b> { +pub enum ResolutionError<'a> { /// error E0401: can't use type parameters from outer function TypeParametersFromOuterFunction, /// error E0402: cannot use an outer type parameter in this context OuterTypeParameterContext, /// error E0403: the name is already used for a type parameter in this type parameter list - NameAlreadyUsedInTypeParameterList(syntax::ast::Name), + NameAlreadyUsedInTypeParameterList(Name), /// error E0404: is not a trait - IsNotATrait(&'b str), + IsNotATrait(&'a str), /// error E0405: use of undeclared trait name - UndeclaredTraitName(&'b str), + UndeclaredTraitName(&'a str), /// error E0406: undeclared associated type UndeclaredAssociatedType, /// error E0407: method is not a member of trait - MethodNotMemberOfTrait(syntax::ast::Name, &'b str), + MethodNotMemberOfTrait(Name, &'a str), /// error E0408: variable `{}` from pattern #1 is not bound in pattern - VariableNotBoundInPattern(syntax::ast::Name, usize), + VariableNotBoundInPattern(Name, usize), /// error E0409: variable is bound with different mode in pattern #{} than in pattern #1 - VariableBoundWithDifferentMode(syntax::ast::Name, usize), + VariableBoundWithDifferentMode(Name, usize), /// error E0410: variable from pattern is not bound in pattern #1 - VariableNotBoundInParentPattern(syntax::ast::Name, usize), + VariableNotBoundInParentPattern(Name, usize), /// error E0411: use of `Self` outside of an impl or trait SelfUsedOutsideImplOrTrait, /// error E0412: use of undeclared - UseOfUndeclared(&'b str, &'b str), + UseOfUndeclared(&'a str, &'a str), /// error E0413: declaration shadows an enum variant or unit-like struct in scope - DeclarationShadowsEnumVariantOrUnitLikeStruct(syntax::ast::Name), + DeclarationShadowsEnumVariantOrUnitLikeStruct(Name), /// error E0414: only irrefutable patterns allowed here OnlyIrrefutablePatternsAllowedHere, /// error E0415: identifier is bound more than once in this parameter list - IdentifierBoundMoreThanOnceInParameterList(&'b str), + IdentifierBoundMoreThanOnceInParameterList(&'a str), /// error E0416: identifier is bound more than once in the same pattern - IdentifierBoundMoreThanOnceInSamePattern(&'b str), + IdentifierBoundMoreThanOnceInSamePattern(&'a str), /// error E0417: static variables cannot be referenced in a pattern StaticVariableReference, /// error E0418: is not an enum variant, struct or const - NotAnEnumVariantStructOrConst(&'b str), + NotAnEnumVariantStructOrConst(&'a str), /// error E0419: unresolved enum variant, struct or const - UnresolvedEnumVariantStructOrConst(&'b str), + UnresolvedEnumVariantStructOrConst(&'a str), /// error E0420: is not an associated const - NotAnAssociatedConst(&'b str), + NotAnAssociatedConst(&'a str), /// error E0421: unresolved associated const - UnresolvedAssociatedConst(&'b str), + UnresolvedAssociatedConst(&'a str), /// error E0422: does not name a struct - DoesNotNameAStruct(&'b str), + DoesNotNameAStruct(&'a str), /// error E0423: is a struct variant name, but this expression uses it like a function name - StructVariantUsedAsFunction(&'b str), + StructVariantUsedAsFunction(&'a str), /// error E0424: `self` is not available in a static method SelfNotAvailableInStaticMethod, /// error E0425: unresolved name - UnresolvedName(&'b str, &'b str), + UnresolvedName(&'a str, &'a str), /// error E0426: use of undeclared label - UndeclaredLabel(&'b str), + UndeclaredLabel(&'a str), /// error E0427: cannot use `ref` binding mode with ... - CannotUseRefBindingModeWith(&'b str), + CannotUseRefBindingModeWith(&'a str), /// error E0428: duplicate definition - DuplicateDefinition(&'b str, &'b str), + DuplicateDefinition(&'a str, Name), /// error E0429: `self` imports are only allowed within a { } list SelfImportsOnlyAllowedWithin, /// error E0430: `self` import can only appear once in the list @@ -180,9 +172,9 @@ pub enum ResolutionError<'b> { /// error E0431: `self` import can only appear in an import list with a non-empty prefix SelfImportOnlyInImportListWithNonEmptyPrefix, /// error E0432: unresolved import - UnresolvedImport(Option<(&'b str, Option<&'b str>)>), + UnresolvedImport(Option<(&'a str, Option<&'a str>)>), /// error E0433: failed to resolve - FailedToResolve(&'b str), + FailedToResolve(&'a str), /// error E0434: can't capture dynamic environment in a fn item CannotCaptureDynamicEnvironmentInFnItem, /// error E0435: attempt to use a non-constant value in a constant @@ -190,180 +182,183 @@ pub enum ResolutionError<'b> { } fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syntax::codemap::Span, - resolution_error: &ResolutionError<'b>) { + resolution_error: ResolutionError<'b>) { + if !resolver.emit_errors { + return; + } match resolution_error { - &ResolutionError::TypeParametersFromOuterFunction => { - resolve_err!(resolver, span, E0401, "can't use type parameters from \ - outer function; try using a local \ - type parameter instead"); + ResolutionError::TypeParametersFromOuterFunction => { + span_err!(resolver.session, span, E0401, "can't use type parameters from \ + outer function; try using a local \ + type parameter instead"); }, - &ResolutionError::OuterTypeParameterContext => { - resolve_err!(resolver, span, E0402, + ResolutionError::OuterTypeParameterContext => { + span_err!(resolver.session, span, E0402, "cannot use an outer type parameter in this context"); }, - &ResolutionError::NameAlreadyUsedInTypeParameterList(name) => { - resolve_err!(resolver, span, E0403, + ResolutionError::NameAlreadyUsedInTypeParameterList(name) => { + span_err!(resolver.session, span, E0403, "the name `{}` is already used for a type \ parameter in this type parameter list", name); }, - &ResolutionError::IsNotATrait(name) => { - resolve_err!(resolver, span, E0404, + ResolutionError::IsNotATrait(name) => { + span_err!(resolver.session, span, E0404, "`{}` is not a trait", name); }, - &ResolutionError::UndeclaredTraitName(name) => { - resolve_err!(resolver, span, E0405, + ResolutionError::UndeclaredTraitName(name) => { + span_err!(resolver.session, span, E0405, "use of undeclared trait name `{}`", name); }, - &ResolutionError::UndeclaredAssociatedType => { - resolve_err!(resolver, span, E0406, "undeclared associated type"); + ResolutionError::UndeclaredAssociatedType => { + span_err!(resolver.session, span, E0406, "undeclared associated type"); }, - &ResolutionError::MethodNotMemberOfTrait(method, trait_) => { - resolve_err!(resolver, span, E0407, + ResolutionError::MethodNotMemberOfTrait(method, trait_) => { + span_err!(resolver.session, span, E0407, "method `{}` is not a member of trait `{}`", method, trait_); }, - &ResolutionError::VariableNotBoundInPattern(variable_name, pattern_number) => { - resolve_err!(resolver, span, E0408, + ResolutionError::VariableNotBoundInPattern(variable_name, pattern_number) => { + span_err!(resolver.session, span, E0408, "variable `{}` from pattern #1 is not bound in pattern #{}", variable_name, pattern_number); }, - &ResolutionError::VariableBoundWithDifferentMode(variable_name, pattern_number) => { - resolve_err!(resolver, span, E0409, + ResolutionError::VariableBoundWithDifferentMode(variable_name, pattern_number) => { + span_err!(resolver.session, span, E0409, "variable `{}` is bound with different \ mode in pattern #{} than in pattern #1", variable_name, pattern_number); }, - &ResolutionError::VariableNotBoundInParentPattern(variable_name, pattern_number) => { - resolve_err!(resolver, span, E0410, + ResolutionError::VariableNotBoundInParentPattern(variable_name, pattern_number) => { + span_err!(resolver.session, span, E0410, "variable `{}` from pattern #{} is not bound in pattern #1", variable_name, pattern_number); }, - &ResolutionError::SelfUsedOutsideImplOrTrait => { - resolve_err!(resolver, span, E0411, "use of `Self` outside of an impl or trait"); + ResolutionError::SelfUsedOutsideImplOrTrait => { + span_err!(resolver.session, span, E0411, "use of `Self` outside of an impl or trait"); }, - &ResolutionError::UseOfUndeclared(kind, name) => { - resolve_err!(resolver, span, E0412, + ResolutionError::UseOfUndeclared(kind, name) => { + span_err!(resolver.session, span, E0412, "use of undeclared {} `{}`", kind, name); }, - &ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(name) => { - resolve_err!(resolver, span, E0413, + ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct(name) => { + span_err!(resolver.session, span, E0413, "declaration of `{}` shadows an enum variant or unit-like struct in \ scope", name); }, - &ResolutionError::OnlyIrrefutablePatternsAllowedHere => { - resolve_err!(resolver, span, E0414, "only irrefutable patterns allowed here"); + ResolutionError::OnlyIrrefutablePatternsAllowedHere => { + span_err!(resolver.session, span, E0414, "only irrefutable patterns allowed here"); }, - &ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => { - resolve_err!(resolver, span, E0415, + ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => { + span_err!(resolver.session, span, E0415, "identifier `{}` is bound more than once in this parameter list", identifier); }, - &ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => { - resolve_err!(resolver, span, E0416, + ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => { + span_err!(resolver.session, span, E0416, "identifier `{}` is bound more than once in the same pattern", identifier); }, - &ResolutionError::StaticVariableReference => { - resolve_err!(resolver, span, E0417, "static variables cannot be \ - referenced in a pattern, \ - use a `const` instead"); + ResolutionError::StaticVariableReference => { + span_err!(resolver.session, span, E0417, "static variables cannot be \ + referenced in a pattern, \ + use a `const` instead"); }, - &ResolutionError::NotAnEnumVariantStructOrConst(name) => { - resolve_err!(resolver, span, E0418, + ResolutionError::NotAnEnumVariantStructOrConst(name) => { + span_err!(resolver.session, span, E0418, "`{}` is not an enum variant, struct or const", name); }, - &ResolutionError::UnresolvedEnumVariantStructOrConst(name) => { - resolve_err!(resolver, span, E0419, + ResolutionError::UnresolvedEnumVariantStructOrConst(name) => { + span_err!(resolver.session, span, E0419, "unresolved enum variant, struct or const `{}`", name); }, - &ResolutionError::NotAnAssociatedConst(name) => { - resolve_err!(resolver, span, E0420, + ResolutionError::NotAnAssociatedConst(name) => { + span_err!(resolver.session, span, E0420, "`{}` is not an associated const", name); }, - &ResolutionError::UnresolvedAssociatedConst(name) => { - resolve_err!(resolver, span, E0421, + ResolutionError::UnresolvedAssociatedConst(name) => { + span_err!(resolver.session, span, E0421, "unresolved associated const `{}`", name); }, - &ResolutionError::DoesNotNameAStruct(name) => { - resolve_err!(resolver, span, E0422, "`{}` does not name a structure", name); + ResolutionError::DoesNotNameAStruct(name) => { + span_err!(resolver.session, span, E0422, "`{}` does not name a structure", name); }, - &ResolutionError::StructVariantUsedAsFunction(path_name) => { - resolve_err!(resolver, span, E0423, + ResolutionError::StructVariantUsedAsFunction(path_name) => { + span_err!(resolver.session, span, E0423, "`{}` is a struct variant name, but \ this expression \ uses it like a function name", path_name); }, - &ResolutionError::SelfNotAvailableInStaticMethod => { - resolve_err!(resolver, span, E0424, "`self` is not available in a static method. \ - Maybe a `self` argument is missing?"); + ResolutionError::SelfNotAvailableInStaticMethod => { + span_err!(resolver.session, span, E0424, "`self` is not available in a static method. \ + Maybe a `self` argument is missing?"); }, - &ResolutionError::UnresolvedName(path, name) => { - resolve_err!(resolver, span, E0425, + ResolutionError::UnresolvedName(path, name) => { + span_err!(resolver.session, span, E0425, "unresolved name `{}`{}", path, name); }, - &ResolutionError::UndeclaredLabel(name) => { - resolve_err!(resolver, span, E0426, + ResolutionError::UndeclaredLabel(name) => { + span_err!(resolver.session, span, E0426, "use of undeclared label `{}`", name); }, - &ResolutionError::CannotUseRefBindingModeWith(descr) => { - resolve_err!(resolver, span, E0427, + ResolutionError::CannotUseRefBindingModeWith(descr) => { + span_err!(resolver.session, span, E0427, "cannot use `ref` binding mode with {}", descr); }, - &ResolutionError::DuplicateDefinition(namespace, name) => { - resolve_err!(resolver, span, E0428, + ResolutionError::DuplicateDefinition(namespace, name) => { + span_err!(resolver.session, span, E0428, "duplicate definition of {} `{}`", namespace, name); }, - &ResolutionError::SelfImportsOnlyAllowedWithin => { - resolve_err!(resolver, span, E0429, "{}", + ResolutionError::SelfImportsOnlyAllowedWithin => { + span_err!(resolver.session, span, E0429, "{}", "`self` imports are only allowed within a { } list"); }, - &ResolutionError::SelfImportCanOnlyAppearOnceInTheList => { - resolve_err!(resolver, span, E0430, + ResolutionError::SelfImportCanOnlyAppearOnceInTheList => { + span_err!(resolver.session, span, E0430, "`self` import can only appear once in the list"); }, - &ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => { - resolve_err!(resolver, span, E0431, + ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => { + span_err!(resolver.session, span, E0431, "`self` import can only appear in an import list with a \ non-empty prefix"); } - &ResolutionError::UnresolvedImport(name) => { + ResolutionError::UnresolvedImport(name) => { let msg = match name { Some((n, Some(p))) => format!("unresolved import `{}`{}", n, p), Some((n, None)) => format!("unresolved import (maybe you meant `{}::*`?)", n), None => "unresolved import".to_owned() }; - resolve_err!(resolver, span, E0432, "{}", msg); + span_err!(resolver.session, span, E0432, "{}", msg); }, - &ResolutionError::FailedToResolve(msg) => { - resolve_err!(resolver, span, E0433, "failed to resolve. {}", msg); + ResolutionError::FailedToResolve(msg) => { + span_err!(resolver.session, span, E0433, "failed to resolve. {}", msg); }, - &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => { - resolve_err!(resolver, span, E0434, "{}", + ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => { + span_err!(resolver.session, span, E0434, "{}", "can't capture dynamic environment in a fn item; \ use the || { ... } closure form instead"); }, - &ResolutionError::AttemptToUseNonConstantValueInConstant =>{ - resolve_err!(resolver, span, E0435, + ResolutionError::AttemptToUseNonConstantValueInConstant =>{ + span_err!(resolver.session, span, E0435, "attempt to use a non-constant value in a constant"); }, } @@ -1563,7 +1558,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { PathSearch, true) { Failed(Some((span, msg))) => { - resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); + resolve_error(self, span, ResolutionError::FailedToResolve(&*msg)); }, Failed(None) => (), // Continue up the search chain. Indeterminate => { @@ -1823,11 +1818,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if sn.contains("::") { resolve_error(self, (*imports)[index].span, - &ResolutionError::UnresolvedImport(None)); + ResolutionError::UnresolvedImport(None)); } else { resolve_error(self, (*imports)[index].span, - &ResolutionError::UnresolvedImport(Some((&*sn, None)))); + ResolutionError::UnresolvedImport(Some((&*sn, None)))); } } @@ -1956,7 +1951,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, span, - &ResolutionError::CannotCaptureDynamicEnvironmentInFnItem + ResolutionError::CannotCaptureDynamicEnvironmentInFnItem ); return None; } @@ -1965,7 +1960,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, span, - &ResolutionError::AttemptToUseNonConstantValueInConstant + ResolutionError::AttemptToUseNonConstantValueInConstant ); return None; } @@ -1984,12 +1979,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error(self, span, - &ResolutionError::TypeParametersFromOuterFunction); + ResolutionError::TypeParametersFromOuterFunction); return None; } ConstantItemRibKind => { // see #9186 - resolve_error(self, span, &ResolutionError::OuterTypeParameterContext); + resolve_error(self, span, ResolutionError::OuterTypeParameterContext); return None; } } @@ -2189,7 +2184,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if seen_bindings.contains(&name) { resolve_error(self, type_parameter.span, - &ResolutionError::NameAlreadyUsedInTypeParameterList( + ResolutionError::NameAlreadyUsedInTypeParameterList( name) ); } @@ -2280,7 +2275,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } else { resolve_error(self, trait_path.span, - &ResolutionError::IsNotATrait(&*path_names_to_string(trait_path, + ResolutionError::IsNotATrait(&*path_names_to_string(trait_path, path_depth)) ); @@ -2294,7 +2289,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } else { resolve_error(self, trait_path.span, - &ResolutionError::UndeclaredTraitName( + ResolutionError::UndeclaredTraitName( &*path_names_to_string(trait_path, path_depth)) ); Err(()) @@ -2316,7 +2311,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } else { resolve_error(self, eq_pred.span, - &ResolutionError::UndeclaredAssociatedType); + ResolutionError::UndeclaredAssociatedType); } } } @@ -2443,7 +2438,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let path_str = path_names_to_string(&trait_ref.path, 0); resolve_error(self, span, - &ResolutionError::MethodNotMemberOfTrait(name, + ResolutionError::MethodNotMemberOfTrait(name, &*path_str)); } } @@ -2493,14 +2488,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { None => { resolve_error(self, p.span, - &ResolutionError::VariableNotBoundInPattern(key, + ResolutionError::VariableNotBoundInPattern(key, i + 1)); } Some(binding_i) => { if binding_0.binding_mode != binding_i.binding_mode { resolve_error(self, binding_i.span, - &ResolutionError::VariableBoundWithDifferentMode(key, + ResolutionError::VariableBoundWithDifferentMode(key, i + 1) ); } @@ -2512,7 +2507,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if !map_0.contains_key(&key) { resolve_error(self, binding.span, - &ResolutionError::VariableNotBoundInParentPattern(key, + ResolutionError::VariableNotBoundInParentPattern(key, i + 1)); } } @@ -2629,11 +2624,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if is_invalid_self_type_name { resolve_error(self, ty.span, - &ResolutionError::SelfUsedOutsideImplOrTrait); + ResolutionError::SelfUsedOutsideImplOrTrait); } else { resolve_error(self, ty.span, - &ResolutionError::UseOfUndeclared( + ResolutionError::UseOfUndeclared( kind, &*path_names_to_string(path, 0)) @@ -2692,7 +2687,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, pattern.span, - &ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct( + ResolutionError::DeclarationShadowsEnumVariantOrUnitLikeStruct( renamed) ); } @@ -2715,7 +2710,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, pattern.span, - &ResolutionError::OnlyIrrefutablePatternsAllowedHere + ResolutionError::OnlyIrrefutablePatternsAllowedHere ); } BareIdentifierPatternUnresolved => { @@ -2751,7 +2746,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, pattern.span, - &ResolutionError::IdentifierBoundMoreThanOnceInParameterList( + ResolutionError::IdentifierBoundMoreThanOnceInParameterList( &*token::get_ident(ident)) ); } else if bindings_list.get(&renamed) == @@ -2761,7 +2756,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, pattern.span, - &ResolutionError::IdentifierBoundMoreThanOnceInSamePattern( + ResolutionError::IdentifierBoundMoreThanOnceInSamePattern( &*token::get_ident(ident)) ); } @@ -2796,7 +2791,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { DefStatic(..) => { resolve_error(&self, path.span, - &ResolutionError::StaticVariableReference); + ResolutionError::StaticVariableReference); } _ => { // If anything ends up here entirely resolved, @@ -2807,7 +2802,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, path.span, - &ResolutionError::NotAnEnumVariantStructOrConst( + ResolutionError::NotAnEnumVariantStructOrConst( &*token::get_ident( path.segments.last().unwrap().identifier) ) @@ -2825,7 +2820,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, path.span, - &ResolutionError::UnresolvedEnumVariantStructOrConst( + ResolutionError::UnresolvedEnumVariantStructOrConst( &*token::get_ident(path.segments.last().unwrap().identifier)) ); } @@ -2862,7 +2857,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, path.span, - &ResolutionError::NotAnAssociatedConst( + ResolutionError::NotAnAssociatedConst( &*token::get_ident( path.segments.last().unwrap().identifier) ) @@ -2873,7 +2868,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, path.span, - &ResolutionError::UnresolvedAssociatedConst( + ResolutionError::UnresolvedAssociatedConst( &*token::get_ident(path.segments.last().unwrap().identifier) ) ); @@ -2892,7 +2887,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, path.span, - &ResolutionError::DoesNotNameAStruct( + ResolutionError::DoesNotNameAStruct( &*path_names_to_string(path, 0)) ); } @@ -2942,7 +2937,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { DefStatic(..) => { resolve_error(self, span, - &ResolutionError::StaticVariableReference); + ResolutionError::StaticVariableReference); return BareIdentifierPatternUnresolved; } _ => { @@ -2959,7 +2954,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Failed(err) => { match err { Some((span, msg)) => { - resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); + resolve_error(self, span, ResolutionError::FailedToResolve(&*msg)); } None => () } @@ -3188,7 +3183,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); + resolve_error(self, span, ResolutionError::FailedToResolve(&*msg)); return None; } Indeterminate => panic!("indeterminate unexpected"), @@ -3247,7 +3242,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)); + resolve_error(self, span, ResolutionError::FailedToResolve(&*msg)); return None; } @@ -3343,7 +3338,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { failed to resolve {}", name); if let Some((span, msg)) = err { - resolve_error(self, span, &ResolutionError::FailedToResolve(&*msg)) + resolve_error(self, span, ResolutionError::FailedToResolve(&*msg)) } return None; @@ -3548,7 +3543,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error(self, expr.span, - &ResolutionError::StructVariantUsedAsFunction(&*path_name)); + ResolutionError::StructVariantUsedAsFunction(&*path_name)); let msg = format!("did you mean to write: \ `{} {{ /* fields */ }}`?", @@ -3588,7 +3583,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, expr.span, - &ResolutionError::StructVariantUsedAsFunction( + ResolutionError::StructVariantUsedAsFunction( &*path_name) ); @@ -3620,7 +3615,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error( self, expr.span, - &ResolutionError::SelfNotAvailableInStaticMethod + ResolutionError::SelfNotAvailableInStaticMethod ); } else { let last_name = path.segments.last().unwrap().identifier.name; @@ -3647,7 +3642,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error(self, expr.span, - &ResolutionError::UnresolvedName(&*path_name, + ResolutionError::UnresolvedName(&*path_name, &*msg)); } } @@ -3668,7 +3663,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolve_error(self, path.span, - &ResolutionError::DoesNotNameAStruct( + ResolutionError::DoesNotNameAStruct( &*path_names_to_string(path, 0)) ); } @@ -3697,7 +3692,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { None => { resolve_error(self, expr.span, - &ResolutionError::UndeclaredLabel(&*token::get_ident(label))) + ResolutionError::UndeclaredLabel(&*token::get_ident(label))) } Some(DlDef(def @ DefLabel(_))) => { // Since this def is a label, it is never read. @@ -3845,7 +3840,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { BindByRef(..) => { resolve_error(self, pat.span, - &ResolutionError::CannotUseRefBindingModeWith(descr)); + ResolutionError::CannotUseRefBindingModeWith(descr)); } } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 080c99b07d6..e797da7b8f6 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -22,6 +22,7 @@ use ResolveResult; use Resolver; use UseLexicalScopeFlag; use {names_to_string, module_to_string}; +use {resolve_error, ResolutionError}; use build_reduced_graph; @@ -272,9 +273,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { Some((span, msg)) => (span, format!(". {}", msg)), None => (import_directive.span, String::new()) }; - ::resolve_error(self.resolver, + resolve_error(self.resolver, span, - &::ResolutionError::UnresolvedImport( + ResolutionError::UnresolvedImport( Some((&*import_path_to_string( &import_directive.module_path, import_directive.subclass), -- cgit 1.4.1-3-g733a5