Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 569a842

Browse files
committed
Point at call span that introduced obligation for the arg
1 parent 8a3f712 commit 569a842

File tree

94 files changed

+668
-250
lines changed

Some content is hidden

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

94 files changed

+668
-250
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,9 +2297,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
22972297
}
22982298
ObligationCauseCode::FunctionArgumentObligation {
22992299
arg_hir_id: _,
2300-
call_hir_id: _,
2300+
call_hir_id,
23012301
ref parent_code,
23022302
} => {
2303+
let hir = self.tcx.hir();
2304+
if let Some(Node::Expr(hir::Expr {
2305+
kind:
2306+
hir::ExprKind::Call(hir::Expr { span, .. }, _)
2307+
| hir::ExprKind::MethodCall(_, span, ..),
2308+
..
2309+
})) = hir.find(call_hir_id)
2310+
{
2311+
err.span_label(*span, "required by a bound in this call");
2312+
}
23032313
ensure_sufficient_stack(|| {
23042314
self.note_obligation_cause_code(
23052315
err,

src/test/ui/associated-types/associated-types-bound-failure.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `<G as GetToInt>::R: ToInt` is not satisfied
22
--> $DIR/associated-types-bound-failure.rs:19:19
33
|
44
LL | ToInt::to_int(&g.get())
5-
| ^^^^^^^^ the trait `ToInt` is not implemented for `<G as GetToInt>::R`
5+
| ------------- ^^^^^^^^ the trait `ToInt` is not implemented for `<G as GetToInt>::R`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by `ToInt::to_int`
810
--> $DIR/associated-types-bound-failure.rs:6:5

src/test/ui/associated-types/associated-types-path-2.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
1313
--> $DIR/associated-types-path-2.rs:29:14
1414
|
1515
LL | f1(2u32, 4u32);
16-
| ^^^^ the trait `Foo` is not implemented for `u32`
16+
| -- ^^^^ the trait `Foo` is not implemented for `u32`
17+
| |
18+
| required by a bound introduced by this call
1719
|
1820
note: required by a bound in `f1`
1921
--> $DIR/associated-types-path-2.rs:13:14
@@ -31,7 +33,9 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
3133
--> $DIR/associated-types-path-2.rs:35:14
3234
|
3335
LL | f1(2u32, 4i32);
34-
| ^^^^ the trait `Foo` is not implemented for `u32`
36+
| -- ^^^^ the trait `Foo` is not implemented for `u32`
37+
| |
38+
| required by a bound introduced by this call
3539
|
3640
note: required by a bound in `f1`
3741
--> $DIR/associated-types-path-2.rs:13:14

src/test/ui/associated-types/issue-27675-unchecked-bounds.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `T: Copy` is not satisfied
22
--> $DIR/issue-27675-unchecked-bounds.rs:15:31
33
|
44
LL | copy::<dyn Setup<From=T>>(t)
5-
| ^ the trait `Copy` is not implemented for `T`
5+
| ------------------------- ^ the trait `Copy` is not implemented for `T`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by a bound in `copy`
810
--> $DIR/issue-27675-unchecked-bounds.rs:10:12

src/test/ui/async-await/issue-72442.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `Option<&str>: AsRef<Path>` is not satisfied
22
--> $DIR/issue-72442.rs:12:36
33
|
44
LL | let mut f = File::open(path.to_str())?;
5-
| ^^^^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
5+
| ---------- ^^^^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by a bound in `File::open`
810
--> $SRC_DIR/std/src/fs.rs:LL:COL

src/test/ui/box/into-boxed-slice-fail.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
22
--> $DIR/into-boxed-slice-fail.rs:7:35
33
|
44
LL | let _ = Box::into_boxed_slice(boxed_slice);
5-
| ^^^^^^^^^^^ doesn't have a size known at compile-time
5+
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `Sized` is not implemented for `[u8]`
810
note: required by `Box::<T, A>::into_boxed_slice`
@@ -24,7 +26,9 @@ error[E0277]: the size for values of type `dyn Debug` cannot be known at compila
2426
--> $DIR/into-boxed-slice-fail.rs:11:35
2527
|
2628
LL | let _ = Box::into_boxed_slice(boxed_trait);
27-
| ^^^^^^^^^^^ doesn't have a size known at compile-time
29+
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
30+
| |
31+
| required by a bound introduced by this call
2832
|
2933
= help: the trait `Sized` is not implemented for `dyn Debug`
3034
note: required by `Box::<T, A>::into_boxed_slice`

src/test/ui/chalkify/type_inference.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `{float}: Bar` is not satisfied
22
--> $DIR/type_inference.rs:27:14
33
|
44
LL | only_bar(x);
5-
| ^ the trait `Bar` is not implemented for `{float}`
5+
| -------- ^ the trait `Bar` is not implemented for `{float}`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the following implementations were found:
810
<i32 as Bar>

src/test/ui/closure-expected.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: expected a `FnOnce<()>` closure, found `{integer}`
22
--> $DIR/closure-expected.rs:3:23
33
|
44
LL | let y = x.or_else(4);
5-
| ^ expected an `FnOnce<()>` closure, found `{integer}`
5+
| ------- ^ expected an `FnOnce<()>` closure, found `{integer}`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `FnOnce<()>` is not implemented for `{integer}`
810
= note: wrap the `{integer}` in a closure with no arguments: `|| { /* code */ }`

src/test/ui/closures/closure-bounds-subtype.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: `F` cannot be shared between threads safely
22
--> $DIR/closure-bounds-subtype.rs:13:22
33
|
44
LL | take_const_owned(f);
5-
| ^ `F` cannot be shared between threads safely
5+
| ---------------- ^ `F` cannot be shared between threads safely
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by a bound in `take_const_owned`
810
--> $DIR/closure-bounds-subtype.rs:4:50

src/test/ui/closures/coerce-unsafe-to-closure.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: expected a `FnOnce<(&str,)>` closure, found `unsafe extern "rust-i
22
--> $DIR/coerce-unsafe-to-closure.rs:2:44
33
|
44
LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
5-
| ^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
5+
| --- ^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `FnOnce<(&str,)>` is not implemented for `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
810

src/test/ui/coherence/coherence-unsafe-trait-object-impl.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `&dyn Trait: Trait` is not satisfied
22
--> $DIR/coherence-unsafe-trait-object-impl.rs:15:13
33
|
44
LL | takes_t(t);
5-
| ^ the trait `Trait` is not implemented for `&dyn Trait`
5+
| ------- ^ the trait `Trait` is not implemented for `&dyn Trait`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by a bound in `takes_t`
810
--> $DIR/coherence-unsafe-trait-object-impl.rs:10:15

src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ LL | #[derive(Clone)]
55
| ----- in this derive macro expansion
66
...
77
LL | x: Error
8-
| ^^^^^^^^ the trait `Clone` is not implemented for `Error`
8+
| ^^^^^^^^
9+
| |
10+
| the trait `Clone` is not implemented for `Error`
11+
| required by a bound introduced by this call
912
|
1013
note: required by `clone`
1114
--> $SRC_DIR/core/src/clone.rs:LL:COL

src/test/ui/derives/derives-span-Clone-enum.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ LL | #[derive(Clone)]
55
| ----- in this derive macro expansion
66
...
77
LL | Error
8-
| ^^^^^ the trait `Clone` is not implemented for `Error`
8+
| ^^^^^
9+
| |
10+
| the trait `Clone` is not implemented for `Error`
11+
| required by a bound introduced by this call
912
|
1013
note: required by `clone`
1114
--> $SRC_DIR/core/src/clone.rs:LL:COL

src/test/ui/derives/derives-span-Clone-struct.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ LL | #[derive(Clone)]
55
| ----- in this derive macro expansion
66
LL | struct Struct {
77
LL | x: Error
8-
| ^^^^^^^^ the trait `Clone` is not implemented for `Error`
8+
| ^^^^^^^^
9+
| |
10+
| the trait `Clone` is not implemented for `Error`
11+
| required by a bound introduced by this call
912
|
1013
note: required by `clone`
1114
--> $SRC_DIR/core/src/clone.rs:LL:COL

src/test/ui/derives/derives-span-Clone-tuple-struct.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ LL | #[derive(Clone)]
55
| ----- in this derive macro expansion
66
LL | struct Struct(
77
LL | Error
8-
| ^^^^^ the trait `Clone` is not implemented for `Error`
8+
| ^^^^^
9+
| |
10+
| the trait `Clone` is not implemented for `Error`
11+
| required by a bound introduced by this call
912
|
1013
note: required by `clone`
1114
--> $SRC_DIR/core/src/clone.rs:LL:COL

src/test/ui/derives/deriving-copyclone.stderr

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ error[E0277]: the trait bound `C: Copy` is not satisfied
22
--> $DIR/deriving-copyclone.rs:31:13
33
|
44
LL | is_copy(B { a: 1, b: C });
5-
| ^^^^^^^^^^^^^^^^
6-
| |
7-
| expected an implementor of trait `Copy`
8-
| help: consider borrowing here: `&B { a: 1, b: C }`
5+
| ------- ^^^^^^^^^^^^^^^^
6+
| | |
7+
| | expected an implementor of trait `Copy`
8+
| | help: consider borrowing here: `&B { a: 1, b: C }`
9+
| required by a bound introduced by this call
910
|
1011
note: required because of the requirements on the impl of `Copy` for `B<C>`
1112
--> $DIR/deriving-copyclone.rs:9:10
@@ -23,10 +24,11 @@ error[E0277]: the trait bound `C: Clone` is not satisfied
2324
--> $DIR/deriving-copyclone.rs:32:14
2425
|
2526
LL | is_clone(B { a: 1, b: C });
26-
| ^^^^^^^^^^^^^^^^
27-
| |
28-
| expected an implementor of trait `Clone`
29-
| help: consider borrowing here: `&B { a: 1, b: C }`
27+
| -------- ^^^^^^^^^^^^^^^^
28+
| | |
29+
| | expected an implementor of trait `Clone`
30+
| | help: consider borrowing here: `&B { a: 1, b: C }`
31+
| required by a bound introduced by this call
3032
|
3133
note: required because of the requirements on the impl of `Clone` for `B<C>`
3234
--> $DIR/deriving-copyclone.rs:9:16
@@ -44,10 +46,11 @@ error[E0277]: the trait bound `D: Copy` is not satisfied
4446
--> $DIR/deriving-copyclone.rs:35:13
4547
|
4648
LL | is_copy(B { a: 1, b: D });
47-
| ^^^^^^^^^^^^^^^^
48-
| |
49-
| expected an implementor of trait `Copy`
50-
| help: consider borrowing here: `&B { a: 1, b: D }`
49+
| ------- ^^^^^^^^^^^^^^^^
50+
| | |
51+
| | expected an implementor of trait `Copy`
52+
| | help: consider borrowing here: `&B { a: 1, b: D }`
53+
| required by a bound introduced by this call
5154
|
5255
note: required because of the requirements on the impl of `Copy` for `B<D>`
5356
--> $DIR/deriving-copyclone.rs:9:10

src/test/ui/derives/deriving-no-inner-impl-error-message.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ LL | #[derive(Clone)]
2929
| ----- in this derive macro expansion
3030
LL | struct C {
3131
LL | x: NoCloneOrEq
32-
| ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NoCloneOrEq`
32+
| ^^^^^^^^^^^^^^
33+
| |
34+
| the trait `Clone` is not implemented for `NoCloneOrEq`
35+
| required by a bound introduced by this call
3336
|
3437
note: required by `clone`
3538
--> $SRC_DIR/core/src/clone.rs:LL:COL

src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `i8: Foo<i32>` is not satisfied
22
--> $DIR/issue-39802-show-5-trait-impls.rs:24:21
33
|
44
LL | Foo::<i32>::bar(&1i8);
5-
| ^^^^ the trait `Foo<i32>` is not implemented for `i8`
5+
| --------------- ^^^^ the trait `Foo<i32>` is not implemented for `i8`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the following implementations were found:
810
<i8 as Foo<bool>>
@@ -20,7 +22,9 @@ error[E0277]: the trait bound `u8: Foo<i32>` is not satisfied
2022
--> $DIR/issue-39802-show-5-trait-impls.rs:25:21
2123
|
2224
LL | Foo::<i32>::bar(&1u8);
23-
| ^^^^ the trait `Foo<i32>` is not implemented for `u8`
25+
| --------------- ^^^^ the trait `Foo<i32>` is not implemented for `u8`
26+
| |
27+
| required by a bound introduced by this call
2428
|
2529
= help: the following implementations were found:
2630
<u8 as Foo<bool>>
@@ -37,7 +41,9 @@ error[E0277]: the trait bound `bool: Foo<i32>` is not satisfied
3741
--> $DIR/issue-39802-show-5-trait-impls.rs:26:21
3842
|
3943
LL | Foo::<i32>::bar(&true);
40-
| ^^^^^ the trait `Foo<i32>` is not implemented for `bool`
44+
| --------------- ^^^^^ the trait `Foo<i32>` is not implemented for `bool`
45+
| |
46+
| required by a bound introduced by this call
4147
|
4248
= help: the following implementations were found:
4349
<bool as Foo<bool>>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ error[E0277]: the trait bound `i32: Foo` is not satisfied
1616
--> $DIR/E0277.rs:15:15
1717
|
1818
LL | some_func(5i32);
19-
| ^^^^ the trait `Foo` is not implemented for `i32`
19+
| --------- ^^^^ the trait `Foo` is not implemented for `i32`
20+
| |
21+
| required by a bound introduced by this call
2022
|
2123
note: required by a bound in `some_func`
2224
--> $DIR/E0277.rs:7:17

src/test/ui/error-should-say-copy-not-pod.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
22
--> $DIR/error-should-say-copy-not-pod.rs:6:17
33
|
44
LL | check_bound("nocopy".to_string());
5-
| ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
5+
| ----------- ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by a bound in `check_bound`
810
--> $DIR/error-should-say-copy-not-pod.rs:3:18

src/test/ui/extern/extern-wrong-value-type.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: expected a `Fn<()>` closure, found `extern "C" fn() {f}`
22
--> $DIR/extern-wrong-value-type.rs:9:11
33
|
44
LL | is_fn(f);
5-
| ^ expected an `Fn<()>` closure, found `extern "C" fn() {f}`
5+
| ----- ^ expected an `Fn<()>` closure, found `extern "C" fn() {f}`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `Fn<()>` is not implemented for `extern "C" fn() {f}`
810
= note: wrap the `extern "C" fn() {f}` in a closure with no arguments: `|| { /* code */ }`

src/test/ui/fn/fn-trait-formatting.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ error[E0277]: expected a `Fn<(isize,)>` closure, found `{integer}`
3535
--> $DIR/fn-trait-formatting.rs:19:14
3636
|
3737
LL | needs_fn(1);
38-
| ^ expected an `Fn<(isize,)>` closure, found `{integer}`
38+
| -------- ^ expected an `Fn<(isize,)>` closure, found `{integer}`
39+
| |
40+
| required by a bound introduced by this call
3941
|
4042
= help: the trait `Fn<(isize,)>` is not implemented for `{integer}`
4143
note: required by a bound in `needs_fn`

src/test/ui/generator/static-not-unpin.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: `[static generator@$DIR/static-not-unpin.rs:11:25: 13:6]` cannot b
22
--> $DIR/static-not-unpin.rs:14:18
33
|
44
LL | assert_unpin(generator);
5-
| ^^^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/static-not-unpin.rs:11:25: 13:6]`
5+
| ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/static-not-unpin.rs:11:25: 13:6]`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= note: consider using `Box::pin`
810
note: required by a bound in `assert_unpin`

src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0631]: type mismatch in closure arguments
22
--> $DIR/issue-62529-1.rs:80:10
33
|
44
LL | task(annotate(
5-
| __________^
5+
| _____----_^
6+
| | |
7+
| | required by a bound introduced by this call
68
LL | |
79
LL | |
810
LL | | Annotate::<RefMutFamily<usize>>::new(),
@@ -26,7 +28,9 @@ error[E0277]: the size for values of type `impl Execute` cannot be known at comp
2628
--> $DIR/issue-62529-1.rs:80:10
2729
|
2830
LL | task(annotate(
29-
| __________^
31+
| _____----_^
32+
| | |
33+
| | required by a bound introduced by this call
3034
LL | |
3135
LL | |
3236
LL | | Annotate::<RefMutFamily<usize>>::new(),
@@ -50,7 +54,9 @@ error[E0277]: the trait bound `impl Execute: Execute` is not satisfied
5054
--> $DIR/issue-62529-1.rs:80:10
5155
|
5256
LL | task(annotate(
53-
| __________^
57+
| _____----_^
58+
| | |
59+
| | required by a bound introduced by this call
5460
LL | |
5561
LL | |
5662
LL | | Annotate::<RefMutFamily<usize>>::new(),

src/test/ui/hrtb/hrtb-higher-ranker-supertraits-transitive.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the trait bound `for<'ccx> B: Bar<'ccx>` is not satisfied
22
--> $DIR/hrtb-higher-ranker-supertraits-transitive.rs:47:26
33
|
44
LL | want_bar_for_any_ccx(b);
5-
| ^ the trait `for<'ccx> Bar<'ccx>` is not implemented for `B`
5+
| -------------------- ^ the trait `for<'ccx> Bar<'ccx>` is not implemented for `B`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by a bound in `want_bar_for_any_ccx`
810
--> $DIR/hrtb-higher-ranker-supertraits-transitive.rs:32:15

0 commit comments

Comments
 (0)