Skip to content

Commit 8257ba2

Browse files
authored
Rollup merge of #98298 - TaKO8Ki:point-to-type-param-definition, r=compiler-errors
Point to type parameter definition when not finding variant, method and associated item fixes #77391
2 parents ecefccd + 402dceb commit 8257ba2

File tree

64 files changed

+168
-125
lines changed

Some content is hidden

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

64 files changed

+168
-125
lines changed

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

+21-15
Original file line numberDiff line numberDiff line change
@@ -346,19 +346,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
346346
);
347347
}
348348

349-
if let Some(def) = actual.ty_adt_def() {
350-
if let Some(full_sp) = tcx.hir().span_if_local(def.did()) {
351-
let def_sp = tcx.sess.source_map().guess_head_span(full_sp);
352-
err.span_label(
353-
def_sp,
354-
format!(
355-
"{} `{}` not found {}",
356-
item_kind,
357-
item_name,
358-
if def.is_enum() && !is_method { "here" } else { "for this" }
359-
),
360-
);
349+
let ty_span = match actual.kind() {
350+
ty::Param(param_type) => {
351+
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
352+
let type_param = generics.type_param(param_type, self.tcx);
353+
Some(self.tcx.def_span(type_param.def_id))
354+
}
355+
ty::Adt(def, _) if def.did().is_local() => {
356+
tcx.def_ident_span(def.did()).map(|span| span)
361357
}
358+
_ => None,
359+
};
360+
361+
if let Some(span) = ty_span {
362+
err.span_label(
363+
span,
364+
format!(
365+
"{item_kind} `{item_name}` not found for this {}",
366+
actual.prefix_string(self.tcx)
367+
),
368+
);
362369
}
363370

364371
if self.is_fn_ty(rcvr_ty, span) {
@@ -1951,9 +1958,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19511958
)
19521959
};
19531960
// Obtain the span for `param` and use it for a structured suggestion.
1954-
if let (Some(param), Some(table)) = (param_type, self.in_progress_typeck_results) {
1955-
let table_owner = table.borrow().hir_owner;
1956-
let generics = self.tcx.generics_of(table_owner.to_def_id());
1961+
if let Some(param) = param_type {
1962+
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
19571963
let type_param = generics.type_param(param, self.tcx);
19581964
let hir = self.tcx.hir();
19591965
if let Some(def_id) = type_param.def_id.as_local() {

src/test/ui/associated-item/associated-item-enum.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no variant or associated item named `mispellable` found for enum `
22
--> $DIR/associated-item-enum.rs:17:11
33
|
44
LL | enum Enum { Variant }
5-
| --------- variant or associated item `mispellable` not found here
5+
| ---- variant or associated item `mispellable` not found for this enum
66
...
77
LL | Enum::mispellable();
88
| ^^^^^^^^^^^
@@ -14,7 +14,7 @@ error[E0599]: no variant or associated item named `mispellable_trait` found for
1414
--> $DIR/associated-item-enum.rs:18:11
1515
|
1616
LL | enum Enum { Variant }
17-
| --------- variant or associated item `mispellable_trait` not found here
17+
| ---- variant or associated item `mispellable_trait` not found for this enum
1818
...
1919
LL | Enum::mispellable_trait();
2020
| ^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ error[E0599]: no variant or associated item named `MISPELLABLE` found for enum `
2626
--> $DIR/associated-item-enum.rs:19:11
2727
|
2828
LL | enum Enum { Variant }
29-
| --------- variant or associated item `MISPELLABLE` not found here
29+
| ---- variant or associated item `MISPELLABLE` not found for this enum
3030
...
3131
LL | Enum::MISPELLABLE;
3232
| ^^^^^^^^^^^

src/test/ui/async-await/pin-needed-to-poll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `poll` found for struct `Sleep` in the current sco
22
--> $DIR/pin-needed-to-poll.rs:42:20
33
|
44
LL | struct Sleep;
5-
| ------------- method `poll` not found for this
5+
| ----- method `poll` not found for this struct
66
...
77
LL | self.sleep.poll(cx)
88
| ^^^^ method not found in `Sleep`

src/test/ui/bogus-tag.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no variant or associated item named `Hsl` found for enum `Color` i
22
--> $DIR/bogus-tag.rs:7:16
33
|
44
LL | enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
5-
| ---------- variant or associated item `Hsl` not found here
5+
| ----- variant or associated item `Hsl` not found for this enum
66
...
77
LL | Color::Hsl(h, s, l) => { println!("hsl"); }
88
| ^^^ variant or associated item not found in `Color`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `closure` found for struct `Obj` in the current sc
22
--> $DIR/issue-18343.rs:7:7
33
|
44
LL | struct Obj<F> where F: FnMut() -> u32 {
5-
| ------------------------------------- method `closure` not found for this
5+
| --- method `closure` not found for this struct
66
...
77
LL | o.closure();
88
| ^^^^^^^ field, not a method

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `closure` found for struct `Obj` in the current sc
22
--> $DIR/issue-2392.rs:36:15
33
|
44
LL | struct Obj<F> where F: FnOnce() -> u32 {
5-
| -------------------------------------- method `closure` not found for this
5+
| --- method `closure` not found for this struct
66
...
77
LL | o_closure.closure();
88
| ^^^^^^^ field, not a method
@@ -16,7 +16,7 @@ error[E0599]: no method named `not_closure` found for struct `Obj` in the curren
1616
--> $DIR/issue-2392.rs:38:15
1717
|
1818
LL | struct Obj<F> where F: FnOnce() -> u32 {
19-
| -------------------------------------- method `not_closure` not found for this
19+
| --- method `not_closure` not found for this struct
2020
...
2121
LL | o_closure.not_closure();
2222
| ^^^^^^^^^^^-- help: remove the arguments
@@ -27,7 +27,7 @@ error[E0599]: no method named `closure` found for struct `Obj` in the current sc
2727
--> $DIR/issue-2392.rs:42:12
2828
|
2929
LL | struct Obj<F> where F: FnOnce() -> u32 {
30-
| -------------------------------------- method `closure` not found for this
30+
| --- method `closure` not found for this struct
3131
...
3232
LL | o_func.closure();
3333
| ^^^^^^^ field, not a method
@@ -41,7 +41,7 @@ error[E0599]: no method named `boxed_closure` found for struct `BoxedObj` in the
4141
--> $DIR/issue-2392.rs:45:14
4242
|
4343
LL | struct BoxedObj {
44-
| --------------- method `boxed_closure` not found for this
44+
| -------- method `boxed_closure` not found for this struct
4545
...
4646
LL | boxed_fn.boxed_closure();
4747
| ^^^^^^^^^^^^^ field, not a method
@@ -55,7 +55,7 @@ error[E0599]: no method named `boxed_closure` found for struct `BoxedObj` in the
5555
--> $DIR/issue-2392.rs:48:19
5656
|
5757
LL | struct BoxedObj {
58-
| --------------- method `boxed_closure` not found for this
58+
| -------- method `boxed_closure` not found for this struct
5959
...
6060
LL | boxed_closure.boxed_closure();
6161
| ^^^^^^^^^^^^^ field, not a method
@@ -69,7 +69,7 @@ error[E0599]: no method named `closure` found for struct `Obj` in the current sc
6969
--> $DIR/issue-2392.rs:53:12
7070
|
7171
LL | struct Obj<F> where F: FnOnce() -> u32 {
72-
| -------------------------------------- method `closure` not found for this
72+
| --- method `closure` not found for this struct
7373
...
7474
LL | w.wrap.closure();
7575
| ^^^^^^^ field, not a method
@@ -83,7 +83,7 @@ error[E0599]: no method named `not_closure` found for struct `Obj` in the curren
8383
--> $DIR/issue-2392.rs:55:12
8484
|
8585
LL | struct Obj<F> where F: FnOnce() -> u32 {
86-
| -------------------------------------- method `not_closure` not found for this
86+
| --- method `not_closure` not found for this struct
8787
...
8888
LL | w.wrap.not_closure();
8989
| ^^^^^^^^^^^-- help: remove the arguments
@@ -94,7 +94,7 @@ error[E0599]: no method named `closure` found for struct `Obj` in the current sc
9494
--> $DIR/issue-2392.rs:58:24
9595
|
9696
LL | struct Obj<F> where F: FnOnce() -> u32 {
97-
| -------------------------------------- method `closure` not found for this
97+
| --- method `closure` not found for this struct
9898
...
9999
LL | check_expression().closure();
100100
| ^^^^^^^ field, not a method
@@ -108,7 +108,7 @@ error[E0599]: no method named `f1` found for struct `FuncContainer` in the curre
108108
--> $DIR/issue-2392.rs:64:31
109109
|
110110
LL | struct FuncContainer {
111-
| -------------------- method `f1` not found for this
111+
| ------------- method `f1` not found for this struct
112112
...
113113
LL | (*self.container).f1(1);
114114
| ^^ field, not a method
@@ -122,7 +122,7 @@ error[E0599]: no method named `f2` found for struct `FuncContainer` in the curre
122122
--> $DIR/issue-2392.rs:65:31
123123
|
124124
LL | struct FuncContainer {
125-
| -------------------- method `f2` not found for this
125+
| ------------- method `f2` not found for this struct
126126
...
127127
LL | (*self.container).f2(1);
128128
| ^^ field, not a method
@@ -136,7 +136,7 @@ error[E0599]: no method named `f3` found for struct `FuncContainer` in the curre
136136
--> $DIR/issue-2392.rs:66:31
137137
|
138138
LL | struct FuncContainer {
139-
| -------------------- method `f3` not found for this
139+
| ------------- method `f3` not found for this struct
140140
...
141141
LL | (*self.container).f3(1);
142142
| ^^ field, not a method

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `example` found for struct `Example` in the curren
22
--> $DIR/issue-32128.rs:12:10
33
|
44
LL | struct Example {
5-
| -------------- method `example` not found for this
5+
| ------- method `example` not found for this struct
66
...
77
LL | demo.example(1);
88
| ^^^^^^^ field, not a method

src/test/ui/confuse-field-and-method/private-field.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `dog_age` found for struct `Dog` in the current sc
22
--> $DIR/private-field.rs:16:23
33
|
44
LL | pub struct Dog {
5-
| -------------- method `dog_age` not found for this
5+
| --- method `dog_age` not found for this struct
66
...
77
LL | let dog_age = dog.dog_age();
88
| ^^^^^^^ private field, not a method

src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0599]: the function or associated item `foo` exists for struct `Foo<{_: u
88
--> $DIR/issue-69654.rs:17:10
99
|
1010
LL | struct Foo<const N: usize> {}
11-
| -------------------------- function or associated item `foo` not found for this
11+
| --- function or associated item `foo` not found for this struct
1212
...
1313
LL | Foo::foo();
1414
| ^^^ function or associated item cannot be called on `Foo<{_: usize}>` due to unsatisfied trait bounds

src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr

+6-12
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,16 @@ LL | [u8; size_of::<T>() + 1]: ,
1515
error[E0599]: the function or associated item `new` exists for struct `Inline<dyn Debug>`, but its trait bounds were not satisfied
1616
--> $DIR/issue-80742.rs:30:36
1717
|
18-
LL | / struct Inline<T>
19-
LL | | where
20-
LL | | [u8; size_of::<T>() + 1]: ,
21-
LL | | {
22-
LL | | _phantom: PhantomData<T>,
23-
LL | | buf: [u8; size_of::<T>() + 1],
24-
LL | | }
25-
| |_- function or associated item `new` not found for this
18+
LL | struct Inline<T>
19+
| ------ function or associated item `new` not found for this struct
2620
...
27-
LL | let dst = Inline::<dyn Debug>::new(0);
28-
| ^^^ function or associated item cannot be called on `Inline<dyn Debug>` due to unsatisfied trait bounds
21+
LL | let dst = Inline::<dyn Debug>::new(0);
22+
| ^^^ function or associated item cannot be called on `Inline<dyn Debug>` due to unsatisfied trait bounds
2923
|
3024
::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL
3125
|
32-
LL | pub trait Debug {
33-
| --------------- doesn't satisfy `dyn Debug: Sized`
26+
LL | pub trait Debug {
27+
| --------------- doesn't satisfy `dyn Debug: Sized`
3428
|
3529
= note: the following trait bounds were not satisfied:
3630
`dyn Debug: Sized`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0599]: no method named `f` found for struct `S` in the current scope
1616
--> $DIR/invalid-const-arg-for-type-param.rs:9:7
1717
|
1818
LL | struct S;
19-
| --------- method `f` not found for this
19+
| - method `f` not found for this struct
2020
...
2121
LL | S.f::<0>();
2222
| ^ method not found in `S`

src/test/ui/consts/const-needs_drop-monomorphic.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no function or associated item named `assert` found for struct `Bo
22
--> $DIR/const-needs_drop-monomorphic.rs:11:46
33
|
44
LL | struct Bool<const B: bool> {}
5-
| -------------------------- function or associated item `assert` not found for this
5+
| ---- function or associated item `assert` not found for this struct
66
...
77
LL | Bool::<{ std::mem::needs_drop::<T>() }>::assert();
88
| ^^^^^^ function or associated item cannot be called on `Bool<{ std::mem::needs_drop::<T>() }>` due to unsatisfied trait bounds

src/test/ui/copy-a-resource.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no method named `clone` found for struct `Foo` in the current scop
22
--> $DIR/copy-a-resource.rs:18:16
33
|
44
LL | struct Foo {
5-
| ---------- method `clone` not found for this
5+
| --- method `clone` not found for this struct
66
...
77
LL | let _y = x.clone();
88
| ^^^^^ method not found in `Foo`

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ error[E0599]: the method `clone` exists for struct `Bar<NotClone>`, but its trai
33
|
44
LL | struct Bar<T: Foo> {
55
| ------------------
6-
| |
7-
| method `clone` not found for this
6+
| | |
7+
| | method `clone` not found for this struct
88
| doesn't satisfy `Bar<NotClone>: Clone`
99
...
1010
LL | struct NotClone;

src/test/ui/derives/issue-91492.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ LL | pub struct NoDerives;
3737
| --------------------- doesn't satisfy `NoDerives: Clone`
3838
...
3939
LL | struct Object<T, A>(T, A);
40-
| -------------------------- method `use_clone` not found for this
40+
| ------ method `use_clone` not found for this struct
4141
...
4242
LL | foo.use_clone();
4343
| ^^^^^^^^^ method cannot be called on `Object<NoDerives, SomeDerives>` due to unsatisfied trait bounds

src/test/ui/derives/issue-91550.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LL | pub struct NoDerives;
2525
| --------------------- doesn't satisfy `NoDerives: Eq`
2626
LL |
2727
LL | struct Object<T>(T);
28-
| -------------------- method `use_eq` not found for this
28+
| ------ method `use_eq` not found for this struct
2929
...
3030
LL | foo.use_eq();
3131
| ^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds
@@ -44,7 +44,7 @@ LL | pub struct NoDerives;
4444
| --------------------- doesn't satisfy `NoDerives: Ord`
4545
LL |
4646
LL | struct Object<T>(T);
47-
| -------------------- method `use_ord` not found for this
47+
| ------ method `use_ord` not found for this struct
4848
...
4949
LL | foo.use_ord();
5050
| ^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds
@@ -66,7 +66,7 @@ LL | pub struct NoDerives;
6666
| doesn't satisfy `NoDerives: PartialOrd`
6767
LL |
6868
LL | struct Object<T>(T);
69-
| -------------------- method `use_ord_and_partial_ord` not found for this
69+
| ------ method `use_ord_and_partial_ord` not found for this struct
7070
...
7171
LL | foo.use_ord_and_partial_ord();
7272
| ^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds

src/test/ui/did_you_mean/issue-40006.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ error[E0599]: no method named `hello_method` found for struct `S` in the current
8888
--> $DIR/issue-40006.rs:38:7
8989
|
9090
LL | struct S;
91-
| --------- method `hello_method` not found for this
91+
| - method `hello_method` not found for this struct
9292
...
9393
LL | S.hello_method();
9494
| ^^^^^^^^^^^^ method not found in `S`

src/test/ui/dont-suggest-private-trait-method.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no function or associated item named `new` found for struct `T` in
22
--> $DIR/dont-suggest-private-trait-method.rs:4:8
33
|
44
LL | struct T;
5-
| --------- function or associated item `new` not found for this
5+
| - function or associated item `new` not found for this struct
66
...
77
LL | T::new();
88
| ^^^ function or associated item not found in `T`

src/test/ui/error-codes/E0599.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no associated item named `NotEvenReal` found for struct `Foo` in t
22
--> $DIR/E0599.rs:4:20
33
|
44
LL | struct Foo;
5-
| ----------- associated item `NotEvenReal` not found for this
5+
| --- associated item `NotEvenReal` not found for this struct
66
...
77
LL | || if let Foo::NotEvenReal() = Foo {};
88
| ^^^^^^^^^^^ associated item not found in `Foo`

src/test/ui/generic-associated-types/method-unsatified-assoc-type-predicate.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ error[E0599]: the method `f` exists for struct `S`, but its trait bounds were no
33
|
44
LL | struct S;
55
| ---------
6-
| |
7-
| method `f` not found for this
6+
| | |
7+
| | method `f` not found for this struct
88
| doesn't satisfy `<S as X>::Y<i32> = i32`
99
| doesn't satisfy `S: M`
1010
...

src/test/ui/hrtb/issue-30786.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@$DIR/
33
|
44
LL | pub struct Map<S, F> {
55
| --------------------
6-
| |
7-
| method `filterx` not found for this
6+
| | |
7+
| | method `filterx` not found for this struct
88
| doesn't satisfy `_: StreamExt`
99
...
1010
LL | let filter = map.filterx(|x: &_| true);
@@ -28,8 +28,8 @@ error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'r>
2828
|
2929
LL | pub struct Filter<S, F> {
3030
| -----------------------
31-
| |
32-
| method `countx` not found for this
31+
| | |
32+
| | method `countx` not found for this struct
3333
| doesn't satisfy `_: StreamExt`
3434
...
3535
LL | let count = filter.countx();

0 commit comments

Comments
 (0)