Skip to content

Point to correct argument in Func Call when Self type fails trait bound #143567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return true;
}

for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
.into_iter()
.flatten()
for param in [
predicate_self_type_to_point_at,
param_to_point_at,
fallback_param_to_point_at,
self_param_to_point_at,
]
.into_iter()
.flatten()
{
if self.blame_specific_arg_if_possible(
error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0283]: type annotations needed
--> $DIR/dedup-normalized-2-higher-ranked.rs:28:5
|
LL | impls(rigid);
| ^^^^^ cannot infer type of the type parameter `U` declared on the function `impls`
| ^^^^^ ----- type must be known at this point
| |
| cannot infer type of the type parameter `U` declared on the function `impls`
|
= note: cannot satisfy `for<'b> <P as Trait>::Rigid: Bound<'b, _>`
note: required by a bound in `impls`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/infer/issue-77092.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ error[E0284]: type annotations needed
LL | println!("{:?}", take_array_from_mut(&mut arr, i));
| ---- ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut`
| |
| type must be known at this point
| required by this formatting parameter
|
= note: required for `[i32; _]` to implement `Debug`
= note: 1 redundant requirement hidden
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0283]: type annotations needed
--> $DIR/auto-trait-selection-freeze.rs:19:16
|
LL | if false { is_trait(foo()) } else { Default::default() }
| ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait`
| ^^^^^^^^ ----- type must be known at this point
| |
| cannot infer type of the type parameter `U` declared on the function `is_trait`
|
note: multiple `impl`s satisfying `impl Sized: Trait<_>` found
--> $DIR/auto-trait-selection-freeze.rs:16:1
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/impl-trait/auto-trait-selection.old.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0283]: type annotations needed
--> $DIR/auto-trait-selection.rs:15:16
|
LL | if false { is_trait(foo()) } else { Default::default() }
| ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait`
| ^^^^^^^^ ----- type must be known at this point
| |
| cannot infer type of the type parameter `U` declared on the function `is_trait`
|
note: multiple `impl`s satisfying `impl Sized: Trait<_>` found
--> $DIR/auto-trait-selection.rs:12:1
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/trait-bounds/false-span-in-trait-bound-label.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// In this test, the span of the trait bound label should point to `1`, not `""`.
// See issue #143336

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

fn main() {
A::f(1, ""); //~ ERROR the trait bound `{integer}: A<_>` is not satisfied [E0277]
}
17 changes: 17 additions & 0 deletions tests/ui/trait-bounds/false-span-in-trait-bound-label.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0277]: the trait bound `{integer}: A<_>` is not satisfied
--> $DIR/false-span-in-trait-bound-label.rs:9:10
|
LL | A::f(1, "");
| ---- ^ the trait `A<_>` is not implemented for `{integer}`
| |
| required by a bound introduced by this call
|
help: this trait has no implementations, consider adding one
--> $DIR/false-span-in-trait-bound-label.rs:4:1
|
LL | trait A<T> {
| ^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
4 changes: 2 additions & 2 deletions tests/ui/traits/inheritance/repeated-supertrait-ambig.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ LL | <dyn CompareToInts>::same_as(c, 22)
`i64` implements `CompareTo<u64>`

error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied
--> $DIR/repeated-supertrait-ambig.rs:38:27
--> $DIR/repeated-supertrait-ambig.rs:38:24
|
LL | CompareTo::same_as(c, 22)
| ------------------ ^^ the trait `CompareTo<i32>` is not implemented for `C`
| ------------------ ^ the trait `CompareTo<i32>` is not implemented for `C`
| |
| required by a bound introduced by this call
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/traits/multidispatch-convert-ambig-dest.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0283]: type annotations needed
--> $DIR/multidispatch-convert-ambig-dest.rs:26:5
|
LL | test(22, std::default::Default::default());
| ^^^^ -------------------------------- type must be known at this point
| ^^^^ -- type must be known at this point
| |
| cannot infer type of the type parameter `U` declared on the function `test`
|
Expand Down
Loading