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

+22-11
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

+2-2
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

+1-1
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

+1-1
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

+5-5
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

+1-1
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

+3-3
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

+2-2
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

+2-2
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

+1-1
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 {}

src/test/compile-fail/derived-errors/issue-31997.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn closure<F, T>(x: F) -> Result<T, ()>
2020
}
2121

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

src/test/compile-fail/does-nothing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
// except according to those terms.
1010

1111
fn main() { println!("doing"); this_does_nothing_what_the; println!("boing"); }
12-
//~^ ERROR unresolved value `this_does_nothing_what_the`
12+
//~^ ERROR cannot find value `this_does_nothing_what_the` in this scope

src/test/compile-fail/enums-pats-not-idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let a(1) = 13; //~ ERROR unresolved tuple struct/variant `a`
12+
let a(1) = 13; //~ ERROR cannot find tuple struct/variant `a` in this scope
1313
}

src/test/compile-fail/export.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
mod foo {
1212
pub fn x(y: isize) { log(debug, y); }
13-
//~^ ERROR unresolved function `log`
14-
//~| ERROR unresolved value `debug`
13+
//~^ ERROR cannot find function `log` in this scope
14+
//~| ERROR cannot find value `debug` in this scope
1515
fn z(y: isize) { log(debug, y); }
16-
//~^ ERROR unresolved function `log`
17-
//~| ERROR unresolved value `debug`
16+
//~^ ERROR cannot find function `log` in this scope
17+
//~| ERROR cannot find value `debug` in this scope
1818
}
1919

2020
fn main() { foo::z(10); } //~ ERROR function `z` is private

