Skip to content

Commit 6efa14b

Browse files
committed
remove generic argument insead of displaying "_"
1 parent c64a2ed commit 6efa14b

11 files changed

+36
-50
lines changed

compiler/rustc_typeck/src/check/method/suggest.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir::{ExprKind, Node, QPath};
1313
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1414
use rustc_middle::ty::fast_reject::simplify_type;
1515
use rustc_middle::ty::print::with_crate_prefix;
16-
use rustc_middle::ty::subst::GenericArgKind;
1716
use rustc_middle::ty::{
1817
self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
1918
};
@@ -411,20 +410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
411410
.sum();
412411
if candidate_numbers == 0 && unsatisfied_predicates.is_empty() {
413412
if let Some((path_string, _)) = ty_str.split_once('<') {
414-
ty_str_reported = format!("{}<", path_string);
415-
for (index, arg) in generics.iter().enumerate() {
416-
let arg_replace = match arg.unpack() {
417-
GenericArgKind::Lifetime(_) => "'_",
418-
GenericArgKind::Type(_)
419-
| GenericArgKind::Const(_) => "_",
420-
};
421-
ty_str_reported =
422-
format!("{}{}", ty_str_reported, arg_replace);
423-
if index < generics.len() - 1 {
424-
ty_str_reported = format!("{}, ", ty_str_reported);
425-
}
426-
}
427-
ty_str_reported = format!("{}>", ty_str_reported);
413+
ty_str_reported = path_string.to_string();
428414
}
429415
}
430416
}

