Skip to content

Commit

Permalink
resolve: Do not use "resolve"/"resolution" in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 12, 2017
1 parent 513d942 commit 2092682
Show file tree
Hide file tree
Showing 93 changed files with 304 additions and 294 deletions.
33 changes: 22 additions & 11 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2084,10 +2084,25 @@ impl<'a> Resolver<'a> {
let expected = source.descr_expected();
let path_str = names_to_string(path);
let code = source.error_code(def.is_some());
let base_msg = if let Some(def) = def {
format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str)
let (base_msg, fallback_label) = if let Some(def) = def {
(format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str),
format!("not a {}", expected))
} else {
format!("unresolved {} `{}`", expected, path_str)
let item_str = path[path.len() - 1];
let (mod_prefix, mod_str) = if path.len() == 1 {
(format!(""), format!("this scope"))
} else if path.len() == 2 && path[0].name == keywords::CrateRoot.name() {
(format!(""), format!("the crate root"))
} else {
let mod_path = &path[..path.len() - 1];
let mod_prefix = match this.resolve_path(mod_path, Some(TypeNS), None) {
PathResult::Module(module) => module.def(),
_ => None,
}.map_or(format!(""), |def| format!("{} ", def.kind_name()));
(mod_prefix, format!("`{}`", names_to_string(mod_path)))
};
(format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str),
format!("not found in {}", mod_str))
};
let mut err = this.session.struct_span_err_with_code(span, &base_msg, code);

Expand Down Expand Up @@ -2177,12 +2192,8 @@ impl<'a> Resolver<'a> {
}
}

