Skip to content

Commit 172aab0

Browse files
Rollup merge of #165943 - estebank:issue-37629, r=mati865
Tweak "missing method on type available here" diagnostic Point at trait that is implemented but private. (Fix #37629.) ``` help: trait `crate::method::A` which provides `a` is implemented but not reachable --> $DIR/item-privacy.rs:7:5 | LL | trait A { | ^^^^^^^ ``` Point at method even when available through autoderef. Use note instead of label when pointing at available method. Point at `impl` where method is available in stead of just pointing at the trait: ``` error[E0599]: no method named `qwer` found for struct `S` in the current scope --> $DIR/use-placement-typeck.rs:13:7 | LL | s.qwer(); | ^^^^ method not found in `S` ... LL | pub struct S; | ------------ method `qwer` not found for this struct | note: the method is available on trait `Bar` for `S` --> $DIR/use-placement-typeck.rs:26:9 | LL | impl Bar for S { LL | fn qwer(&self) {} | ^^^^^^^^^^^^^^ the method is available here = help: items from traits can only be used if the trait is in scope help: trait `Bar` which provides `qwer` is implemented but not in scope; perhaps you want to import it | LL + use crate::m::Bar; | ```
2 parents b0b6006 + eb545c5 commit 172aab0

32 files changed

Lines changed: 471 additions & 152 deletions

‎compiler/rustc_hir_typeck/src/method/probe.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ impl<'tcx> Pick<'tcx> {
19131913
// the code from `report_method_error()`.
19141914
lint.help(format!(
19151915
"call with fully qualified syntax `{}(...)` to keep using the current \
1916-
method",
1916+
method",
19171917
tcx.def_path_str(this.item.def_id),
19181918
));
19191919
}

‎compiler/rustc_hir_typeck/src/method/suggest.rs‎

Lines changed: 143 additions & 50 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ LL | match fut.as_mut().poll(ctx) {
3030
| |
3131
| this method is `std::pin::Pin::<Ptr>::as_mut`
3232
|
33-
--> $SRC_DIR/core/src/future/future.rs:LL:COL
34-
|
35-
= note: the method is available for `Pin<&mut impl Future<Output = ()>>` here
3633
note: this returns `Pin<&mut impl Future<Output = ()>>`
3734
--> $SRC_DIR/core/src/pin.rs:LL:COL
3835
note: you might have meant to call `std::convert::AsMut::as_mut` instead
3936
--> $SRC_DIR/core/src/convert/mod.rs:LL:COL
37+
note: the method is available on trait `Future` for `Pin<&mut impl Future<Output = ()>>`
38+
--> $SRC_DIR/core/src/future/future.rs:LL:COL
39+
|
40+
= note: the method is available here
4041
= help: items from traits can only be used if the trait is in scope
4142
help: consider calling `std::convert::AsMut::as_mut` using the fully-qualified path
4243
|

‎tests/ui/coherence/coherence_inherent.stderr‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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+
note: the method is available on trait `TheTrait` for `TheStruct`
8+
--> $DIR/coherence_inherent.rs:7:12
9+
|
10+
LL | pub trait TheTrait {
11+
LL | fn the_fn(&self);
12+
| ^^^^^^ the method is available here
713
= help: items from traits can only be used if the trait is in scope
814
help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it
915
|

‎tests/ui/coherence/coherence_inherent_cc.stderr‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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+
note: the method is available on trait `TheTrait` for `TheStruct`
8+
--> $DIR/auxiliary/coherence_inherent_cc_lib.rs:4:8
9+
|
10+
LL | pub trait TheTrait {
11+
LL | fn the_fn(&self);
12+
| ^^^^^^ the method is available here
713
= help: items from traits can only be used if the trait is in scope
814
help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it
915
|

‎tests/ui/hygiene/trait_items.stderr‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
error[E0599]: no method named `f` found for unit type `()` in the current scope
22
--> $DIR/trait_items.rs:18:24
33
|
4-
LL | fn f(&self) {}
5-
| - the method is available for `()` here
6-
...
74
LL | fn f() { ::baz::m!(); }
85
| ----------- in this macro invocation
96
...
107
LL | pub macro m() { ().f() }
118
| ^ method not found in `()`
129
|
10+
note: the method is available on trait `T` for `()`
11+
--> $DIR/trait_items.rs:8:5
12+
|
13+
LL | pub trait T {
14+
LL | fn f(&self) {}
15+
| - the method is available here
16+
LL | }
17+
LL | impl T for () {}
18+
| ^^^^^^^^^^^^^ the trait is implemented here
1319
= help: items from traits can only be used if the trait is in scope
1420
help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it
1521
|

‎tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
error[E0599]: no method named `my_debug` found for opaque type `impl Debug` in the current scope
22
--> $DIR/call_method_on_inherent_impl_ref-err.rs:19:11
33
|
4-
LL | fn my_debug(&self);
5-
| -------- the method is available for `&impl Debug` here
6-
...
74
LL | x.my_debug();
85
| ^^^^^^^^ method not found in `impl Debug`
96
|
7+
note: the method is available on trait `MyDebug` for `impl Debug`
8+
--> $DIR/call_method_on_inherent_impl_ref-err.rs:13:5
9+
|
10+
LL | impl<T> MyDebug for &T
11+
LL | where
12+
LL | T: std::fmt::Debug,
13+
LL | {
14+
LL | fn my_debug(&self) {}
15+
| ^^^^^^^^^^^^^^^^^^ the method is available here
1016
= help: items from traits can only be used if the trait is implemented and in scope
1117
note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
1218
--> $DIR/call_method_on_inherent_impl_ref-err.rs:5:1

‎tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
error[E0599]: no method named `my_debug` found for type `_` in the current scope
22
--> $DIR/call_method_on_inherent_impl_ref-err.rs:19:11
33
|
4-
LL | fn my_debug(&self);
5-
| -------- the method is available for `&_` here
6-
...
74
LL | x.my_debug();
85
| ^^^^^^^^ method not found in `_`
96
|
7+
note: the method is available on trait `MyDebug` for `_`
8+
--> $DIR/call_method_on_inherent_impl_ref-err.rs:13:5
9+
|
10+
LL | impl<T> MyDebug for &T
11+
LL | where
12+
LL | T: std::fmt::Debug,
13+
LL | {
14+
LL | fn my_debug(&self) {}
15+
| ^^^^^^^^^^^^^^^^^^ the method is available here
1016
= help: items from traits can only be used if the trait is implemented and in scope
1117
note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
1218
--> $DIR/call_method_on_inherent_impl_ref-err.rs:5:1

‎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
@@ -4,10 +4,10 @@ error[E0599]: no method named `fmt` found for opaque type `impl Debug` in the cu
44
LL | x.fmt(f);
55
| ^^^ method not found in `impl Debug`
66
|
7+
note: the method is available on trait `Debug` for `impl Debug`
78
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
89
|
9-
= note: the method is available for `impl Debug` here
10-
|
10+
= note: the method is available here
1111
= help: items from traits can only be used if the trait is in scope
1212
help: trait `Debug` which provides `fmt` is implemented but not in scope; perhaps you want to import it
1313
|

‎tests/ui/impl-trait/no-method-suggested-traits.stderr‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ LL + use crate::no_method_suggested_traits::foo::PubPub;
2929
error[E0599]: no method named `method` found for type `char` in the current scope
3030
--> $DIR/no-method-suggested-traits.rs:33:9
3131
|
32-
LL | fn method(&self) {}
33-
| ------ the method is available for `char` here
34-
...
3532
LL | 'a'.method();
3633
| ^^^^^^ method not found in `char`
3734
|
35+
note: the method is available on trait `Bar` for `char`
36+
--> $DIR/no-method-suggested-traits.rs:19:5
37+
|
38+
LL | pub trait Bar {
39+
LL | fn method(&self) {}
40+
| ------ the method is available here
41+
...
42+
LL | impl Bar for char {}
43+
| ^^^^^^^^^^^^^^^^^ the trait is implemented here
3844
= help: items from traits can only be used if the trait is in scope
3945
help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it
4046
|
@@ -47,6 +53,12 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&char>>` in
4753
LL | std::rc::Rc::new(&mut Box::new(&'a')).method();
4854
| ^^^^^^ method not found in `Rc<&mut Box<&char>>`
4955
|
56+
note: the method is available on trait `Bar` for `char`
57+
--> $DIR/no-method-suggested-traits.rs:12:12
58+
|
59+
LL | pub trait Bar {
60+
LL | fn method(&self) {}
61+
| ^^^^^^ the method is available here
5062
= help: items from traits can only be used if the trait is in scope
5163
help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it
5264
|
@@ -59,11 +71,15 @@ error[E0599]: no method named `method` found for type `i32` in the current scope
5971
LL | 1i32.method();
6072
| ^^^^^^ method not found in `i32`
6173
|
62-
::: $DIR/auxiliary/no_method_suggested_traits.rs:8:12
74+
note: the method is available on trait `PubPub` for `i32`
75+
--> $DIR/auxiliary/no_method_suggested_traits.rs:14:5
6376
|
77+
LL | pub trait PubPub {
6478
LL | fn method(&self) {}
65-
| ------ the method is available for `i32` here
66-
|
79+
| ------ the method is available here
80+
...
81+
LL | impl PubPub for i32 {}
82+
| ^^^^^^^^^^^^^^^^^^^ the trait is implemented here
6783
= help: items from traits can only be used if the trait is in scope
6884
help: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it
6985
|
@@ -76,6 +92,12 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&i32>>` in
7692
LL | std::rc::Rc::new(&mut Box::new(&1i32)).method();
7793
| ^^^^^^ method not found in `Rc<&mut Box<&i32>>`
7894
|
95+
note: the method is available on trait `PubPub` for `i32`
96+
--> $DIR/auxiliary/no_method_suggested_traits.rs:8:12
97+
|
98+
LL | pub trait PubPub {
99+
LL | fn method(&self) {}
100+
| ^^^^^^ the method is available here
79101
= help: items from traits can only be used if the trait is in scope
80102
help: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it
81103
|

0 commit comments

Comments
 (0)