Skip to content

Commit 8a3c058

Browse files
committed
E0599: use param name for lifetime arg suggestions too
It's not needed to convey it's a placeholder since it's already surrounded by `/*` and `*/`, and `'_` wouldn't work in that position so it's not a helpful suggestion.
1 parent aa1dfdd commit 8a3c058

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -3878,19 +3878,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38783878
let candidate_strs: Vec<String> = candidates
38793879
.iter()
38803880
.map(|cand| {
3881-
use ty::GenericParamDefKind::{Const, Lifetime, Type};
3881+
use ty::GenericParamDefKind::{Const, Type};
38823882
let cand_path = self.tcx.def_path_str(cand.def_id);
38833883
let cand_params = &self.tcx.generics_of(cand.def_id).own_params;
38843884
let cand_args: String = cand_params
38853885
.iter()
38863886
.skip(1)
38873887
.filter_map(|param| match param.kind {
3888-
Lifetime => Some("'_"),
38893888
Type { has_default: true, .. }
38903889
| Const { has_default: true, .. } => None,
3891-
// in keeping with suggestions for missing generic args,
3892-
// use their names from the trait definition as placeholders
3893-
Type { .. } | Const { .. } => Some(param.name.as_str()),
3890+
// if a placeholder is needed, use the parameter's name
3891+
_ => Some(param.name.as_str()),
38943892
})
38953893
.intersperse(", ")
38963894
.collect();

Diff for: tests/ui/suggestions/no-method-found-suggest-trait-args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait Trait2<'a, A, const B: u8, C = (), const D: u8 = 0> {
1111

1212
fn foo<T>(value: T) {
1313
//~^ SUGGESTION : Trait</* I */>
14-
//~| SUGGESTION : Trait2</* '_, A, B */>
14+
//~| SUGGESTION : Trait2</* 'a, A, B */>
1515
value.method();
1616
//~^ ERROR no method named `method` found for type parameter `T` in the current scope [E0599]
1717
value.method2();
@@ -20,7 +20,7 @@ fn foo<T>(value: T) {
2020

2121
fn bar(value: impl Copy) {
2222
//~^ SUGGESTION + Trait</* I */>
23-
//~| SUGGESTION + Trait2</* '_, A, B */>
23+
//~| SUGGESTION + Trait2</* 'a, A, B */>
2424
value.method();
2525
//~^ ERROR no method named `method` found for type parameter `impl Copy` in the current scope [E0599]
2626
value.method2();

Diff for: tests/ui/suggestions/no-method-found-suggest-trait-args.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LL | value.method2();
2525
= help: items from traits can only be used if the type parameter is bounded by the trait
2626
help: the following trait defines an item `method2`, perhaps you need to restrict type parameter `T` with it:
2727
|
28-
LL | fn foo<T: Trait2</* '_, A, B */>>(value: T) {
28+
LL | fn foo<T: Trait2</* 'a, A, B */>>(value: T) {
2929
| ++++++++++++++++++++++++
3030

3131
error[E0599]: no method named `method` found for type parameter `impl Copy` in the current scope
@@ -55,7 +55,7 @@ LL | value.method2();
5555
= help: items from traits can only be used if the type parameter is bounded by the trait
5656
help: the following trait defines an item `method2`, perhaps you need to restrict type parameter `impl Copy` with it:
5757
|
58-
LL | fn bar(value: impl Copy + Trait2</* '_, A, B */>) {
58+
LL | fn bar(value: impl Copy + Trait2</* 'a, A, B */>) {
5959
| ++++++++++++++++++++++++
6060

6161
error: aborting due to 4 previous errors

0 commit comments

Comments
 (0)