// Fallback labels.
if def.is_some() {
err.span_label(span, &format!("not a {}", expected));
} else {
err.span_label(span, &format!("no resolution found"));
}
// Fallback label.
err.span_label(span, &fallback_label);
err
};
let report_errors = |this: &mut Self, def: Option<Def>| {
Expand Down Expand Up @@ -2983,8 +2994,8 @@ impl<'a> Resolver<'a> {
let participle = |binding: &NameBinding| {
if binding.is_import() { "imported" } else { "defined" }
};
let msg1 = format!("`{}` could resolve to the name {} here", name, participle(b1));
let msg2 = format!("`{}` could also resolve to the name {} here", name, participle(b2));
let msg1 = format!("`{}` could refer to the name {} here", name, participle(b1));
let msg2 = format!("`{}` could also refer to the name {} here", name, participle(b2));
let note = if !lexical && b1.is_glob_import() {
format!("consider adding an explicit import of `{}` to disambiguate", name)
} else if let Def::Macro(..) = b1.def() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ impl<'a> Resolver<'a> {
MacroBinding::Modern(binding) => (binding.span, "imported"),
MacroBinding::Legacy(binding) => (binding.span, "defined"),
};
let msg1 = format!("`{}` could resolve to the macro {} here", ident, participle);
let msg2 = format!("`{}` could also resolve to the macro imported here", ident);
let msg1 = format!("`{}` could refer to the macro {} here", ident, participle);
let msg2 = format!("`{}` could also refer to the macro imported here", ident);
self.session.struct_span_err(span, &format!("`{}` is ambiguous", ident))
.span_note(legacy_span, &msg1)
.span_note(resolution.span, &msg2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
extern crate macro_crate_test;

fn main() {
macro_crate_test::foo(); //~ ERROR unresolved function `macro_crate_test::foo`
macro_crate_test::foo(); //~ ERROR cannot find function `foo` in module `macro_crate_test`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail-fulldeps/qquote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ fn main() {

assert_eq!(pprust::expr_to_string(&*quote_expr!(&cx, 23)), "23");

let expr = quote_expr!(&cx, 2 - $abcd + 7); //~ ERROR unresolved value `abcd`
let expr = quote_expr!(&cx, 2 - $abcd + 7); //~ ERROR cannot find value `abcd` in this scope
assert_eq!(pprust::expr_to_string(&*expr), "2 - $abcd + 7");
}
10 changes: 5 additions & 5 deletions src/test/compile-fail/associated-path-shl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
// Check that associated paths starting with `<<` are successfully parsed.

fn main() {
let _: <<A>::B>::C; //~ ERROR unresolved type `A`
let _ = <<A>::B>::C; //~ ERROR unresolved type `A`
let <<A>::B>::C; //~ ERROR unresolved type `A`
let 0 ... <<A>::B>::C; //~ ERROR unresolved type `A`
let _: <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let _ = <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let 0 ... <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
//~^ ERROR only char and numeric types are allowed in range patterns
<<A>::B>::C; //~ ERROR unresolved type `A`
<<A>::B>::C; //~ ERROR cannot find type `A` in this scope
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/associated-types-eq-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait Foo {
}

fn foo2<I: Foo>(x: I) {
let _: A = x.boo(); //~ ERROR unresolved type `A`
let _: A = x.boo(); //~ ERROR cannot find type `A` in this scope
}

pub fn main() {}
6 changes: 3 additions & 3 deletions src/test/compile-fail/bad-expr-path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod m1 {}

fn main(arguments: Vec<String>) { //~ ERROR main function has wrong type
log(debug, m1::arguments);
//~^ ERROR unresolved function `log`
//~| ERROR unresolved value `debug`
//~| ERROR unresolved value `m1::arguments`
//~^ ERROR cannot find function `log` in this scope
//~| ERROR cannot find value `debug` in this scope
//~| ERROR cannot find value `arguments` in module `m1`
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/bad-expr-path2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod m1 {

fn main(arguments: Vec<String>) { //~ ERROR main function has wrong type
log(debug, m1::arguments);
//~^ ERROR unresolved function `log`
//~| ERROR unresolved value `debug`
//~^ ERROR cannot find function `log` in this scope
//~| ERROR cannot find value `debug` in this scope
//~| ERROR expected value, found module `m1::arguments`
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/class-missing-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ impl cat {
fn sleep(&self) { loop{} }
fn meow(&self) {
println!("Meow");
meows += 1; //~ ERROR unresolved value `meows`
sleep(); //~ ERROR unresolved function `sleep`
meows += 1; //~ ERROR cannot find value `meows` in this scope
sleep(); //~ ERROR cannot find function `sleep` in this scope
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/coherence-error-suppression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Foo for i8 {}
impl Foo for i16 {}
impl Foo for i32 {}
impl Foo for i64 {}
impl Foo for DoesNotExist {} //~ ERROR unresolved type `DoesNotExist`
impl Foo for DoesNotExist {} //~ ERROR cannot find type `DoesNotExist` in this scope
impl Foo for u8 {}
impl Foo for u16 {}
impl Foo for u32 {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/derived-errors/issue-31997.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn closure<F, T>(x: F) -> Result<T, ()>
}

fn foo() -> Result<(), ()> {
try!(closure(|| bar(0 as *mut _))); //~ ERROR unresolved function `bar`
try!(closure(|| bar(0 as *mut _))); //~ ERROR cannot find function `bar` in this scope
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/does-nothing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
// except according to those terms.

fn main() { println!("doing"); this_does_nothing_what_the; println!("boing"); }
//~^ ERROR unresolved value `this_does_nothing_what_the`
//~^ ERROR cannot find value `this_does_nothing_what_the` in this scope
2 changes: 1 addition & 1 deletion src/test/compile-fail/enums-pats-not-idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// except according to those terms.

fn main() {
let a(1) = 13; //~ ERROR unresolved tuple struct/variant `a`
let a(1) = 13; //~ ERROR cannot find tuple struct/variant `a` in this scope
}
8 changes: 4 additions & 4 deletions src/test/compile-fail/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

mod foo {
pub fn x(y: isize) { log(debug, y); }
//~^ ERROR unresolved function `log`
//~| ERROR unresolved value `debug`
//~^ ERROR cannot find function `log` in this scope
//~| ERROR cannot find value `debug` in this scope
fn z(y: isize) { log(debug, y); }
//~^ ERROR unresolved function `log`
//~| ERROR unresolved value `debug`
//~^ ERROR cannot find function `log` in this scope
//~| ERROR cannot find value `debug` in this scope
}

fn main() { foo::z(10); } //~ ERROR function `z` is private
2 changes: 1 addition & 1 deletion src/test/compile-fail/extern-with-type-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "rust-intrinsic" {

// Unresolved bounds should still error.
fn align_of<T: NoSuchTrait>() -> usize;
//~^ ERROR unresolved trait `NoSuchTrait`
//~^ ERROR cannot find trait `NoSuchTrait` in this scope
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/for-expn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
fn main() {
// Odd formatting to make sure we get the right span.
for t in &
foo //~ ERROR unresolved value `foo`
foo //~ ERROR cannot find value `foo` in this scope
{
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/for-loop-hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

fn main() {
for _ in 0..10 {
iter.next(); //~ ERROR unresolved value `iter`
iter.next(); //~ ERROR cannot find value `iter` in this scope
}
}
14 changes: 7 additions & 7 deletions src/test/compile-fail/glob-resolve1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ mod bar {
fn foo<T>() {}

fn main() {
fpriv(); //~ ERROR unresolved function `fpriv`
epriv(); //~ ERROR unresolved function `epriv`
fpriv(); //~ ERROR cannot find function `fpriv` in this scope
epriv(); //~ ERROR cannot find function `epriv` in this scope
B; //~ ERROR expected value, found enum `B`
C; //~ ERROR unresolved value `C`
import(); //~ ERROR: unresolved function `import`
C; //~ ERROR cannot find value `C` in this scope
import(); //~ ERROR: cannot find function `import` in this scope

foo::<A>(); //~ ERROR: unresolved type `A`
foo::<C>(); //~ ERROR: unresolved type `C`
foo::<D>(); //~ ERROR: unresolved type `D`
foo::<A>(); //~ ERROR: cannot find type `A` in this scope
foo::<C>(); //~ ERROR: cannot find type `C` in this scope
foo::<D>(); //~ ERROR: cannot find type `D` in this scope
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/import-glob-0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ mod module_of_many_things {
fn main() {
f1();
f2();
f999(); //~ ERROR unresolved function `f999`
f999(); //~ ERROR cannot find function `f999` in this scope
f4();
}
4 changes: 1 addition & 3 deletions src/test/compile-fail/import-glob-circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: unresolved

mod circ1 {
pub use circ2::f2;
pub fn f1() { println!("f1"); }
Expand All @@ -25,5 +23,5 @@ mod circ2 {
mod test {
use circ1::*;

fn test() { f1066(); }
fn test() { f1066(); } //~ ERROR cannot find function `f1066` in this scope
}
8 changes: 4 additions & 4 deletions src/test/compile-fail/imports/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ mod e {
}

mod f {
pub use a::*; //~ NOTE `foo` could resolve to the name imported here
pub use b::*; //~ NOTE `foo` could also resolve to the name imported here
pub use a::*; //~ NOTE `foo` could refer to the name imported here
pub use b::*; //~ NOTE `foo` could also refer to the name imported here
}

mod g {
pub use a::*; //~ NOTE `foo` could resolve to the name imported here
pub use f::*; //~ NOTE `foo` could also resolve to the name imported here
pub use a::*; //~ NOTE `foo` could refer to the name imported here
pub use f::*; //~ NOTE `foo` could also refer to the name imported here
}

fn main() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/imports/macro-paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ mod foo {
}

fn f() {
use foo::*; //~ NOTE could also resolve to the name imported here
use foo::*; //~ NOTE could also refer to the name imported here
bar::m! { //~ ERROR ambiguous
//~| NOTE macro-expanded items do not shadow when used in a macro invocation path
mod bar { pub use two_macros::m; } //~ NOTE could resolve to the name defined here
mod bar { pub use two_macros::m; } //~ NOTE could refer to the name defined here
//~^^^ NOTE in this expansion
}
}

pub mod baz { //~ NOTE could also resolve to the name defined here
pub mod baz { //~ NOTE could also refer to the name defined here
pub use two_macros::m;
}

fn g() {
baz::m! { //~ ERROR ambiguous
//~| NOTE macro-expanded items do not shadow when used in a macro invocation path
mod baz { pub use two_macros::m; } //~ NOTE could resolve to the name defined here
mod baz { pub use two_macros::m; } //~ NOTE could refer to the name defined here
//~^^^ NOTE in this expansion
}
}
12 changes: 6 additions & 6 deletions src/test/compile-fail/imports/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ mod m1 {
}

mod m2 {
use two_macros::*; //~ NOTE could also resolve
use two_macros::*; //~ NOTE could also refer
m! { //~ ERROR ambiguous
//~| NOTE macro-expanded macro imports do not shadow
use foo::m; //~ NOTE could resolve to the name imported here
use foo::m; //~ NOTE could refer to the name imported here
//~^^^ NOTE in this expansion
}
}

mod m3 {
use two_macros::m; //~ NOTE could also resolve
use two_macros::m; //~ NOTE could also refer
fn f() {
use two_macros::n as m; // This shadows the above import
m!();
Expand All @@ -42,14 +42,14 @@ mod m3 {
fn g() {
m! { //~ ERROR ambiguous
//~| NOTE macro-expanded macro imports do not shadow
use two_macros::n as m; //~ NOTE could resolve to the name imported here
use two_macros::n as m; //~ NOTE could refer to the name imported here
//~^^^ NOTE in this expansion
}
}
}

mod m4 {
macro_rules! m { () => {} } //~ NOTE could resolve to the macro defined here
use two_macros::m; //~ NOTE could also resolve to the macro imported here
macro_rules! m { () => {} } //~ NOTE could refer to the macro defined here
use two_macros::m; //~ NOTE could also refer to the macro imported here
m!(); //~ ERROR ambiguous
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/imports/rfc-1560-warning-cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ mod bar {
struct Foo;

mod baz {
use *; //~ NOTE `Foo` could resolve to the name imported here
use bar::*; //~ NOTE `Foo` could also resolve to the name imported here
use *; //~ NOTE `Foo` could refer to the name imported here
use bar::*; //~ NOTE `Foo` could also refer to the name imported here
fn f(_: Foo) {}
//~^ WARN `Foo` is ambiguous
//~| WARN hard error in a future release
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-1476.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// except according to those terms.

fn main() {
println!("{}", x); //~ ERROR unresolved value `x`
println!("{}", x); //~ ERROR cannot find value `x` in this scope
}
8 changes: 4 additions & 4 deletions src/test/compile-fail/issue-15167.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
// macro f should not be able to inject a reference to 'n'.

macro_rules! f { () => (n) }
//~^ ERROR unresolved value `n`
//~| ERROR unresolved value `n`
//~| ERROR unresolved value `n`
//~| ERROR unresolved value `n`
//~^ ERROR cannot find value `n` in this scope
//~| ERROR cannot find value `n` in this scope
//~| ERROR cannot find value `n` in this scope
//~| ERROR cannot find value `n` in this scope

fn main() -> (){
for n in 0..1 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-18058.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
// except according to those terms.

impl Undefined {}
//~^ ERROR unresolved type `Undefined`
//~^ ERROR cannot find type `Undefined` in this scope

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-19883.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait From<Src> {
trait To: Sized {
fn to<Dst: From<Self>>(self) ->
<Dst as From<Self>>::Dst
//~^ ERROR unresolved associated type `From::Dst`
//~^ ERROR cannot find associated type `Dst` in trait `From`
{
From::from(self)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-22037.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
trait A {
type Output;
fn a(&self) -> <Self as A>::X;
//~^ ERROR unresolved associated type `A::X`
//~^ ERROR cannot find associated type `X` in trait `A`
}

impl A for u32 {
Expand Down
Loading

0 comments on commit 2092682

Please sign in to comment.