src/test/ui/auto-ref-slice-plus-ref.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `test_mut` found for struct `Vec<_, _>` in the current scope
1+
error[E0599]: no method named `test_mut` found for struct `Vec` in the current scope
22
--> $DIR/auto-ref-slice-plus-ref.rs:7:7
33
|
44
LL | a.test_mut();
@@ -11,7 +11,7 @@ note: `MyIter` defines an item `test_mut`, perhaps you need to implement it
1111
LL | trait MyIter {
1212
| ^^^^^^^^^^^^
1313

14-
error[E0599]: no method named `test` found for struct `Vec<_, _>` in the current scope
14+
error[E0599]: no method named `test` found for struct `Vec` in the current scope
1515
--> $DIR/auto-ref-slice-plus-ref.rs:8:7
1616
|
1717
LL | a.test();

src/test/ui/class-cast-to-trait.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `eat` found for struct `Box<_, _>` in the current scope
1+
error[E0599]: no method named `eat` found for struct `Box` in the current scope
22
--> $DIR/class-cast-to-trait.rs:53:8
33
|
44
LL | nyan.eat();

src/test/ui/confuse-field-and-method/issue-18343.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `closure` found for struct `Obj<_>` in the current scope
1+
error[E0599]: no method named `closure` found for struct `Obj` in the current scope
22
--> $DIR/issue-18343.rs:7:7
33
|
44
LL | struct Obj<F> where F: FnMut() -> u32 {

src/test/ui/confuse-field-and-method/issue-2392.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `closure` found for struct `Obj<_>` in the current scope
1+
error[E0599]: no method named `closure` found for struct `Obj` in the current scope
22
--> $DIR/issue-2392.rs:36:15
33
|
44
LL | struct Obj<F> where F: FnOnce() -> u32 {
@@ -12,7 +12,7 @@ help: to call the function stored in `closure`, surround the field access with p
1212
LL | (o_closure.closure)();
1313
| ^ ^
1414

15-
error[E0599]: no method named `not_closure` found for struct `Obj<_>` in the current scope
15+
error[E0599]: no method named `not_closure` found for struct `Obj` in the current scope
1616
--> $DIR/issue-2392.rs:38:15
1717
|
1818
LL | struct Obj<F> where F: FnOnce() -> u32 {
@@ -23,7 +23,7 @@ LL | o_closure.not_closure();
2323
| |
2424
| field, not a method
2525

26-
error[E0599]: no method named `closure` found for struct `Obj<_>` in the current scope
26+
error[E0599]: no method named `closure` found for struct `Obj` in the current scope
2727
--> $DIR/issue-2392.rs:42:12
2828
|
2929
LL | struct Obj<F> where F: FnOnce() -> u32 {
@@ -65,7 +65,7 @@ help: to call the function stored in `boxed_closure`, surround the field access
6565
LL | (boxed_closure.boxed_closure)();
6666
| ^ ^
6767

68-
error[E0599]: no method named `closure` found for struct `Obj<_>` in the current scope
68+
error[E0599]: no method named `closure` found for struct `Obj` in the current scope
6969
--> $DIR/issue-2392.rs:53:12
7070
|
7171
LL | struct Obj<F> where F: FnOnce() -> u32 {
@@ -79,7 +79,7 @@ help: to call the function stored in `closure`, surround the field access with p
7979
LL | (w.wrap.closure)();
8080
| ^ ^
8181

82-
error[E0599]: no method named `not_closure` found for struct `Obj<_>` in the current scope
82+
error[E0599]: no method named `not_closure` found for struct `Obj` in the current scope
8383
--> $DIR/issue-2392.rs:55:12
8484
|
8585
LL | struct Obj<F> where F: FnOnce() -> u32 {
@@ -90,7 +90,7 @@ LL | w.wrap.not_closure();
9090
| |
9191
| field, not a method
9292

93-
error[E0599]: no method named `closure` found for struct `Obj<_>` in the current scope
93+
error[E0599]: no method named `closure` found for struct `Obj` in the current scope
9494
--> $DIR/issue-2392.rs:58:24
9595
|
9696
LL | struct Obj<F> where F: FnOnce() -> u32 {

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | use no_method_suggested_traits::qux::PrivPub;
1616
LL | use no_method_suggested_traits::Reexported;
1717
|
1818

19-
error[E0599]: no method named `method` found for struct `Rc<_>` in the current scope
19+
error[E0599]: no method named `method` found for struct `Rc` in the current scope
2020
--> $DIR/no-method-suggested-traits.rs:26:44
2121
|
2222
LL | std::rc::Rc::new(&mut Box::new(&1u32)).method();
@@ -46,7 +46,7 @@ help: the following trait is implemented but not in scope; perhaps add a `use` f
4646
LL | use foo::Bar;
4747
|
4848

49-
error[E0599]: no method named `method` found for struct `Rc<_>` in the current scope
49+
error[E0599]: no method named `method` found for struct `Rc` in the current scope
5050
--> $DIR/no-method-suggested-traits.rs:32:43
5151
|
5252
LL | std::rc::Rc::new(&mut Box::new(&'a')).method();
@@ -70,7 +70,7 @@ help: the following trait is implemented but not in scope; perhaps add a `use` f
7070
LL | use no_method_suggested_traits::foo::PubPub;
7171
|
7272

73-
error[E0599]: no method named `method` found for struct `Rc<_>` in the current scope
73+
error[E0599]: no method named `method` found for struct `Rc` in the current scope
7474
--> $DIR/no-method-suggested-traits.rs:37:44
7575
|
7676
LL | std::rc::Rc::new(&mut Box::new(&1i32)).method();
@@ -98,7 +98,7 @@ LL | Foo.method();
9898
candidate #3: `no_method_suggested_traits::qux::PrivPub`
9999
candidate #4: `Reexported`
100100

101-
error[E0599]: no method named `method` found for struct `Rc<_>` in the current scope
101+
error[E0599]: no method named `method` found for struct `Rc` in the current scope
102102
--> $DIR/no-method-suggested-traits.rs:42:43
103103
|
104104
LL | std::rc::Rc::new(&mut Box::new(&Foo)).method();
@@ -124,7 +124,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
124124
LL | pub trait Bar {
125125
| ^^^^^^^^^^^^^
126126

127-
error[E0599]: no method named `method2` found for struct `Rc<_>` in the current scope
127+
error[E0599]: no method named `method2` found for struct `Rc` in the current scope
128128
--> $DIR/no-method-suggested-traits.rs:47:44
129129
|
130130
LL | std::rc::Rc::new(&mut Box::new(&1u64)).method2();
@@ -150,7 +150,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
150150
LL | pub trait Bar {
151151
| ^^^^^^^^^^^^^
152152

153-
error[E0599]: no method named `method2` found for struct `Rc<_>` in the current scope
153+
error[E0599]: no method named `method2` found for struct `Rc` in the current scope
154154
--> $DIR/no-method-suggested-traits.rs:52:71
155155
|
156156
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
@@ -176,7 +176,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
176176
LL | pub trait Bar {
177177
| ^^^^^^^^^^^^^
178178

179-
error[E0599]: no method named `method2` found for struct `Rc<_>` in the current scope
179+
error[E0599]: no method named `method2` found for struct `Rc` in the current scope
180180
--> $DIR/no-method-suggested-traits.rs:56:74
181181
|
182182
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
@@ -202,7 +202,7 @@ LL | Foo.method3();
202202
= note: the following trait defines an item `method3`, perhaps you need to implement it:
203203
candidate #1: `PubPub`
204204

205-
error[E0599]: no method named `method3` found for struct `Rc<_>` in the current scope
205+
error[E0599]: no method named `method3` found for struct `Rc` in the current scope
206206
--> $DIR/no-method-suggested-traits.rs:61:43
207207
|
208208
LL | std::rc::Rc::new(&mut Box::new(&Foo)).method3();
@@ -225,7 +225,7 @@ LL | Bar::X.method3();
225225
= note: the following trait defines an item `method3`, perhaps you need to implement it:
226226
candidate #1: `PubPub`
227227

228-
error[E0599]: no method named `method3` found for struct `Rc<_>` in the current scope
228+
error[E0599]: no method named `method3` found for struct `Rc` in the current scope
229229
--> $DIR/no-method-suggested-traits.rs:65:46
230230
|
231231
LL | std::rc::Rc::new(&mut Box::new(&Bar::X)).method3();
@@ -241,7 +241,7 @@ error[E0599]: no method named `method3` found for type `usize` in the current sc
241241
LL | 1_usize.method3();
242242
| ^^^^^^^ method not found in `usize`
243243

244-
error[E0599]: no method named `method3` found for struct `Rc<_>` in the current scope
244+
error[E0599]: no method named `method3` found for struct `Rc` in the current scope
245245
--> $DIR/no-method-suggested-traits.rs:70:47
246246
|
247247
LL | std::rc::Rc::new(&mut Box::new(&1_usize)).method3();
@@ -253,7 +253,7 @@ error[E0599]: no method named `method3` found for struct `no_method_suggested_tr
253253
LL | no_method_suggested_traits::Foo.method3();
254254
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
255255

256-
error[E0599]: no method named `method3` found for struct `Rc<_>` in the current scope
256+
error[E0599]: no method named `method3` found for struct `Rc` in the current scope
257257
--> $DIR/no-method-suggested-traits.rs:72:71
258258
|
259259
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3();
@@ -265,7 +265,7 @@ error[E0599]: no method named `method3` found for enum `no_method_suggested_trai
265265
LL | no_method_suggested_traits::Bar::X.method3();
266266
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
267267

268-
error[E0599]: no method named `method3` found for struct `Rc<_>` in the current scope
268+
error[E0599]: no method named `method3` found for struct `Rc` in the current scope
269269
--> $DIR/no-method-suggested-traits.rs:75:74
270270
|
271271
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3();

src/test/ui/issues/issue-41880.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `iter` found for struct `Iterate<_, _>` in the current scope
1+
error[E0599]: no method named `iter` found for struct `Iterate` in the current scope
22
--> $DIR/issue-41880.rs:27:24
33
|
44
LL | pub struct Iterate<T, F> {

src/test/ui/methods/method-not-found-generic-arg-elision.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,22 @@ fn main() {
6969
let d = point_i32.distance();
7070
//~^ ERROR no method named `distance` found for struct `Point<i32>
7171
let d = point_i32.other();
72-
//~^ ERROR no method named `other` found for struct `Point<_>
72+
//~^ ERROR no method named `other` found for struct `Point
7373
let v = vec![1_i32, 2, 3];
7474
v.iter().map(|x| x * x).extend(std::iter::once(100));
75-
//~^ ERROR no method named `extend` found for struct `Map<_, _>
75+
//~^ ERROR no method named `extend` found for struct `Map
7676
let wrapper = Wrapper(true);
7777
wrapper.method();
7878
//~^ ERROR no method named `method` found for struct `Wrapper<bool>
7979
wrapper.other();
80-
//~^ ERROR no method named `other` found for struct `Wrapper<_>
80+
//~^ ERROR no method named `other` found for struct `Wrapper
8181
let boolean = true;
8282
let wrapper = Wrapper2::<'_, _, 3> {x: &boolean};
8383
wrapper.method();
8484
//~^ ERROR no method named `method` found for struct `Wrapper2<'_, bool, 3_usize>
8585
wrapper.other();
86-
//~^ ERROR no method named `other` found for struct `Wrapper2<'_, _, _>
86+
//~^ ERROR no method named `other` found for struct `Wrapper2
8787
let a = vec![1, 2, 3];
8888
a.not_found();
89-
//~^ ERROR no method named `not_found` found for struct `Vec<_, _>
89+
//~^ ERROR no method named `not_found` found for struct `Vec
9090
}

src/test/ui/methods/method-not-found-generic-arg-elision.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | let d = point_i32.distance();
99
|
1010
= note: The method was found for Point<f64>.
1111

12-
error[E0599]: no method named `other` found for struct `Point<_>` in the current scope
12+
error[E0599]: no method named `other` found for struct `Point` in the current scope
1313
--> $DIR/method-not-found-generic-arg-elision.rs:71:23
1414
|
1515
LL | struct Point<T> {
@@ -18,7 +18,7 @@ LL | struct Point<T> {
1818
LL | let d = point_i32.other();
1919
| ^^^^^ method not found in `Point<i32>`
2020

21-
error[E0599]: no method named `extend` found for struct `Map<_, _>` in the current scope
21+
error[E0599]: no method named `extend` found for struct `Map` in the current scope
2222
--> $DIR/method-not-found-generic-arg-elision.rs:74:29
2323
|
2424
LL | v.iter().map(|x| x * x).extend(std::iter::once(100));
@@ -35,7 +35,7 @@ LL | wrapper.method();
3535
|
3636
= note: The method was found for Wrapper<i8>, Wrapper<u16>, Wrapper<u16> and 3 more.
3737

38-
error[E0599]: no method named `other` found for struct `Wrapper<_>` in the current scope
38+
error[E0599]: no method named `other` found for struct `Wrapper` in the current scope
3939
--> $DIR/method-not-found-generic-arg-elision.rs:79:13
4040
|
4141
LL | struct Wrapper<T>(T);
@@ -55,7 +55,7 @@ LL | wrapper.method();
5555
|
5656
= note: The method was found for Wrapper2<'a, i8, C>, Wrapper2<'a, i32, C> and Wrapper2<'a, i32, C>.
5757

58-
error[E0599]: no method named `other` found for struct `Wrapper2<'_, _, _>` in the current scope
58+
error[E0599]: no method named `other` found for struct `Wrapper2` in the current scope
5959
--> $DIR/method-not-found-generic-arg-elision.rs:85:13
6060
|
6161
LL | struct Wrapper2<'a, T, const C: usize> {
@@ -64,7 +64,7 @@ LL | struct Wrapper2<'a, T, const C: usize> {
6464
LL | wrapper.other();
6565
| ^^^^^ method not found in `Wrapper2<'_, bool, 3_usize>`
6666

67-
error[E0599]: no method named `not_found` found for struct `Vec<_, _>` in the current scope
67+
error[E0599]: no method named `not_found` found for struct `Vec` in the current scope
6868
--> $DIR/method-not-found-generic-arg-elision.rs:88:7
6969
|
7070
LL | a.not_found();

src/test/ui/object-pointer-types.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | fn owned(self: Box<Self>);
1616
LL | x.owned();
1717
| ^^^^^ method not found in `&mut dyn Foo`
1818

19-
error[E0599]: no method named `managed` found for struct `Box<_, _>` in the current scope
19+
error[E0599]: no method named `managed` found for struct `Box` in the current scope
2020
--> $DIR/object-pointer-types.rs:23:7
2121
|
2222
LL | x.managed();

src/test/ui/resolve/issue-82865.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0433]: failed to resolve: maybe a missing crate `x`?
44
LL | use x::y::z;
55
| ^ maybe a missing crate `x`?
66

7-
error[E0599]: no function or associated item named `z` found for struct `Box<_, _>` in the current scope
7+
error[E0599]: no function or associated item named `z` found for struct `Box` in the current scope
88
--> $DIR/issue-82865.rs:8:10
99
|
1010
LL | Box::z

0 commit comments

Comments
 (0)