Skip to content

Commit 9f88d75

Browse files
committed
reword "possible candidate" import suggestion
1 parent 97f3eee commit 9f88d75

Some content is hidden

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

46 files changed

+112
-106
lines changed

src/librustc_resolve/diagnostics.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl TypoSuggestion {
4747
/// A free importable items suggested in case of resolution failure.
4848
crate struct ImportSuggestion {
4949
pub did: Option<DefId>,
50+
pub descr: &'static str,
5051
pub path: Path,
5152
}
5253

@@ -652,7 +653,7 @@ impl<'a> Resolver<'a> {
652653
Res::Def(DefKind::Ctor(..), did) => this.parent(did),
653654
_ => res.opt_def_id(),
654655
};
655-
candidates.push(ImportSuggestion { did, path });
656+
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
656657
}
657658
}
658659
}
@@ -1445,29 +1446,31 @@ fn find_span_immediately_after_crate_name(
14451446
crate fn show_candidates(
14461447
err: &mut DiagnosticBuilder<'_>,
14471448
// This is `None` if all placement locations are inside expansions
1448-
span: Option<Span>,
1449+
use_placement_span: Option<Span>,
14491450
candidates: &[ImportSuggestion],
14501451
better: bool,
14511452
found_use: bool,
14521453
) {
14531454
if candidates.is_empty() {
14541455
return;
14551456
}
1457+
14561458
// we want consistent results across executions, but candidates are produced
14571459
// by iterating through a hash map, so make sure they are ordered:
14581460
let mut path_strings: Vec<_> =
14591461
candidates.iter().map(|c| path_names_to_string(&c.path)).collect();
14601462
path_strings.sort();
14611463
path_strings.dedup();
14621464

1463-
let better = if better { "better " } else { "" };
1464-
let msg_diff = match path_strings.len() {
1465-
1 => " is found in another module, you can import it",
1466-
_ => "s are found in other modules, you can import them",
1465+
let (determiner, kind) = if candidates.len() == 1 {
1466+
("this", candidates[0].descr)
1467+
} else {
1468+
("one of these", "items")
14671469
};
1468-
let msg = format!("possible {}candidate{} into scope", better, msg_diff);
1470+
let instead = if better { " instead" } else { "" };
1471+
let msg = format!("consider importing {} {}{}", determiner, kind, instead);
14691472

1470-
if let Some(span) = span {
1473+
if let Some(span) = use_placement_span {
14711474
for candidate in &mut path_strings {
14721475
// produce an additional newline to separate the new use statement
14731476
// from the directly following item.

src/librustc_resolve/late/diagnostics.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,10 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
873873
let module_def_id = module.def_id().unwrap();
874874
if module_def_id == def_id {
875875
let path = Path { span: name_binding.span, segments: path_segments };
876-
result = Some((module, ImportSuggestion { did: Some(def_id), path }));
876+
result = Some((
877+
module,
878+
ImportSuggestion { did: Some(def_id), descr: "module", path },
879+
));
877880
} else {
878881
// add the module to the lookup
879882
if seen_modules.insert(module_def_id) {

src/test/ui/class-missing-self.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0425]: cannot find function `sleep` in this scope
1010
LL | sleep();
1111
| ^^^^^ not found in this scope
1212
|
13-
help: possible candidate is found in another module, you can import it into scope
13+
help: consider importing this function
1414
|
1515
LL | use std::thread::sleep;
1616
|

src/test/ui/crate-in-paths.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find value `Foo` in this scope
44
LL | Foo;
55
| ^^^ not found in this scope
66
|
7-
help: possible candidate is found in another module, you can import it into scope
7+
help: consider importing this unit struct
88
|
99
LL | use crate::bar::Foo;
1010
|

src/test/ui/did_you_mean/issue-56028-there-is-an-enum-variant.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error[E0425]: cannot find value `Set` in this scope
2222
LL | fn setup() -> Set { Set }
2323
| ^^^ not found in this scope
2424
|
25-
help: possible candidates are found in other modules, you can import them into scope
25+
help: consider importing one of these items
2626
|
2727
LL | use AffixHeart::Set;
2828
|

src/test/ui/glob-resolve1.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find function `fpriv` in this scope
44
LL | fpriv();
55
| ^^^^^ not found in this scope
66
|
7-
help: possible candidate is found in another module, you can import it into scope
7+
help: consider importing this function
88
|
99
LL | use bar::fpriv;
1010
|
@@ -15,7 +15,7 @@ error[E0425]: cannot find function `epriv` in this scope
1515
LL | epriv();
1616
| ^^^^^ not found in this scope
1717
|
18-
help: possible candidate is found in another module, you can import it into scope
18+
help: consider importing this function
1919
|
2020
LL | use bar::epriv;
2121
|
@@ -32,7 +32,7 @@ error[E0425]: cannot find value `C` in this scope
3232
LL | C;
3333
| ^ not found in this scope
3434
|
35-
help: possible candidate is found in another module, you can import it into scope
35+
help: consider importing this unit struct
3636
|
3737
LL | use bar::C;
3838
|
@@ -56,7 +56,7 @@ help: an enum with a similar name exists
5656
|
5757
LL | foo::<B>();
5858
| ^
59-
help: possible candidate is found in another module, you can import it into scope
59+
help: consider importing this enum
6060
|
6161
LL | use bar::A;
6262
|
@@ -74,7 +74,7 @@ help: an enum with a similar name exists
7474
|
7575
LL | foo::<B>();
7676
| ^
77-
help: possible candidate is found in another module, you can import it into scope
77+
help: consider importing this struct
7878
|
7979
LL | use bar::C;
8080
|
@@ -92,7 +92,7 @@ help: an enum with a similar name exists
9292
|
9393
LL | foo::<B>();
9494
| ^
95-
help: possible candidate is found in another module, you can import it into scope
95+
help: consider importing this type alias
9696
|
9797
LL | use bar::D;
9898
|

src/test/ui/hygiene/globs.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find function `f` in this scope
44
LL | f();
55
| ^ not found in this scope
66
|
7-
help: possible candidate is found in another module, you can import it into scope
7+
help: consider importing one of these items
88
|
99
LL | use foo::f;
1010
|
@@ -23,7 +23,7 @@ LL | | }
2323
| |_____- in this macro invocation
2424
|
2525
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
26-
help: possible candidates are found in other modules, you can import them into scope
26+
help: consider importing one of these items
2727
|
2828
LL | use bar::g;
2929
|
@@ -41,7 +41,7 @@ LL | n!(f);
4141
LL | n!(f);
4242
| ^ not found in this scope
4343
|
44-
= note: possible candidate is found in another module, you can import it into scope:
44+
= note: consider importing one of these items:
4545
foo::f
4646
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
4747

@@ -54,7 +54,7 @@ LL | n!(f);
5454
LL | f
5555
| ^ not found in this scope
5656
|
57-
= note: possible candidate is found in another module, you can import it into scope:
57+
= note: consider importing one of these items:
5858
foo::f
5959
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6060

src/test/ui/impl-trait/universal_wrong_bounds.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0404]: expected trait, found derive macro `Debug`
44
LL | fn wants_debug(g: impl Debug) { }
55
| ^^^^^ not a trait
66
|
7-
help: possible better candidate is found in another module, you can import it into scope
7+
help: consider importing this trait instead
88
|
99
LL | use std::fmt::Debug;
1010
|
@@ -15,7 +15,7 @@ error[E0404]: expected trait, found derive macro `Debug`
1515
LL | fn wants_display(g: impl Debug) { }
1616
| ^^^^^ not a trait
1717
|
18-
help: possible better candidate is found in another module, you can import it into scope
18+
help: consider importing this trait instead
1919
|
2020
LL | use std::fmt::Debug;
2121
|

src/test/ui/issues/issue-17546.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ error[E0573]: expected type, found variant `Result`
2424
LL | fn new() -> Result<foo::MyEnum, String> {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type
2626
|
27-
help: possible better candidates are found in other modules, you can import them into scope
27+
help: consider importing one of these items instead
2828
|
2929
LL | use std::fmt::Result;
3030
|
@@ -42,7 +42,7 @@ error[E0573]: expected type, found variant `Result`
4242
LL | fn new() -> Result<foo::MyEnum, String> {
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type
4444
|
45-
help: possible better candidates are found in other modules, you can import them into scope
45+
help: consider importing one of these items instead
4646
|
4747
LL | use std::fmt::Result;
4848
|

src/test/ui/issues/issue-35675.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error[E0425]: cannot find function, tuple struct or tuple variant `Apple` in thi
1515
LL | Apple(5)
1616
| ^^^^^ not found in this scope
1717
|
18-
help: possible candidate is found in another module, you can import it into scope
18+
help: consider importing this tuple variant
1919
|
2020
LL | use Fruit::Apple;
2121
|
@@ -35,7 +35,7 @@ error[E0425]: cannot find function, tuple struct or tuple variant `Apple` in thi
3535
LL | Apple(5)
3636
| ^^^^^ not found in this scope
3737
|
38-
help: possible candidate is found in another module, you can import it into scope
38+
help: consider importing this tuple variant
3939
|
4040
LL | use Fruit::Apple;
4141
|

src/test/ui/issues/issue-37534.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0404]: expected trait, found derive macro `Hash`
44
LL | struct Foo<T: ?Hash> { }
55
| ^^^^ not a trait
66
|
7-
help: possible better candidate is found in another module, you can import it into scope
7+
help: consider importing this trait instead
88
|
99
LL | use std::hash::Hash;
1010
|

src/test/ui/issues/issue-38293.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0423]: expected function, found module `baz`
1010
LL | baz();
1111
| ^^^ not a function
1212
|
13-
help: possible better candidate is found in another module, you can import it into scope
13+
help: consider importing this function instead
1414
|
1515
LL | use bar::baz;
1616
|

src/test/ui/issues/issue-42944.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0425]: cannot find function, tuple struct or tuple variant `B` in this sc
1010
LL | B(());
1111
| ^ not found in this scope
1212
|
13-
help: possible candidate is found in another module, you can import it into scope
13+
help: consider importing this tuple struct
1414
|
1515
LL | use foo::B;
1616
|

src/test/ui/issues/issue-4366-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0412]: cannot find type `Bar` in this scope
44
LL | fn sub() -> Bar { 1 }
55
| ^^^ not found in this scope
66
|
7-
help: possible candidate is found in another module, you can import it into scope
7+
help: consider importing this type alias
88
|
99
LL | use a::b::Bar;
1010
|
@@ -15,7 +15,7 @@ error[E0423]: expected function, found module `foo`
1515
LL | foo();
1616
| ^^^ not a function
1717
|
18-
help: possible better candidates are found in other modules, you can import them into scope
18+
help: consider importing one of these items instead
1919
|
2020
LL | use foo::foo;
2121
|

src/test/ui/issues/issue-4366.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find function `foo` in this scope
44
LL | fn sub() -> isize { foo(); 1 }
55
| ^^^ not found in this scope
66
|
7-
help: possible candidates are found in other modules, you can import them into scope
7+
help: consider importing one of these items
88
|
99
LL | use foo::foo;
1010
|

src/test/ui/issues/issue-50599.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find value `LOG10_2` in module `std::f64`
44
LL | const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize;
55
| ^^^^^^^ not found in `std::f64`
66
|
7-
help: possible candidates are found in other modules, you can import them into scope
7+
help: consider importing one of these items
88
|
99
LL | use std::f32::consts::LOG10_2;
1010
|

src/test/ui/lexical-scopes.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0574]: expected struct, variant or union type, found type parameter `T`
44
LL | let t = T { i: 0 };
55
| ^ not a struct, variant or union type
66
|
7-
help: possible better candidate is found in another module, you can import it into scope
7+
help: consider importing this struct instead
88
|
99
LL | use T;
1010
|

src/test/ui/lint/use_suggestion_json.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod foo {
9494
],
9595
"children": [
9696
{
97-
"message": "possible candidates are found in other modules, you can import them into scope",
97+
"message": "consider importing one of these items",
9898
"code": null,
9999
"level": "help",
100100
"spans": [
@@ -385,7 +385,7 @@ mod foo {
385385
\u001b[0m\u001b[1m\u001b[38;5;12mLL\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m let x: Iter;\u001b[0m
386386
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9m^^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9mnot found in this scope\u001b[0m
387387
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
388-
\u001b[0m\u001b[1m\u001b[38;5;14mhelp\u001b[0m\u001b[0m: possible candidates are found in other modules, you can import them into scope\u001b[0m
388+
\u001b[0m\u001b[1m\u001b[38;5;14mhelp\u001b[0m\u001b[0m: consider importing one of these items\u001b[0m
389389
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
390390
\u001b[0m\u001b[1m\u001b[38;5;12mLL\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0muse std::collections::binary_heap::Iter;\u001b[0m
391391
\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m

src/test/ui/macros/macro-outer-attributes.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find function `bar` in module `a`
44
LL | a::bar();
55
| ^^^ not found in `a`
66
|
7-
help: possible candidate is found in another module, you can import it into scope
7+
help: consider importing this function
88
|
99
LL | use b::bar;
1010
|

src/test/ui/namespace/namespace-mix.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ help: a tuple struct with a similar name exists
1212
|
1313
LL | check(m1::TS);
1414
| ^^
15-
help: possible better candidates are found in other modules, you can import them into scope
15+
help: consider importing one of these items instead
1616
|
1717
LL | use m2::S;
1818
|
@@ -35,7 +35,7 @@ help: a tuple struct with a similar name exists
3535
|
3636
LL | check(xm1::TS);
3737
| ^^
38-
help: possible better candidates are found in other modules, you can import them into scope
38+
help: consider importing one of these items instead
3939
|
4040
LL | use m2::S;
4141
|
@@ -57,7 +57,7 @@ help: a tuple variant with a similar name exists
5757
|
5858
LL | check(m7::TV);
5959
| ^^
60-
help: possible better candidates are found in other modules, you can import them into scope
60+
help: consider importing one of these items instead
6161
|
6262
LL | use m8::V;
6363
|
@@ -79,7 +79,7 @@ help: a tuple variant with a similar name exists
7979
|
8080
LL | check(xm7::TV);
8181
| ^^
82-
help: possible better candidates are found in other modules, you can import them into scope
82+
help: consider importing one of these items instead
8383
|
8484
LL | use m8::V;
8585
|

0 commit comments

Comments
 (0)