Skip to content

Commit 796b4d1

Browse files
committed
Point to correct argument in Func Call when Self type fails trait bound
When a trait bound fails due to the Self type parameter, adjust_fulfillment_errors now correctly points to the corresponding function argument instead of incorrectly pointing to other arguments. Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent cf7e896 commit 796b4d1

File tree

9 files changed

+25
-14
lines changed

9 files changed

+25
-14
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
184184
return true;
185185
}
186186

187-
for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
188-
.into_iter()
189-
.flatten()
187+
for param in [
188+
predicate_self_type_to_point_at,
189+
param_to_point_at,
190+
fallback_param_to_point_at,
191+
self_param_to_point_at,
192+
]
193+
.into_iter()
194+
.flatten()
190195
{
191196
if self.blame_specific_arg_if_possible(
192197
error,

tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.current.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0283]: type annotations needed
22
--> $DIR/dedup-normalized-2-higher-ranked.rs:28:5
33
|
44
LL | impls(rigid);
5-
| ^^^^^ cannot infer type of the type parameter `U` declared on the function `impls`
5+
| ^^^^^ ----- type must be known at this point
6+
| |
7+
| cannot infer type of the type parameter `U` declared on the function `impls`
68
|
79
= note: cannot satisfy `for<'b> <P as Trait>::Rigid: Bound<'b, _>`
810
note: required by a bound in `impls`

tests/ui/const-generics/infer/issue-77092.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error[E0284]: type annotations needed
2020
LL | println!("{:?}", take_array_from_mut(&mut arr, i));
2121
| ---- ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut`
2222
| |
23-
| type must be known at this point
23+
| required by this formatting parameter
2424
|
2525
= note: required for `[i32; _]` to implement `Debug`
2626
= note: 1 redundant requirement hidden

tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0283]: type annotations needed
22
--> $DIR/auto-trait-selection-freeze.rs:19:16
33
|
44
LL | if false { is_trait(foo()) } else { Default::default() }
5-
| ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait`
5+
| ^^^^^^^^ ----- type must be known at this point
6+
| |
7+
| cannot infer type of the type parameter `U` declared on the function `is_trait`
68
|
79
note: multiple `impl`s satisfying `impl Sized: Trait<_>` found
810
--> $DIR/auto-trait-selection-freeze.rs:16:1

tests/ui/impl-trait/auto-trait-selection.old.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0283]: type annotations needed
22
--> $DIR/auto-trait-selection.rs:15:16
33
|
44
LL | if false { is_trait(foo()) } else { Default::default() }
5-
| ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait`
5+
| ^^^^^^^^ ----- type must be known at this point
6+
| |
7+
| cannot infer type of the type parameter `U` declared on the function `is_trait`
68
|
79
note: multiple `impl`s satisfying `impl Sized: Trait<_>` found
810
--> $DIR/auto-trait-selection.rs:12:1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// In this test, the span of the trait bound label should point to `1`, not `""`.
2-
// See issue #1433376
2+
// See issue #143336
33

44
trait A<T> {
55
fn f(self, x: T);
66
}
77

88
fn main() {
99
A::f(1, ""); //~ ERROR the trait bound `{integer}: A<_>` is not satisfied [E0277]
10-
}
10+
}

tests/ui/trait-bounds/false-span-in-trait-bound-label.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `{integer}: A<_>` is not satisfied
2-
--> $DIR/false-span-in-trait-bound-label.rs:9:13
2+
--> $DIR/false-span-in-trait-bound-label.rs:9:10
33
|
44
LL | A::f(1, "");
5-
| ---- ^^ the trait `A<_>` is not implemented for `{integer}`
5+
| ---- ^ the trait `A<_>` is not implemented for `{integer}`
66
| |
77
| required by a bound introduced by this call
88
|

tests/ui/traits/inheritance/repeated-supertrait-ambig.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ LL | <dyn CompareToInts>::same_as(c, 22)
3434
`i64` implements `CompareTo<u64>`
3535

3636
error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied
37-
--> $DIR/repeated-supertrait-ambig.rs:38:27
37+
--> $DIR/repeated-supertrait-ambig.rs:38:24
3838
|
3939
LL | CompareTo::same_as(c, 22)
40-
| ------------------ ^^ the trait `CompareTo<i32>` is not implemented for `C`
40+
| ------------------ ^ the trait `CompareTo<i32>` is not implemented for `C`
4141
| |
4242
| required by a bound introduced by this call
4343
|

tests/ui/traits/multidispatch-convert-ambig-dest.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0283]: type annotations needed
22
--> $DIR/multidispatch-convert-ambig-dest.rs:26:5
33
|
44
LL | test(22, std::default::Default::default());
5-
| ^^^^ -------------------------------- type must be known at this point
5+
| ^^^^ -- type must be known at this point
66
| |
77
| cannot infer type of the type parameter `U` declared on the function `test`
88
|

0 commit comments

Comments
 (0)