Skip to content

Commit 824383d

Browse files
committed
Auto merge of #64237 - estebank:tweak-method-not-found, r=Centril
Give method not found a primary span label
2 parents 1e86913 + 5799fb4 commit 824383d

File tree

63 files changed

+101
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+101
-98
lines changed

Diff for: src/librustc_typeck/check/method/suggest.rs

+3
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
425425
"private field"
426426
};
427427
err.span_label(item_name.span, format!("{}, not a method", field_kind));
428+
} else if lev_candidate.is_none() && static_sources.is_empty() {
429+
err.span_label(span, format!("{} not found in `{}`", item_kind, ty_str));
430+
self.tcx.sess.trait_methods_not_found.borrow_mut().insert(orig_span);
428431
}
429432
} else {
430433
err.span_label(span, format!("{} not found in `{}`", item_kind, ty_str));

Diff for: src/test/ui/auto-ref-slice-plus-ref.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0599]: no method named `test` found for type `std::vec::Vec<{integer}>` i
1212
--> $DIR/auto-ref-slice-plus-ref.rs:8:7
1313
|
1414
LL | a.test();
15-
| ^^^^
15+
| ^^^^ method not found in `std::vec::Vec<{integer}>`
1616
|
1717
= help: items from traits can only be used if the trait is implemented and in scope
1818
= note: the following trait defines an item `test`, perhaps you need to implement it:
@@ -22,7 +22,7 @@ error[E0599]: no method named `test` found for type `[{integer}; 1]` in the curr
2222
--> $DIR/auto-ref-slice-plus-ref.rs:10:11
2323
|
2424
LL | ([1]).test();
25-
| ^^^^
25+
| ^^^^ method not found in `[{integer}; 1]`
2626
|
2727
= help: items from traits can only be used if the trait is implemented and in scope
2828
= note: the following trait defines an item `test`, perhaps you need to implement it:
@@ -32,7 +32,7 @@ error[E0599]: no method named `test` found for type `&[{integer}; 1]` in the cur
3232
--> $DIR/auto-ref-slice-plus-ref.rs:11:12
3333
|
3434
LL | (&[1]).test();
35-
| ^^^^
35+
| ^^^^ method not found in `&[{integer}; 1]`
3636
|
3737
= help: items from traits can only be used if the trait is implemented and in scope
3838
= note: the following trait defines an item `test`, perhaps you need to implement it:

Diff for: src/test/ui/class-cast-to-trait.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `eat` found for type `std::boxed::Box<dyn Noisy>`
22
--> $DIR/class-cast-to-trait.rs:53:8
33
|
44
LL | nyan.eat();
5-
| ^^^
5+
| ^^^ method not found in `std::boxed::Box<dyn Noisy>`
66

77
error: aborting due to previous error
88

Diff for: src/test/ui/coherence/coherence_inherent.old.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `the_fn` found for type `&Lib::TheStruct` in the c
22
--> $DIR/coherence_inherent.rs:35:11
33
|
44
LL | s.the_fn();
5-
| ^^^^^^
5+
| ^^^^^^ method not found in `&Lib::TheStruct`
66
|
77
= help: items from traits can only be used if the trait is in scope
88
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:

Diff for: src/test/ui/coherence/coherence_inherent.re.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `the_fn` found for type `&Lib::TheStruct` in the c
22
--> $DIR/coherence_inherent.rs:35:11
33
|
44
LL | s.the_fn();
5-
| ^^^^^^
5+
| ^^^^^^ method not found in `&Lib::TheStruct`
66
|
77
= help: items from traits can only be used if the trait is in scope
88
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:

Diff for: src/test/ui/coherence/coherence_inherent_cc.old.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `the_fn` found for type `&coherence_inherent_cc_li
22
--> $DIR/coherence_inherent_cc.rs:26:11
33
|
44
LL | s.the_fn();
5-
| ^^^^^^
5+
| ^^^^^^ method not found in `&coherence_inherent_cc_lib::TheStruct`
66
|
77
= help: items from traits can only be used if the trait is in scope
88
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:

Diff for: src/test/ui/coherence/coherence_inherent_cc.re.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `the_fn` found for type `&coherence_inherent_cc_li
22
--> $DIR/coherence_inherent_cc.rs:26:11
33
|
44
LL | s.the_fn();
5-
| ^^^^^^
5+
| ^^^^^^ method not found in `&coherence_inherent_cc_lib::TheStruct`
66
|
77
= help: items from traits can only be used if the trait is in scope
88
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:

