Skip to content

Commit 2092682

Browse files
committed
resolve: Do not use "resolve"/"resolution" in error messages
1 parent 513d942 commit 2092682

File tree

93 files changed

+304
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+304
-294
lines changed

src/librustc_resolve/lib.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,10 +2084,25 @@ impl<'a> Resolver<'a> {
20842084
let expected = source.descr_expected();
20852085
let path_str = names_to_string(path);
20862086
let code = source.error_code(def.is_some());
2087-
let base_msg = if let Some(def) = def {
2088-
format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str)
2087+
let (base_msg, fallback_label) = if let Some(def) = def {
2088+
(format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str),
2089+
format!("not a {}", expected))
20892090
} else {
2090-
format!("unresolved {} `{}`", expected, path_str)
2091+
let item_str = path[path.len() - 1];
2092+
let (mod_prefix, mod_str) = if path.len() == 1 {
2093+
(format!(""), format!("this scope"))
2094+
} else if path.len() == 2 && path[0].name == keywords::CrateRoot.name() {
2095+
(format!(""), format!("the crate root"))
2096+
} else {
2097+
let mod_path = &path[..path.len() - 1];
2098+
let mod_prefix = match this.resolve_path(mod_path, Some(TypeNS), None) {
2099+
PathResult::Module(module) => module.def(),
2100+
_ => None,
2101+
}.map_or(format!(""), |def| format!("{} ", def.kind_name()));
2102+
(mod_prefix, format!("`{}`", names_to_string(mod_path)))
2103+
};
2104+
(format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str),
2105+
format!("not found in {}", mod_str))
20912106
};
20922107
let mut err = this.session.struct_span_err_with_code(span, &base_msg, code);
20932108

@@ -2177,12 +2192,8 @@ impl<'a> Resolver<'a> {
21772192
}
21782193
}
21792194

2180-
// Fallback labels.
2181-
if def.is_some() {
2182-
err.span_label(span, &format!("not a {}", expected));
2183-
} else {
2184-
err.span_label(span, &format!("no resolution found"));
2185-
}
2195+
// Fallback label.
2196+
err.span_label(span, &fallback_label);
21862197
err
21872198
};
21882199
let report_errors = |this: &mut Self, def: Option<Def>| {
@@ -2983,8 +2994,8 @@ impl<'a> Resolver<'a> {
29832994
let participle = |binding: &NameBinding| {
29842995
if binding.is_import() { "imported" } else { "defined" }
29852996
};
2986-
let msg1 = format!("`{}` could resolve to the name {} here", name, participle(b1));
2987-
let msg2 = format!("`{}` could also resolve to the name {} here", name, participle(b2));
2997+
let msg1 = format!("`{}` could refer to the name {} here", name, participle(b1));
2998+
let msg2 = format!("`{}` could also refer to the name {} here", name, participle(b2));
29882999
let note = if !lexical && b1.is_glob_import() {
29893000
format!("consider adding an explicit import of `{}` to disambiguate", name)
29903001
} else if let Def::Macro(..) = b1.def() {

src/librustc_resolve/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ impl<'a> Resolver<'a> {
380380
MacroBinding::Modern(binding) => (binding.span, "imported"),
381381
MacroBinding::Legacy(binding) => (binding.span, "defined"),
382382
};
383-
let msg1 = format!("`{}` could resolve to the macro {} here", ident, participle);
384-
let msg2 = format!("`{}` could also resolve to the macro imported here", ident);
383+
let msg1 = format!("`{}` could refer to the macro {} here", ident, participle);
384+
let msg2 = format!("`{}` could also refer to the macro imported here", ident);
385385
self.session.struct_span_err(span, &format!("`{}` is ambiguous", ident))
386386
.span_note(legacy_span, &msg1)
387387
.span_note(resolution.span, &msg2)

src/test/compile-fail-fulldeps/macro-crate-doesnt-resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
extern crate macro_crate_test;
1515

1616
fn main() {
17-
macro_crate_test::foo(); //~ ERROR unresolved function `macro_crate_test::foo`
17+
macro_crate_test::foo(); //~ ERROR cannot find function `foo` in module `macro_crate_test`
1818
}

src/test/compile-fail-fulldeps/qquote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ fn main() {
3939

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

42-
let expr = quote_expr!(&cx, 2 - $abcd + 7); //~ ERROR unresolved value `abcd`
42+
let expr = quote_expr!(&cx, 2 - $abcd + 7); //~ ERROR cannot find value `abcd` in this scope
4343
assert_eq!(pprust::expr_to_string(&*expr), "2 - $abcd + 7");
4444
}

src/test/compile-fail/associated-path-shl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// Check that associated paths starting with `<<` are successfully parsed.
1212

1313
fn main() {
14-
let _: <<A>::B>::C; //~ ERROR unresolved type `A`
15-
let _ = <<A>::B>::C; //~ ERROR unresolved type `A`
16-
let <<A>::B>::C; //~ ERROR unresolved type `A`
17-
let 0 ... <<A>::B>::C; //~ ERROR unresolved type `A`
14+
let _: <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
15+
let _ = <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
16+
let <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
17+
let 0 ... <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
1818
//~^ ERROR only char and numeric types are allowed in range patterns
19-
<<A>::B>::C; //~ ERROR unresolved type `A`
19+
<<A>::B>::C; //~ ERROR cannot find type `A` in this scope
2020
}

src/test/compile-fail/associated-types-eq-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub trait Foo {
1717
}
1818

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

2323
pub fn main() {}

src/test/compile-fail/bad-expr-path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod m1 {}
1212

1313
fn main(arguments: Vec<String>) { //~ ERROR main function has wrong type
1414
log(debug, m1::arguments);
15-
//~^ ERROR unresolved function `log`
16-
//~| ERROR unresolved value `debug`
17-
//~| ERROR unresolved value `m1::arguments`
15+
//~^ ERROR cannot find function `log` in this scope
16+
//~| ERROR cannot find value `debug` in this scope
17+
//~| ERROR cannot find value `arguments` in module `m1`
1818
}

src/test/compile-fail/bad-expr-path2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod m1 {
1414

1515
fn main(arguments: Vec<String>) { //~ ERROR main function has wrong type
1616
log(debug, m1::arguments);
17-
//~^ ERROR unresolved function `log`
18-
//~| ERROR unresolved value `debug`
17+
//~^ ERROR cannot find function `log` in this scope
18+
//~| ERROR cannot find value `debug` in this scope
1919
//~| ERROR expected value, found module `m1::arguments`
2020
}

src/test/compile-fail/class-missing-self.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ impl cat {
1616
fn sleep(&self) { loop{} }
1717
fn meow(&self) {
1818
println!("Meow");
19-
meows += 1; //~ ERROR unresolved value `meows`
20-
sleep(); //~ ERROR unresolved function `sleep`
19+
meows += 1; //~ ERROR cannot find value `meows` in this scope
20+
sleep(); //~ ERROR cannot find function `sleep` in this scope
2121
}
2222

2323
}

src/test/compile-fail/coherence-error-suppression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Foo for i8 {}
1616
impl Foo for i16 {}
1717
impl Foo for i32 {}
1818
impl Foo for i64 {}
19-
impl Foo for DoesNotExist {} //~ ERROR unresolved type `DoesNotExist`
19+
impl Foo for DoesNotExist {} //~ ERROR cannot find type `DoesNotExist` in this scope
2020
impl Foo for u8 {}
2121
impl Foo for u16 {}
2222
impl Foo for u32 {}

0 commit comments

Comments
 (0)