Skip to content

Commit 1d5fb06

Browse files
committed
Auto merge of #38890 - petrochenkov:noresolve, r=nrc
resolve: Do not use "resolve"/"resolution" in error messages Use less jargon-y wording instead. `cannot find <struct> <S> in <this scope>` and `cannot find <struct> <S> in <module a::b>` are used for base messages (this also harmonizes nicely with "you can import it into scope" suggestions) and `not found in <this scope>` and `not found in <a::b>` are used for short labels in fall-back case. I tweaked some other diagnostics to avoid using "resolve" (see, e.g., `librustc_resolve/macros.rs`), but haven't touched messages for imports. Closes #38750 r? @nrc
2 parents b0c52c5 + 2092682 commit 1d5fb06

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
@@ -2090,10 +2090,25 @@ impl<'a> Resolver<'a> {
20902090
let expected = source.descr_expected();
20912091
let path_str = names_to_string(path);
20922092
let code = source.error_code(def.is_some());
2093-
let base_msg = if let Some(def) = def {
2094-
format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str)
2093+
let (base_msg, fallback_label) = if let Some(def) = def {
2094+
(format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str),
2095+
format!("not a {}", expected))
20952096
} else {
2096-
format!("unresolved {} `{}`", expected, path_str)
2097+
let item_str = path[path.len() - 1];
2098+
let (mod_prefix, mod_str) = if path.len() == 1 {
2099+
(format!(""), format!("this scope"))
2100+
} else if path.len() == 2 && path[0].name == keywords::CrateRoot.name() {
2101+
(format!(""), format!("the crate root"))
2102+
} else {
2103+
let mod_path = &path[..path.len() - 1];
2104+
let mod_prefix = match this.resolve_path(mod_path, Some(TypeNS), None) {
2105+
PathResult::Module(module) => module.def(),
2106+
_ => None,
2107+
}.map_or(format!(""), |def| format!("{} ", def.kind_name()));
2108+
(mod_prefix, format!("`{}`", names_to_string(mod_path)))
2109+
};
2110+
(format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str),
2111+
format!("not found in {}", mod_str))
20972112
};
20982113
let mut err = this.session.struct_span_err_with_code(span, &base_msg, code);
20992114

@@ -2183,12 +2198,8 @@ impl<'a> Resolver<'a> {
21832198
}
21842199
}
21852200

2186-
// Fallback labels.
2187-
if def.is_some() {
2188-
err.span_label(span, &format!("not a {}", expected));
2189-
} else {
2190-
err.span_label(span, &format!("no resolution found"));
2191-
}
2201+
// Fallback label.
2202+
err.span_label(span, &fallback_label);
21922203
err
21932204
};
21942205
let report_errors = |this: &mut Self, def: Option<Def>| {
@@ -2989,8 +3000,8 @@ impl<'a> Resolver<'a> {
29893000
let participle = |binding: &NameBinding| {
29903001
if binding.is_import() { "imported" } else { "defined" }
29913002
};
2992-
let msg1 = format!("`{}` could resolve to the name {} here", name, participle(b1));
2993-
let msg2 = format!("`{}` could also resolve to the name {} here", name, participle(b2));
3003+
let msg1 = format!("`{}` could refer to the name {} here", name, participle(b1));
3004+
let msg2 = format!("`{}` could also refer to the name {} here", name, participle(b2));
29943005
let note = if !lexical && b1.is_glob_import() {
29953006
format!("consider adding an explicit import of `{}` to disambiguate", name)
29963007
} 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)