diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 299a8c0299d0edfce01a9aeaf7191156a859fd8e..5f4244caa629c508e619beee9ee3ad4dedddd95c 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1714,9 +1714,10 @@ fn resolve_item(&mut self, item: &Item) { match self.resolve_crate_relative_path(prefix.span, &prefix.segments, TypeNS) { - Some(def) => + Ok(def) => self.record_def(item.id, PathResolution::new(def, 0)), - None => { + Err(true) => self.record_def(item.id, err_path_resolution()), + Err(false) => { resolve_error(self, prefix.span, ResolutionError::FailedToResolve( @@ -1835,7 +1836,7 @@ fn resolve_trait_reference(&mut self, trait_path: &Path, path_depth: usize) -> Result { - if let Some(path_res) = self.resolve_path(id, trait_path, path_depth, TypeNS) { + self.resolve_path(id, trait_path, path_depth, TypeNS).and_then(|path_res| { if let Def::Trait(_) = path_res.base_def { debug!("(resolving trait) found trait def: {:?}", path_res); Ok(path_res) @@ -1855,9 +1856,10 @@ fn resolve_trait_reference(&mut self, } } err.emit(); - Err(()) + Err(true) } - } else { + }).map_err(|error_reported| { + if error_reported { return } // find possible candidates let trait_name = trait_path.segments.last().unwrap().identifier.name; @@ -1880,8 +1882,7 @@ fn resolve_trait_reference(&mut self, ); resolve_error(self, trait_path.span, error); - Err(()) - } + }) } fn resolve_generics(&mut self, generics: &Generics) { @@ -1890,15 +1891,18 @@ fn resolve_generics(&mut self, generics: &Generics) { &hir::WherePredicate::BoundPredicate(_) | &hir::WherePredicate::RegionPredicate(_) => {} &hir::WherePredicate::EqPredicate(ref eq_pred) => { - let path_res = self.resolve_path(eq_pred.id, &eq_pred.path, 0, TypeNS); - if let Some(PathResolution { base_def: Def::TyParam(..), .. }) = path_res { - self.record_def(eq_pred.id, path_res.unwrap()); - } else { - resolve_error(self, - eq_pred.span, - ResolutionError::UndeclaredAssociatedType); + self.resolve_path(eq_pred.id, &eq_pred.path, 0, TypeNS).and_then(|path_res| { + if let PathResolution { base_def: Def::TyParam(..), .. } = path_res { + Ok(self.record_def(eq_pred.id, path_res)) + } else { + Err(false) + } + }).map_err(|error_reported| { self.record_def(eq_pred.id, err_path_resolution()); - } + if error_reported { return } + let error_variant = ResolutionError::UndeclaredAssociatedType; + resolve_error(self, eq_pred.span, error_variant); + }).unwrap_or(()); } } } @@ -2168,21 +2172,18 @@ fn resolve_type(&mut self, ty: &Ty) { // This is a path in the type namespace. Walk through scopes // looking for it. - match resolution { - Some(def) => { - // Write the result into the def map. - debug!("(resolving type) writing resolution for `{}` (id {}) = {:?}", - path_names_to_string(path, 0), - ty.id, - def); - self.record_def(ty.id, def); - } - None => { - self.record_def(ty.id, err_path_resolution()); - - // Keep reporting some errors even if they're ignored above. - self.resolve_path(ty.id, path, 0, TypeNS); + if let Some(def) = resolution { + // Write the result into the def map. + debug!("(resolving type) writing resolution for `{}` (id {}) = {:?}", + path_names_to_string(path, 0), ty.id, def); + self.record_def(ty.id, def); + } else { + self.record_def(ty.id, err_path_resolution()); + // Keep reporting some errors even if they're ignored above. + if let Err(true) = self.resolve_path(ty.id, path, 0, TypeNS) { + // `resolve_path` already reported the error + } else { let kind = if maybe_qself.is_some() { "associated type" } else { @@ -2481,11 +2482,11 @@ fn resolve_pattern(&mut self, PatKind::Struct(ref path, _, _) => { match self.resolve_path(pat_id, path, 0, TypeNS) { - Some(definition) => { + Ok(definition) => { self.record_def(pattern.id, definition); } - result => { - debug!("(resolving pattern) didn't find struct def: {:?}", result); + Err(true) => self.record_def(pattern.id, err_path_resolution()), + Err(false) => { resolve_error( self, path.span, @@ -2552,14 +2553,14 @@ fn resolve_possibly_assoc_item(&mut self, } let mut resolution = self.with_no_errors(|this| { - this.resolve_path(id, path, 0, namespace) + this.resolve_path(id, path, 0, namespace).ok() }); for depth in 1..max_assoc_types { if resolution.is_some() { break; } self.with_no_errors(|this| { - resolution = this.resolve_path(id, path, depth, TypeNS); + resolution = this.resolve_path(id, path, depth, TypeNS).ok(); }); } if let Some(Def::Mod(_)) = resolution.map(|r| r.base_def) { @@ -2572,7 +2573,7 @@ fn resolve_possibly_assoc_item(&mut self, /// Skips `path_depth` trailing segments, which is also reflected in the /// returned value. See `hir::def::PathResolution` for more info. fn resolve_path(&mut self, id: NodeId, path: &Path, path_depth: usize, namespace: Namespace) - -> Option { + -> Result { let span = path.span; let segments = &path.segments[..path.segments.len() - path_depth]; @@ -2611,14 +2612,14 @@ fn resolve_path(&mut self, id: NodeId, path: &Path, path_depth: usize, namespace // // Such behavior is required for backward compatibility. // The same fallback is used when `a` resolves to nothing. - let unqualified_def = resolve_identifier_with_fallback(self, true); - return unqualified_def.and_then(|def| self.adjust_local_def(def, span)).map(mk_res); + let def = resolve_identifier_with_fallback(self, true).ok_or(false); + return def.and_then(|def| self.adjust_local_def(def, span).ok_or(true)).map(mk_res); } let unqualified_def = resolve_identifier_with_fallback(self, false); let def = self.resolve_module_relative_path(span, segments, namespace); match (def, unqualified_def) { - (Some(d), Some(ref ud)) if d == ud.def => { + (Ok(d), Some(ref ud)) if d == ud.def => { self.session .add_lint(lint::builtin::UNUSED_QUALIFICATIONS, id, @@ -2739,7 +2740,7 @@ fn resolve_module_relative_path(&mut self, span: Span, segments: &[hir::PathSegment], namespace: Namespace) - -> Option { + -> Result { let module_path = segments.split_last() .unwrap() .1 @@ -2760,9 +2761,9 @@ fn resolve_module_relative_path(&mut self, }; resolve_error(self, span, ResolutionError::FailedToResolve(&msg)); - return None; + return Err(true); } - Indeterminate => return None, + Indeterminate => return Err(false), Success(resulting_module) => { containing_module = resulting_module; } @@ -2773,7 +2774,7 @@ fn resolve_module_relative_path(&mut self, result.success().map(|binding| { self.check_privacy(containing_module, name, binding, span); binding.def().unwrap() - }) + }).ok_or(false) } /// Invariant: This must be called only during main resolution, not during @@ -2782,7 +2783,7 @@ fn resolve_crate_relative_path(&mut self, span: Span, segments: &[hir::PathSegment], namespace: Namespace) - -> Option { + -> Result { let module_path = segments.split_last() .unwrap() .1 @@ -2808,10 +2809,10 @@ fn resolve_crate_relative_path(&mut self, }; resolve_error(self, span, ResolutionError::FailedToResolve(&msg)); - return None; + return Err(true); } - Indeterminate => return None, + Indeterminate => return Err(false), Success(resulting_module) => { containing_module = resulting_module; @@ -2823,7 +2824,7 @@ fn resolve_crate_relative_path(&mut self, result.success().map(|binding| { self.check_privacy(containing_module, name, binding, span); binding.def().unwrap() - }) + }).ok_or(false) } fn with_no_errors(&mut self, f: F) -> T @@ -3038,25 +3039,26 @@ fn resolve_expr(&mut self, expr: &Expr) { }); self.record_def(expr.id, err_path_resolution()); - match type_res.map(|r| r.base_def) { - Some(Def::Struct(..)) => { - let mut err = resolve_struct_error(self, - expr.span, - ResolutionError::StructVariantUsedAsFunction(&path_name)); - - let msg = format!("did you mean to write: `{} {{ /* fields */ }}`?", - path_name); - if self.emit_errors { - err.fileline_help(expr.span, &msg); - } else { - err.span_help(expr.span, &msg); - } - err.emit(); - } - _ => { - // Keep reporting some errors even if they're ignored above. - self.resolve_path(expr.id, path, 0, ValueNS); + if let Ok(Def::Struct(..)) = type_res.map(|r| r.base_def) { + let error_variant = + ResolutionError::StructVariantUsedAsFunction(&path_name); + let mut err = resolve_struct_error(self, expr.span, error_variant); + + let msg = format!("did you mean to write: `{} {{ /* fields */ }}`?", + path_name); + + if self.emit_errors { + err.fileline_help(expr.span, &msg); + } else { + err.span_help(expr.span, &msg); + } + err.emit(); + } else { + // Keep reporting some errors even if they're ignored above. + if let Err(true) = self.resolve_path(expr.id, path, 0, ValueNS) { + // `resolve_path` already reported the error + } else { let mut method_scope = false; self.value_ribs.iter().rev().all(|rib| { method_scope = match rib.kind { @@ -3130,8 +3132,9 @@ fn resolve_expr(&mut self, expr: &Expr) { // check to ensure that the path is actually a structure; that // is checked later during typeck. match self.resolve_path(expr.id, path, 0, TypeNS) { - Some(definition) => self.record_def(expr.id, definition), - None => { + Ok(definition) => self.record_def(expr.id, definition), + Err(true) => self.record_def(expr.id, err_path_resolution()), + Err(false) => { debug!("(resolving expression) didn't find struct def",); resolve_error(self, diff --git a/src/test/compile-fail-fulldeps/macro-crate-doesnt-resolve.rs b/src/test/compile-fail-fulldeps/macro-crate-doesnt-resolve.rs index 8ac03606720e4fbf8e6ec860aa40bfbb6a26767a..1fbde00a3dfdecf2b7377ad415cbd78d29a64bf0 100644 --- a/src/test/compile-fail-fulldeps/macro-crate-doesnt-resolve.rs +++ b/src/test/compile-fail-fulldeps/macro-crate-doesnt-resolve.rs @@ -16,5 +16,4 @@ fn main() { macro_crate_test::foo(); //~^ ERROR failed to resolve. Use of undeclared type or module `macro_crate_test` - //~^^ ERROR unresolved name `macro_crate_test::foo` } diff --git a/src/test/compile-fail/bad-module.rs b/src/test/compile-fail/bad-module.rs index edc118cb0399b1f51851b60af703579e41998c00..0cd3a8853185fade135c0916d475447724a754d7 100644 --- a/src/test/compile-fail/bad-module.rs +++ b/src/test/compile-fail/bad-module.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: unresolved name +// error-pattern: failed to resolve. Use of undeclared type or module `thing` fn main() { let foo = thing::len(Vec::new()); } diff --git a/src/test/compile-fail/bad-type-env-capture.rs b/src/test/compile-fail/bad-type-env-capture.rs index a3139905244c6aa4ec9a0216a31164bacaf1bd17..c1547dd82b3b2e5a83c6904a2d68a2a836b33abb 100644 --- a/src/test/compile-fail/bad-type-env-capture.rs +++ b/src/test/compile-fail/bad-type-env-capture.rs @@ -10,6 +10,5 @@ fn foo() { fn bar(b: T) { } //~ ERROR can't use type parameters from outer - //~^ ERROR type name `T` is undefined or not in scope } fn main() { } diff --git a/src/test/compile-fail/export-fully-qualified.rs b/src/test/compile-fail/export-fully-qualified.rs index 2ba2ef1c05a044b36c9cb55d4830fab90ea8efc8..166ef7ab87fcd1d2297dc0eda5e21f4c16424c48 100644 --- a/src/test/compile-fail/export-fully-qualified.rs +++ b/src/test/compile-fail/export-fully-qualified.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: unresolved name +// error-pattern: failed to resolve. Use of undeclared type or module `foo` // In this test baz isn't resolved when called as foo.baz even though // it's called from inside foo. This is somewhat surprising and may diff --git a/src/test/compile-fail/export2.rs b/src/test/compile-fail/export2.rs index 6104c02c90a03332145a30a132a4822675ee5e8a..f7b1400aa45acf87e7c8a60bea566b0d75527013 100644 --- a/src/test/compile-fail/export2.rs +++ b/src/test/compile-fail/export2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: unresolved name +// error-pattern: failed to resolve. Use of undeclared type or module `bar` mod foo { pub fn x() { bar::x(); } diff --git a/src/test/compile-fail/inner-static-type-parameter.rs b/src/test/compile-fail/inner-static-type-parameter.rs index 6fcda66486b78018ef3fe61b08c2d0270ec6e89b..a6a331984583675c99a942ea23f96347bc95f091 100644 --- a/src/test/compile-fail/inner-static-type-parameter.rs +++ b/src/test/compile-fail/inner-static-type-parameter.rs @@ -15,7 +15,6 @@ enum Bar { What } //~ ERROR parameter `T` is never used fn foo() { static a: Bar = Bar::What; //~^ ERROR cannot use an outer type parameter in this context - //~| ERROR type name `T` is undefined or not in scope } fn main() { diff --git a/src/test/compile-fail/issue-12796.rs b/src/test/compile-fail/issue-12796.rs index 33fbdce4ee25a2b50fd3a4474bc31c840ccd7879..0c3c82a99f28f4f38a6ba45caea71226fadad3de 100644 --- a/src/test/compile-fail/issue-12796.rs +++ b/src/test/compile-fail/issue-12796.rs @@ -12,7 +12,6 @@ trait Trait { fn outer(&self) { fn inner(_: &Self) { //~^ ERROR can't use type parameters from outer function - //~^^ ERROR use of `Self` outside of an impl or trait } } } diff --git a/src/test/compile-fail/issue-3021-b.rs b/src/test/compile-fail/issue-3021-b.rs index 5c539cd739cefe51df9d933a85ef28098dcc15e6..2b0a24cfdb35f9e3bbabf3baaa3a5f7a0904f21a 100644 --- a/src/test/compile-fail/issue-3021-b.rs +++ b/src/test/compile-fail/issue-3021-b.rs @@ -17,7 +17,6 @@ struct siphash { impl siphash { pub fn reset(&mut self) { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment - //~^ ERROR unresolved name `k0` } } } diff --git a/src/test/compile-fail/issue-3021-c.rs b/src/test/compile-fail/issue-3021-c.rs index 03473bd44cc1bcce136af6bdf35c25260068f068..635006a3b4dad62af9afe2611bd533bf5578580c 100644 --- a/src/test/compile-fail/issue-3021-c.rs +++ b/src/test/compile-fail/issue-3021-c.rs @@ -13,8 +13,6 @@ fn siphash() { trait t { fn g(&self, x: T) -> T; //~ ERROR can't use type parameters from outer function; try using //~^ ERROR can't use type parameters from outer function; try using - //~^^ ERROR type name `T` is undefined or not in scope - //~^^^ ERROR type name `T` is undefined or not in scope } } diff --git a/src/test/compile-fail/issue-3021-d.rs b/src/test/compile-fail/issue-3021-d.rs index ecc8ac34ecf2ba5f45cc5cf2c47805a385eed093..c23e12e713aad797157fa2fc7e897aeef6997ff4 100644 --- a/src/test/compile-fail/issue-3021-d.rs +++ b/src/test/compile-fail/issue-3021-d.rs @@ -29,9 +29,7 @@ fn mk_result(st : &SipState) -> u64 { impl siphash for SipState { fn reset(&self) { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment - //~^ ERROR unresolved name `k0` self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR can't capture dynamic environment - //~^ ERROR unresolved name `k1` } fn result(&self) -> u64 { return mk_result(self); } } diff --git a/src/test/compile-fail/issue-3021.rs b/src/test/compile-fail/issue-3021.rs index 7cf772b0728795334680a6b3ff01c68e27447623..f93a333d2aea7b8f37ed1b5f37915bbb641f6d89 100644 --- a/src/test/compile-fail/issue-3021.rs +++ b/src/test/compile-fail/issue-3021.rs @@ -20,7 +20,6 @@ struct SipState { impl SipHash for SipState { fn reset(&self) { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment - //~^ ERROR unresolved name `k0` } } panic!(); diff --git a/src/test/compile-fail/issue-3214.rs b/src/test/compile-fail/issue-3214.rs index 4f955df82051f535df746e4147542fdf0c3cbecb..d3b932fbc53efa5710b0a0843e25809f91148f4a 100644 --- a/src/test/compile-fail/issue-3214.rs +++ b/src/test/compile-fail/issue-3214.rs @@ -11,7 +11,6 @@ fn foo() { struct foo { x: T, //~ ERROR can't use type parameters from outer function; - //~^ ERROR type name `T` is undefined or not in scope } impl Drop for foo { diff --git a/src/test/compile-fail/issue-3521-2.rs b/src/test/compile-fail/issue-3521-2.rs index ad5bc4e445c9839b7ebc41064ef684f460087340..6cd2c02c417ea8ed5f8aacfd19367259ed7b72b5 100644 --- a/src/test/compile-fail/issue-3521-2.rs +++ b/src/test/compile-fail/issue-3521-2.rs @@ -13,7 +13,6 @@ fn main() { static y: isize = foo + 1; //~^ ERROR attempt to use a non-constant value in a constant - //~| ERROR unresolved name `foo` println!("{}", y); } diff --git a/src/test/compile-fail/issue-3521.rs b/src/test/compile-fail/issue-3521.rs index 34cd8cae2de32a64a3255c45b05354428b7c5910..52375ef281ace24513c5f70d46257acd5512d401 100644 --- a/src/test/compile-fail/issue-3521.rs +++ b/src/test/compile-fail/issue-3521.rs @@ -15,8 +15,7 @@ fn main() { enum Stuff { Bar = foo //~^ ERROR attempt to use a non-constant value in a constant - //~| ERROR unresolved name `foo` - //~^^^ ERROR constant evaluation error: non-constant path in constant expression + //~^^ ERROR constant evaluation error: non-constant path in constant expression } println!("{}", Stuff::Bar); diff --git a/src/test/compile-fail/issue-3668-2.rs b/src/test/compile-fail/issue-3668-2.rs index a09c8090de06de5716e718d3d33e6291f7edfaf9..16fb2f68133f291f9519dcb591330338e28684d8 100644 --- a/src/test/compile-fail/issue-3668-2.rs +++ b/src/test/compile-fail/issue-3668-2.rs @@ -11,7 +11,6 @@ fn f(x:isize) { static child: isize = x + 1; //~^ ERROR attempt to use a non-constant value in a constant - //~| ERROR unresolved name `x` } fn main() {} diff --git a/src/test/compile-fail/issue-3668.rs b/src/test/compile-fail/issue-3668.rs index 9b7476244f0d26a19e0d91639fea3c306c20406f..9c31dc1e38ef8ff312193b105a73e9346e9d0153 100644 --- a/src/test/compile-fail/issue-3668.rs +++ b/src/test/compile-fail/issue-3668.rs @@ -17,7 +17,6 @@ impl PTrait for P { fn getChildOption(&self) -> Option> { static childVal: Box

= self.child.get(); //~^ ERROR attempt to use a non-constant value in a constant - //~| ERROR unresolved name `self` panic!(); } } diff --git a/src/test/compile-fail/issue-5997-enum.rs b/src/test/compile-fail/issue-5997-enum.rs index 20d239c6ae046540009c5215f44c7d415be7c04a..463fdaa106926a898579d7335aba455180227b17 100644 --- a/src/test/compile-fail/issue-5997-enum.rs +++ b/src/test/compile-fail/issue-5997-enum.rs @@ -11,7 +11,6 @@ fn f() -> bool { enum E { V(Z) } //~^ ERROR can't use type parameters from outer function - //~^^ ERROR type name `Z` is undefined or not in scope true } diff --git a/src/test/compile-fail/issue-5997-struct.rs b/src/test/compile-fail/issue-5997-struct.rs index 40be2f04cb43ca5daace5380ff219a76ee9936b2..e9cfafc98df0ef47fffdfe2768cd6353e7071555 100644 --- a/src/test/compile-fail/issue-5997-struct.rs +++ b/src/test/compile-fail/issue-5997-struct.rs @@ -9,8 +9,7 @@ // except according to those terms. fn f() -> bool { - struct S(T); //~ ERROR type name `T` is undefined or not in scope - //~^ ERROR can't use type parameters from outer function; try using + struct S(T); //~ ERROR can't use type parameters from outer function; try using true } diff --git a/src/test/compile-fail/issue-6642.rs b/src/test/compile-fail/issue-6642.rs index 2c1809d4d4886f45c25a7f5ff87a679d10eeaa17..1fe10ba7a27bba10bc7d762c6671b85a4452cb03 100644 --- a/src/test/compile-fail/issue-6642.rs +++ b/src/test/compile-fail/issue-6642.rs @@ -13,7 +13,6 @@ impl A { fn m(&self) { fn x() { self.m() //~ ERROR can't capture dynamic environment in a fn item - //~^ ERROR unresolved name `self` } } } diff --git a/src/test/compile-fail/macro-inner-attributes.rs b/src/test/compile-fail/macro-inner-attributes.rs index abf0ed420e7a26c59cf03009f84cdcaae0e8364d..1111b21d4550c14c3ef2fbae02ae702a562dd9ed 100644 --- a/src/test/compile-fail/macro-inner-attributes.rs +++ b/src/test/compile-fail/macro-inner-attributes.rs @@ -26,6 +26,5 @@ fn main() { a::bar(); //~^ ERROR failed to resolve. Use of undeclared type or module `a` - //~^^ ERROR unresolved name `a::bar` b::bar(); } diff --git a/src/test/compile-fail/no-link.rs b/src/test/compile-fail/no-link.rs index a9c2b6a942c658dab4e09a84e3752eba44cf51db..957b6cda55311b79c927ee3ec5de589e5085cc92 100644 --- a/src/test/compile-fail/no-link.rs +++ b/src/test/compile-fail/no-link.rs @@ -14,6 +14,5 @@ fn main() { unsafe { libc::abs(0); //~ ERROR Use of undeclared type or module `libc` - //~^ ERROR unresolved name `libc::abs` } } diff --git a/src/test/compile-fail/resolve-type-param-in-item-in-trait.rs b/src/test/compile-fail/resolve-type-param-in-item-in-trait.rs index 92134ecde91aa56c9ba3bccb0281128e5a98f6f6..30ff1ed0e26f7a2a637a253e7512c7ac73a62048 100644 --- a/src/test/compile-fail/resolve-type-param-in-item-in-trait.rs +++ b/src/test/compile-fail/resolve-type-param-in-item-in-trait.rs @@ -18,7 +18,6 @@ enum Foo { //~^ ERROR parameter `B` is never used Variance(A) //~^ ERROR can't use type parameters from outer function - //~^^ ERROR type name `A` is undefined or not in scope } } } @@ -27,8 +26,7 @@ trait TraitB { fn outer(self) { struct Foo(A); //~^ ERROR can't use type parameters from outer function - //~^^ ERROR type name `A` is undefined or not in scope - //~^^^ ERROR parameter `B` is never used + //~^^ ERROR parameter `B` is never used } } @@ -36,8 +34,7 @@ trait TraitC { fn outer(self) { struct Foo { a: A } //~^ ERROR can't use type parameters from outer function - //~^^ ERROR type name `A` is undefined or not in scope - //~^^^ ERROR parameter `B` is never used + //~^^ ERROR parameter `B` is never used } } @@ -45,7 +42,6 @@ trait TraitD { fn outer(self) { fn foo(a: A) { } //~^ ERROR can't use type parameters from outer function - //~^^ ERROR type name `A` is undefined or not in scope } }