Diff for: src/test/ui/const-generics/invalid-const-arg-for-type-param.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | struct S;
1111
| --------- method `f` not found for this
1212
...
1313
LL | S.f::<0>();
14-
| ^
14+
| ^ method not found in `S`
1515

1616
error[E0107]: wrong number of const arguments: expected 0, found 1
1717
--> $DIR/invalid-const-arg-for-type-param.rs:8:9

Diff for: src/test/ui/copy-a-resource.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Foo {
55
| ---------- method `clone` not found for this
66
...
77
LL | let _y = x.clone();
8-
| ^^^^^
8+
| ^^^^^ method not found in `Foo`
99
|
1010
= help: items from traits can only be used if the trait is implemented and in scope
1111
= note: the following trait defines an item `clone`, perhaps you need to implement it:

Diff for: src/test/ui/derives/derive-assoc-type-not-impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Bar<T: Foo> {
55
| ------------------ method `clone` not found for this
66
...
77
LL | Bar::<NotClone> { x: 1 }.clone();
8-
| ^^^^^
8+
| ^^^^^ method not found in `Bar<NotClone>`
99
|
1010
= note: the method `clone` exists but the following trait bounds were not satisfied:
1111
`Bar<NotClone> : std::clone::Clone`

Diff for: src/test/ui/error-festival.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ error[E0599]: no method named `z` found for type `&str` in the current scope
2424
--> $DIR/error-festival.rs:16:7
2525
|
2626
LL | x.z();
27-
| ^
27+
| ^ method not found in `&str`
2828

2929
error[E0600]: cannot apply unary operator `!` to type `Question`
3030
--> $DIR/error-festival.rs:19:5

Diff for: src/test/ui/hygiene/no_implicit_prelude.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | fn f() { ::bar::m!(); }
2222
| ------------ in this macro invocation
2323
...
2424
LL | ().clone()
25-
| ^^^^^
25+
| ^^^^^ method not found in `()`
2626
|
2727
= help: items from traits can only be used if the trait is in scope
2828
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:

Diff for: src/test/ui/hygiene/trait_items.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn f() { ::baz::m!(); }
55
| ------------ in this macro invocation
66
...
77
LL | pub macro m() { ().f() }
8-
| ^
8+
| ^ method not found in `()`
99
|
1010
= help: items from traits can only be used if the trait is in scope
1111
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:

Diff for: src/test/ui/impl-trait/bindings-opaque.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ error[E0599]: no method named `count_ones` found for type `impl std::marker::Cop
1010
--> $DIR/bindings-opaque.rs:11:17
1111
|
1212
LL | let _ = FOO.count_ones();
13-
| ^^^^^^^^^^
13+
| ^^^^^^^^^^ method not found in `impl std::marker::Copy`
1414

1515
error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
1616
--> $DIR/bindings-opaque.rs:13:17
1717
|
1818
LL | let _ = BAR.count_ones();
19-
| ^^^^^^^^^^
19+
| ^^^^^^^^^^ method not found in `impl std::marker::Copy`
2020

2121
error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
2222
--> $DIR/bindings-opaque.rs:15:17
2323
|
2424
LL | let _ = foo.count_ones();
25-
| ^^^^^^^^^^
25+
| ^^^^^^^^^^ method not found in `impl std::marker::Copy`
2626

2727
error: aborting due to 3 previous errors
2828

Diff for: src/test/ui/impl-trait/issues/issue-21659-show-relevant-trait-impls-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Bar;
55
| ----------- method `foo` not found for this
66
...
77
LL | f1.foo(1usize);
8-
| ^^^
8+
| ^^^ method not found in `Bar`
99
|
1010
= help: items from traits can only be used if the trait is implemented and in scope
1111
= note: the following trait defines an item `foo`, perhaps you need to implement it:

Diff for: src/test/ui/impl-trait/method-suggestion-no-duplication.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Foo;
55
| ----------- method `is_empty` not found for this
66
...
77
LL | foo(|s| s.is_empty());
8-
| ^^^^^^^^
8+
| ^^^^^^^^ method not found in `Foo`
99
|
1010
= help: items from traits can only be used if the trait is implemented and in scope
1111
= note: the following trait defines an item `is_empty`, perhaps you need to implement it:

Diff for: src/test/ui/impl-trait/no-method-suggested-traits.stderr

+24-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `method` found for type `u32` in the current scope
22
--> $DIR/no-method-suggested-traits.rs:23:10
33
|
44
LL | 1u32.method();
5-
| ^^^^^^
5+
| ^^^^^^ method not found in `u32`
66
|
77
= help: items from traits can only be used if the trait is in scope
88
help: the following traits are implemented but not in scope, perhaps add a `use` for one of them:
@@ -20,7 +20,7 @@ error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::box
2020
--> $DIR/no-method-suggested-traits.rs:26:44
2121
|
2222
LL | std::rc::Rc::new(&mut Box::new(&1u32)).method();
23-
| ^^^^^^
23+
| ^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&u32>>`
2424
|
2525
= help: items from traits can only be used if the trait is in scope
2626
help: the following traits are implemented but not in scope, perhaps add a `use` for one of them:
@@ -38,7 +38,7 @@ error[E0599]: no method named `method` found for type `char` in the current scop
3838
--> $DIR/no-method-suggested-traits.rs:30:9
3939
|
4040
LL | 'a'.method();
41-
| ^^^^^^
41+
| ^^^^^^ method not found in `char`
4242
|
4343
= help: items from traits can only be used if the trait is in scope
4444
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
@@ -58,7 +58,7 @@ LL | fn method(&self) {}
5858
| the method is available for `std::rc::Rc<std::rc::Rc<&mut std::boxed::Box<&char>>>` here
5959
...
6060
LL | std::rc::Rc::new(&mut Box::new(&'a')).method();
61-
| ^^^^^^
61+
| ^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&char>>`
6262
|
6363
= help: items from traits can only be used if the trait is in scope
6464
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
@@ -70,7 +70,7 @@ error[E0599]: no method named `method` found for type `i32` in the current scope
7070
--> $DIR/no-method-suggested-traits.rs:35:10
7171
|
7272
LL | 1i32.method();
73-
| ^^^^^^
73+
| ^^^^^^ method not found in `i32`
7474
|
7575
= help: items from traits can only be used if the trait is in scope
7676
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
@@ -82,7 +82,7 @@ error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::box
8282
--> $DIR/no-method-suggested-traits.rs:37:44
8383
|
8484
LL | std::rc::Rc::new(&mut Box::new(&1i32)).method();
85-
| ^^^^^^
85+
| ^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&i32>>`
8686
|
8787
= help: items from traits can only be used if the trait is in scope
8888
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
@@ -97,7 +97,7 @@ LL | struct Foo;
9797
| ----------- method `method` not found for this
9898
...
9999
LL | Foo.method();
100-
| ^^^^^^
100+
| ^^^^^^ method not found in `Foo`
101101
|
102102
= help: items from traits can only be used if the trait is implemented and in scope
103103
= note: the following traits define an item `method`, perhaps you need to implement one of them:
@@ -110,7 +110,7 @@ error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::box
110110
--> $DIR/no-method-suggested-traits.rs:42:43
111111
|
112112
LL | std::rc::Rc::new(&mut Box::new(&Foo)).method();
113-
| ^^^^^^
113+
| ^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&Foo>>`
114114
|
115115
= help: items from traits can only be used if the trait is implemented and in scope
116116
= note: the following traits define an item `method`, perhaps you need to implement one of them:
@@ -123,7 +123,7 @@ error[E0599]: no method named `method2` found for type `u64` in the current scop
123123
--> $DIR/no-method-suggested-traits.rs:45:10
124124
|
125125
LL | 1u64.method2();
126-
| ^^^^^^^
126+
| ^^^^^^^ method not found in `u64`
127127
|
128128
= help: items from traits can only be used if the trait is implemented and in scope
129129
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -133,7 +133,7 @@ error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::bo
133133
--> $DIR/no-method-suggested-traits.rs:47:44
134134
|
135135
LL | std::rc::Rc::new(&mut Box::new(&1u64)).method2();
136-
| ^^^^^^^
136+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&u64>>`
137137
|
138138
= help: items from traits can only be used if the trait is implemented and in scope
139139
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -143,7 +143,7 @@ error[E0599]: no method named `method2` found for type `no_method_suggested_trai
143143
--> $DIR/no-method-suggested-traits.rs:50:37
144144
|
145145
LL | no_method_suggested_traits::Foo.method2();
146-
| ^^^^^^^
146+
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
147147
|
148148
= help: items from traits can only be used if the trait is implemented and in scope
149149
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -153,7 +153,7 @@ error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::bo
153153
--> $DIR/no-method-suggested-traits.rs:52:71
154154
|
155155
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
156-
| ^^^^^^^
156+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>`
157157
|
158158
= help: items from traits can only be used if the trait is implemented and in scope
159159
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -163,7 +163,7 @@ error[E0599]: no method named `method2` found for type `no_method_suggested_trai
163163
--> $DIR/no-method-suggested-traits.rs:54:40
164164
|
165165
LL | no_method_suggested_traits::Bar::X.method2();
166-
| ^^^^^^^
166+
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
167167
|
168168
= help: items from traits can only be used if the trait is implemented and in scope
169169
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -173,7 +173,7 @@ error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::bo
173173
--> $DIR/no-method-suggested-traits.rs:56:74
174174
|
175175
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
176-
| ^^^^^^^
176+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>`
177177
|
178178
= help: items from traits can only be used if the trait is implemented and in scope
179179
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -186,7 +186,7 @@ LL | struct Foo;
186186
| ----------- method `method3` not found for this
187187
...
188188
LL | Foo.method3();
189-
| ^^^^^^^
189+
| ^^^^^^^ method not found in `Foo`
190190
|
191191
= help: items from traits can only be used if the trait is implemented and in scope
192192
= note: the following trait defines an item `method3`, perhaps you need to implement it:
@@ -196,7 +196,7 @@ error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::bo
196196
--> $DIR/no-method-suggested-traits.rs:61:43
197197
|
198198
LL | std::rc::Rc::new(&mut Box::new(&Foo)).method3();
199-
| ^^^^^^^
199+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&Foo>>`
200200
|
201201
= help: items from traits can only be used if the trait is implemented and in scope
202202
= note: the following trait defines an item `method3`, perhaps you need to implement it:
@@ -209,7 +209,7 @@ LL | enum Bar { X }
209209
| -------- method `method3` not found for this
210210
...
211211
LL | Bar::X.method3();
212-
| ^^^^^^^
212+
| ^^^^^^^ method not found in `Bar`
213213
|
214214
= help: items from traits can only be used if the trait is implemented and in scope
215215
= note: the following trait defines an item `method3`, perhaps you need to implement it:
@@ -219,7 +219,7 @@ error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::bo
219219
--> $DIR/no-method-suggested-traits.rs:65:46
220220
|
221221
LL | std::rc::Rc::new(&mut Box::new(&Bar::X)).method3();
222-
| ^^^^^^^
222+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&Bar>>`
223223
|
224224
= help: items from traits can only be used if the trait is implemented and in scope
225225
= note: the following trait defines an item `method3`, perhaps you need to implement it:
@@ -229,37 +229,37 @@ error[E0599]: no method named `method3` found for type `usize` in the current sc
229229
--> $DIR/no-method-suggested-traits.rs:69:13
230230
|
231231
LL | 1_usize.method3();
232-
| ^^^^^^^
232+
| ^^^^^^^ method not found in `usize`
233233

234234
error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&usize>>` in the current scope
235235
--> $DIR/no-method-suggested-traits.rs:70:47
236236
|
237237
LL | std::rc::Rc::new(&mut Box::new(&1_usize)).method3();
238-
| ^^^^^^^
238+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&usize>>`
239239

240240
error[E0599]: no method named `method3` found for type `no_method_suggested_traits::Foo` in the current scope
241241
--> $DIR/no-method-suggested-traits.rs:71:37
242242
|
243243
LL | no_method_suggested_traits::Foo.method3();
244-
| ^^^^^^^
244+
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
245245

246246
error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>` in the current scope
247247
--> $DIR/no-method-suggested-traits.rs:72:71
248248
|
249249
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3();
250-
| ^^^^^^^
250+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>`
251251

252252
error[E0599]: no method named `method3` found for type `no_method_suggested_traits::Bar` in the current scope
253253
--> $DIR/no-method-suggested-traits.rs:74:40
254254
|
255255
LL | no_method_suggested_traits::Bar::X.method3();
256-
| ^^^^^^^
256+
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
257257

258258
error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>` in the current scope
259259
--> $DIR/no-method-suggested-traits.rs:75:74
260260
|
261261
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3();
262-
| ^^^^^^^
262+
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>`
263263

264264
error: aborting due to 24 previous errors
265265

Diff for: src/test/ui/infinite/infinite-autoderef.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ LL | struct Foo;
4444
| ----------- method `bar` not found for this
4545
...
4646
LL | Foo.bar();
47-
| ^^^
47+
| ^^^ method not found in `Foo`
4848

4949
error: aborting due to 6 previous errors
5050

0 commit comments

Comments
 (0)