src/test/compile-fail/extern-with-type-bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "rust-intrinsic" {
2424

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

3030
fn main() {}

src/test/compile-fail/for-expn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
fn main() {
1414
// Odd formatting to make sure we get the right span.
1515
for t in &
16-
foo //~ ERROR unresolved value `foo`
16+
foo //~ ERROR cannot find value `foo` in this scope
1717
{
1818
}
1919
}

src/test/compile-fail/for-loop-hygiene.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
fn main() {
1515
for _ in 0..10 {
16-
iter.next(); //~ ERROR unresolved value `iter`
16+
iter.next(); //~ ERROR cannot find value `iter` in this scope
1717
}
1818
}

src/test/compile-fail/glob-resolve1.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ mod bar {
2929
fn foo<T>() {}
3030

3131
fn main() {
32-
fpriv(); //~ ERROR unresolved function `fpriv`
33-
epriv(); //~ ERROR unresolved function `epriv`
32+
fpriv(); //~ ERROR cannot find function `fpriv` in this scope
33+
epriv(); //~ ERROR cannot find function `epriv` in this scope
3434
B; //~ ERROR expected value, found enum `B`
35-
C; //~ ERROR unresolved value `C`
36-
import(); //~ ERROR: unresolved function `import`
35+
C; //~ ERROR cannot find value `C` in this scope
36+
import(); //~ ERROR: cannot find function `import` in this scope
3737

38-
foo::<A>(); //~ ERROR: unresolved type `A`
39-
foo::<C>(); //~ ERROR: unresolved type `C`
40-
foo::<D>(); //~ ERROR: unresolved type `D`
38+
foo::<A>(); //~ ERROR: cannot find type `A` in this scope
39+
foo::<C>(); //~ ERROR: cannot find type `C` in this scope
40+
foo::<D>(); //~ ERROR: cannot find type `D` in this scope
4141
}

src/test/compile-fail/import-glob-0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ mod module_of_many_things {
2121
fn main() {
2222
f1();
2323
f2();
24-
f999(); //~ ERROR unresolved function `f999`
24+
f999(); //~ ERROR cannot find function `f999` in this scope
2525
f4();
2626
}

src/test/compile-fail/import-glob-circular.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: unresolved
12-
1311
mod circ1 {
1412
pub use circ2::f2;
1513
pub fn f1() { println!("f1"); }
@@ -25,5 +23,5 @@ mod circ2 {
2523
mod test {
2624
use circ1::*;
2725

28-
fn test() { f1066(); }
26+
fn test() { f1066(); } //~ ERROR cannot find function `f1066` in this scope
2927
}

src/test/compile-fail/imports/duplicate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ mod e {
3232
}
3333

3434
mod f {
35-
pub use a::*; //~ NOTE `foo` could resolve to the name imported here
36-
pub use b::*; //~ NOTE `foo` could also resolve to the name imported here
35+
pub use a::*; //~ NOTE `foo` could refer to the name imported here
36+
pub use b::*; //~ NOTE `foo` could also refer to the name imported here
3737
}
3838

3939
mod g {
40-
pub use a::*; //~ NOTE `foo` could resolve to the name imported here
41-
pub use f::*; //~ NOTE `foo` could also resolve to the name imported here
40+
pub use a::*; //~ NOTE `foo` could refer to the name imported here
41+
pub use f::*; //~ NOTE `foo` could also refer to the name imported here
4242
}
4343

4444
fn main() {

src/test/compile-fail/imports/macro-paths.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ mod foo {
2121
}
2222

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

32-
pub mod baz { //~ NOTE could also resolve to the name defined here
32+
pub mod baz { //~ NOTE could also refer to the name defined here
3333
pub use two_macros::m;
3434
}
3535

3636
fn g() {
3737
baz::m! { //~ ERROR ambiguous
3838
//~| NOTE macro-expanded items do not shadow when used in a macro invocation path
39-
mod baz { pub use two_macros::m; } //~ NOTE could resolve to the name defined here
39+
mod baz { pub use two_macros::m; } //~ NOTE could refer to the name defined here
4040
//~^^^ NOTE in this expansion
4141
}
4242
}

src/test/compile-fail/imports/macros.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ mod m1 {
2424
}
2525

2626
mod m2 {
27-
use two_macros::*; //~ NOTE could also resolve
27+
use two_macros::*; //~ NOTE could also refer
2828
m! { //~ ERROR ambiguous
2929
//~| NOTE macro-expanded macro imports do not shadow
30-
use foo::m; //~ NOTE could resolve to the name imported here
30+
use foo::m; //~ NOTE could refer to the name imported here
3131
//~^^^ NOTE in this expansion
3232
}
3333
}
3434

3535
mod m3 {
36-
use two_macros::m; //~ NOTE could also resolve
36+
use two_macros::m; //~ NOTE could also refer
3737
fn f() {
3838
use two_macros::n as m; // This shadows the above import
3939
m!();
@@ -42,14 +42,14 @@ mod m3 {
4242
fn g() {
4343
m! { //~ ERROR ambiguous
4444
//~| NOTE macro-expanded macro imports do not shadow
45-
use two_macros::n as m; //~ NOTE could resolve to the name imported here
45+
use two_macros::n as m; //~ NOTE could refer to the name imported here
4646
//~^^^ NOTE in this expansion
4747
}
4848
}
4949
}
5050

5151
mod m4 {
52-
macro_rules! m { () => {} } //~ NOTE could resolve to the macro defined here
53-
use two_macros::m; //~ NOTE could also resolve to the macro imported here
52+
macro_rules! m { () => {} } //~ NOTE could refer to the macro defined here
53+
use two_macros::m; //~ NOTE could also refer to the macro imported here
5454
m!(); //~ ERROR ambiguous
5555
}

src/test/compile-fail/imports/rfc-1560-warning-cycle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ mod bar {
1717
struct Foo;
1818

1919
mod baz {
20-
use *; //~ NOTE `Foo` could resolve to the name imported here
21-
use bar::*; //~ NOTE `Foo` could also resolve to the name imported here
20+
use *; //~ NOTE `Foo` could refer to the name imported here
21+
use bar::*; //~ NOTE `Foo` could also refer to the name imported here
2222
fn f(_: Foo) {}
2323
//~^ WARN `Foo` is ambiguous
2424
//~| WARN hard error in a future release

src/test/compile-fail/issue-1476.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
println!("{}", x); //~ ERROR unresolved value `x`
12+
println!("{}", x); //~ ERROR cannot find value `x` in this scope
1313
}

src/test/compile-fail/issue-15167.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// macro f should not be able to inject a reference to 'n'.
1212

1313
macro_rules! f { () => (n) }
14-
//~^ ERROR unresolved value `n`
15-
//~| ERROR unresolved value `n`
16-
//~| ERROR unresolved value `n`
17-
//~| ERROR unresolved value `n`
14+
//~^ ERROR cannot find value `n` in this scope
15+
//~| ERROR cannot find value `n` in this scope
16+
//~| ERROR cannot find value `n` in this scope
17+
//~| ERROR cannot find value `n` in this scope
1818

1919
fn main() -> (){
2020
for n in 0..1 {

src/test/compile-fail/issue-18058.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// except according to those terms.
1010

1111
impl Undefined {}
12-
//~^ ERROR unresolved type `Undefined`
12+
//~^ ERROR cannot find type `Undefined` in this scope
1313

1414
fn main() {}

src/test/compile-fail/issue-19883.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait From<Src> {
1717
trait To: Sized {
1818
fn to<Dst: From<Self>>(self) ->
1919
<Dst as From<Self>>::Dst
20-
//~^ ERROR unresolved associated type `From::Dst`
20+
//~^ ERROR cannot find associated type `Dst` in trait `From`
2121
{
2222
From::from(self)
2323
}

src/test/compile-fail/issue-22037.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
trait A {
1212
type Output;
1313
fn a(&self) -> <Self as A>::X;
14-
//~^ ERROR unresolved associated type `A::X`
14+
//~^ ERROR cannot find associated type `X` in trait `A`
1515
}
1616

1717
impl A for u32 {

0 commit comments

Comments
 (0)