Skip to content

Commit c4b6a59

Browse files
committed
Make E0599's label more clear for field which is used like a method.
fixes #127178
1 parent 52f3c71 commit c4b6a59

34 files changed

+110
-51
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22772277
let call_expr = tcx.hir().expect_expr(tcx.parent_hir_id(expr.hir_id));
22782278

22792279
if let Some(span) = call_expr.span.trim_start(item_name.span) {
2280-
err.span_suggestion(
2280+
err.span_suggestion_verbose(
22812281
span,
22822282
"remove the arguments",
22832283
"",
@@ -3266,7 +3266,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32663266
.copied();
32673267

32683268
if explain {
3269-
err.help("items from traits can only be used if the trait is in scope");
3269+
err.help(
3270+
"items from traits can only be used if the trait is implemented and in scope",
3271+
);
32703272
}
32713273

32723274
let msg = format!(
@@ -3570,7 +3572,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
35703572
}
35713573
}
35723574
}
3573-
if self.suggest_valid_traits(err, item_name, valid_out_of_scope_traits, true) {
3575+
if self.suggest_valid_traits(
3576+
err,
3577+
item_name,
3578+
valid_out_of_scope_traits,
3579+
!trait_missing_method,
3580+
) {
35743581
return;
35753582
}
35763583

tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LL | match fut.as_mut().poll(ctx) {
2929
|
3030
= note: the method is available for `Pin<&mut impl Future<Output = ()>>` here
3131
|
32-
= help: items from traits can only be used if the trait is in scope
32+
= help: items from traits can only be used if the trait is implemented and in scope
3333
help: trait `Future` which provides `poll` is implemented but not in scope; perhaps you want to import it
3434
|
3535
LL + use std::future::Future;

tests/ui/coherence/coherence_inherent.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c
44
LL | s.the_fn();
55
| ^^^^^^ method not found in `&TheStruct`
66
|
7-
= help: items from traits can only be used if the trait is in scope
7+
= help: items from traits can only be used if the trait is implemented and in scope
88
help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it
99
|
1010
LL + use Lib::TheTrait;

tests/ui/coherence/coherence_inherent_cc.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c
44
LL | s.the_fn();
55
| ^^^^^^ method not found in `&TheStruct`
66
|
7-
= help: items from traits can only be used if the trait is in scope
7+
= help: items from traits can only be used if the trait is implemented and in scope
88
help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it
99
|
1010
LL + use coherence_inherent_cc_lib::TheTrait;

tests/ui/confuse-field-and-method/issue-2392.stderr

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ LL | struct Obj<F> where F: FnOnce() -> u32 {
1919
| ------------- method `not_closure` not found for this struct
2020
...
2121
LL | o_closure.not_closure();
22-
| ^^^^^^^^^^^-- help: remove the arguments
23-
| |
24-
| field, not a method
22+
| ^^^^^^^^^^^ field, not a method
23+
|
24+
help: remove the arguments
25+
|
26+
LL - o_closure.not_closure();
27+
LL + o_closure.not_closure;
28+
|
2529

2630
error[E0599]: no method named `closure` found for struct `Obj` in the current scope
2731
--> $DIR/issue-2392.rs:42:12
@@ -86,9 +90,13 @@ LL | struct Obj<F> where F: FnOnce() -> u32 {
8690
| ------------- method `not_closure` not found for this struct
8791
...
8892
LL | w.wrap.not_closure();
89-
| ^^^^^^^^^^^-- help: remove the arguments
90-
| |
91-
| field, not a method
93+
| ^^^^^^^^^^^ field, not a method
94+
|
95+
help: remove the arguments
96+
|
97+
LL - w.wrap.not_closure();
98+
LL + w.wrap.not_closure;
99+
|
92100

93101
error[E0599]: no method named `closure` found for struct `Obj` in the current scope
94102
--> $DIR/issue-2392.rs:58:24

tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn f(a: S) {
2626
a.f();
2727
//~^ ERROR the method `f` exists for struct `S`, but its trait bounds were not satisfied
2828
//~| NOTE method cannot be called on `S` due to unsatisfied trait bounds
29+
//~| HELP items from traits can only be used if the trait is implemented and in scope
2930
}
3031

3132
fn main() {}

tests/ui/hygiene/no_implicit_prelude.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | fn f() { ::bar::m!(); }
2222
LL | ().clone()
2323
| ^^^^^
2424
|
25-
= help: items from traits can only be used if the trait is in scope
25+
= help: items from traits can only be used if the trait is implemented and in scope
2626
help: there is a method `clone_from` with a similar name, but with different arguments
2727
--> $SRC_DIR/core/src/clone.rs:LL:COL
2828
= note: this error originates in the macro `::bar::m` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/hygiene/trait_items.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | fn f() { ::baz::m!(); }
1010
LL | pub macro m() { ().f() }
1111
| ^ method not found in `()`
1212
|
13-
= help: items from traits can only be used if the trait is in scope
13+
= help: items from traits can only be used if the trait is implemented and in scope
1414
= note: this error originates in the macro `::baz::m` (in Nightly builds, run with -Z macro-backtrace for more info)
1515
help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it
1616
|

tests/ui/impl-trait/call_method_without_import.no_import.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | x.fmt(f);
77
|
88
= note: the method is available for `impl Debug` here
99
|
10-
= help: items from traits can only be used if the trait is in scope
10+
= help: items from traits can only be used if the trait is implemented and in scope
1111
help: trait `Debug` which provides `fmt` is implemented but not in scope; perhaps you want to import it
1212
|
1313
LL + use std::fmt::Debug;
@@ -19,7 +19,7 @@ error[E0599]: no method named `fmt` found for mutable reference `&mut impl Debug
1919
LL | x.fmt(f);
2020
| ^^^ method not found in `&mut impl Debug`
2121
|
22-
= help: items from traits can only be used if the trait is in scope
22+
= help: items from traits can only be used if the trait is implemented and in scope
2323
help: the following traits which provide `fmt` are implemented but not in scope; perhaps you want to import one of them
2424
|
2525
LL + use std::fmt::Binary;

tests/ui/impl-trait/no-method-suggested-traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ fn main() {
2222

2323
1u32.method();
2424
//~^ ERROR no method named
25-
//~|items from traits can only be used if the trait is in scope
25+
//~|items from traits can only be used if the trait is implemented and in scope
2626
std::rc::Rc::new(&mut Box::new(&1u32)).method();
27-
//~^items from traits can only be used if the trait is in scope
27+
//~^items from traits can only be used if the trait is implemented and in scope
2828
//~| ERROR no method named `method` found for struct
2929

3030
'a'.method();

0 commit comments

Comments
 (0)