Skip to content

Commit 53d1540

Browse files
authored
Rollup merge of #71903 - euclio:reword-possible-better, r=petrochenkov
reword "possible candidate" import suggestion This suggestion has always read a bit awkwardly to me, particularly the "possible better candidate" variant. This commit rewords the suggestion to be more concise and mention the kind of the suggested item. There isn't a nice way to label individual suggestions, so I opted to use "items" in the case of multiple suggestions.
2 parents f3691ac + 9f88d75 commit 53d1540

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

Lines changed: 11 additions & 8 deletions
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,10 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
877877
let module_def_id = module.def_id().unwrap();
878878
if module_def_id == def_id {
879879
let path = Path { span: name_binding.span, segments: path_segments };
880-
result = Some((module, ImportSuggestion { did: Some(def_id), path }));
880+
result = Some((
881+
module,
882+
ImportSuggestion { did: Some(def_id), descr: "module", path },
883+
));
881884
} else {
882885
// add the module to the lookup
883886
if seen_modules.insert(module_def_id) {

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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
|

0 commit comments

Comments
 (0)