Skip to content

Commit be0f77d

Browse files
committed
Auto merge of #43864 - GuillaumeGomez:static-method-invalid-use, r=eddyb
Add help for static method invalid use Fixes #30391.
2 parents 7ac979d + 20167ab commit be0f77d

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

src/librustc_typeck/check/method/suggest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
260260
if !static_sources.is_empty() {
261261
err.note("found the following associated functions; to be used as methods, \
262262
functions must have a `self` parameter");
263+
err.help(&format!("try with `{}::{}`", self.ty_to_string(actual), item_name));
263264

264265
report_candidates(&mut err, static_sources);
265266
}

src/test/ui/issue-41652/issue_41652.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ error[E0599]: no method named `f` found for type `{integer}` in the current scop
55
| ^
66
|
77
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
8+
= help: try with `{integer}::f`
89
note: candidate #1 is defined in the trait `issue_41652_b::Tr`
910
--> $DIR/auxiliary/issue_41652_b.rs:14:5
1011
|

src/test/ui/span/issue-7575.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ error[E0599]: no method named `f9` found for type `usize` in the current scope
55
| ^^
66
|
77
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
8+
= help: try with `usize::f9`
89
note: candidate #1 is defined in the trait `CtxtFn`
910
--> $DIR/issue-7575.rs:16:5
1011
|
@@ -36,6 +37,7 @@ error[E0599]: no method named `fff` found for type `Myisize` in the current scop
3637
| ^^^
3738
|
3839
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
40+
= help: try with `Myisize::fff`
3941
note: candidate #1 is defined in an impl for the type `Myisize`
4042
--> $DIR/issue-7575.rs:51:5
4143
|
@@ -51,6 +53,7 @@ error[E0599]: no method named `is_str` found for type `T` in the current scope
5153
| ^^^^^^
5254
|
5355
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
56+
= help: try with `T::is_str`
5457
note: candidate #1 is defined in the trait `ManyImplTrait`
5558
--> $DIR/issue-7575.rs:57:5
5659
|

0 commit comments

Comments
 (0)