Skip to content

Commit

Permalink
Point at call span that introduced obligation for the arg
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Sep 16, 2021
1 parent 8a3f712 commit 569a842
Show file tree
Hide file tree
Showing 94 changed files with 668 additions and 250 deletions.
Expand Up @@ -2297,9 +2297,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
ObligationCauseCode::FunctionArgumentObligation {
arg_hir_id: _,
call_hir_id: _,
call_hir_id,
ref parent_code,
} => {
let hir = self.tcx.hir();
if let Some(Node::Expr(hir::Expr {
kind:
hir::ExprKind::Call(hir::Expr { span, .. }, _)
| hir::ExprKind::MethodCall(_, span, ..),
..
})) = hir.find(call_hir_id)
{
err.span_label(*span, "required by a bound in this call");
}
ensure_sufficient_stack(|| {
self.note_obligation_cause_code(
err,
Expand Down
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `<G as GetToInt>::R: ToInt` is not satisfied
--> $DIR/associated-types-bound-failure.rs:19:19
|
LL | ToInt::to_int(&g.get())
| ^^^^^^^^ the trait `ToInt` is not implemented for `<G as GetToInt>::R`
| ------------- ^^^^^^^^ the trait `ToInt` is not implemented for `<G as GetToInt>::R`
| |
| required by a bound introduced by this call
|
note: required by `ToInt::to_int`
--> $DIR/associated-types-bound-failure.rs:6:5
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/associated-types/associated-types-path-2.stderr
Expand Up @@ -13,7 +13,9 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:29:14
|
LL | f1(2u32, 4u32);
| ^^^^ the trait `Foo` is not implemented for `u32`
| -- ^^^^ the trait `Foo` is not implemented for `u32`
| |
| required by a bound introduced by this call
|
note: required by a bound in `f1`
--> $DIR/associated-types-path-2.rs:13:14
Expand All @@ -31,7 +33,9 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:35:14
|
LL | f1(2u32, 4i32);
| ^^^^ the trait `Foo` is not implemented for `u32`
| -- ^^^^ the trait `Foo` is not implemented for `u32`
| |
| required by a bound introduced by this call
|
note: required by a bound in `f1`
--> $DIR/associated-types-path-2.rs:13:14
Expand Down
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `T: Copy` is not satisfied
--> $DIR/issue-27675-unchecked-bounds.rs:15:31
|
LL | copy::<dyn Setup<From=T>>(t)
| ^ the trait `Copy` is not implemented for `T`
| ------------------------- ^ the trait `Copy` is not implemented for `T`
| |
| required by a bound introduced by this call
|
note: required by a bound in `copy`
--> $DIR/issue-27675-unchecked-bounds.rs:10:12
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/async-await/issue-72442.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `Option<&str>: AsRef<Path>` is not satisfied
--> $DIR/issue-72442.rs:12:36
|
LL | let mut f = File::open(path.to_str())?;
| ^^^^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
| ---------- ^^^^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
| |
| required by a bound introduced by this call
|
note: required by a bound in `File::open`
--> $SRC_DIR/std/src/fs.rs:LL:COL
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/box/into-boxed-slice-fail.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
--> $DIR/into-boxed-slice-fail.rs:7:35
|
LL | let _ = Box::into_boxed_slice(boxed_slice);
| ^^^^^^^^^^^ doesn't have a size known at compile-time
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `[u8]`
note: required by `Box::<T, A>::into_boxed_slice`
Expand All @@ -24,7 +26,9 @@ error[E0277]: the size for values of type `dyn Debug` cannot be known at compila
--> $DIR/into-boxed-slice-fail.rs:11:35
|
LL | let _ = Box::into_boxed_slice(boxed_trait);
| ^^^^^^^^^^^ doesn't have a size known at compile-time
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `dyn Debug`
note: required by `Box::<T, A>::into_boxed_slice`
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/chalkify/type_inference.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `{float}: Bar` is not satisfied
--> $DIR/type_inference.rs:27:14
|
LL | only_bar(x);
| ^ the trait `Bar` is not implemented for `{float}`
| -------- ^ the trait `Bar` is not implemented for `{float}`
| |
| required by a bound introduced by this call
|
= help: the following implementations were found:
<i32 as Bar>
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/closure-expected.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: expected a `FnOnce<()>` closure, found `{integer}`
--> $DIR/closure-expected.rs:3:23
|
LL | let y = x.or_else(4);
| ^ expected an `FnOnce<()>` closure, found `{integer}`
| ------- ^ expected an `FnOnce<()>` closure, found `{integer}`
| |
| required by a bound introduced by this call
|
= help: the trait `FnOnce<()>` is not implemented for `{integer}`
= note: wrap the `{integer}` in a closure with no arguments: `|| { /* code */ }`
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/closures/closure-bounds-subtype.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: `F` cannot be shared between threads safely
--> $DIR/closure-bounds-subtype.rs:13:22
|
LL | take_const_owned(f);
| ^ `F` cannot be shared between threads safely
| ---------------- ^ `F` cannot be shared between threads safely
| |
| required by a bound introduced by this call
|
note: required by a bound in `take_const_owned`
--> $DIR/closure-bounds-subtype.rs:4:50
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/closures/coerce-unsafe-to-closure.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: expected a `FnOnce<(&str,)>` closure, found `unsafe extern "rust-i
--> $DIR/coerce-unsafe-to-closure.rs:2:44
|
LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
| ^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
| --- ^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
| |
| required by a bound introduced by this call
|
= help: the trait `FnOnce<(&str,)>` is not implemented for `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`

Expand Down
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `&dyn Trait: Trait` is not satisfied
--> $DIR/coherence-unsafe-trait-object-impl.rs:15:13
|
LL | takes_t(t);
| ^ the trait `Trait` is not implemented for `&dyn Trait`
| ------- ^ the trait `Trait` is not implemented for `&dyn Trait`
| |
| required by a bound introduced by this call
|
note: required by a bound in `takes_t`
--> $DIR/coherence-unsafe-trait-object-impl.rs:10:15
Expand Down
Expand Up @@ -5,7 +5,10 @@ LL | #[derive(Clone)]
| ----- in this derive macro expansion
...
LL | x: Error
| ^^^^^^^^ the trait `Clone` is not implemented for `Error`
| ^^^^^^^^
| |
| the trait `Clone` is not implemented for `Error`
| required by a bound introduced by this call
|
note: required by `clone`
--> $SRC_DIR/core/src/clone.rs:LL:COL
Expand Down
5 changes: 4 additions & 1 deletion src/test/ui/derives/derives-span-Clone-enum.stderr
Expand Up @@ -5,7 +5,10 @@ LL | #[derive(Clone)]
| ----- in this derive macro expansion
...
LL | Error
| ^^^^^ the trait `Clone` is not implemented for `Error`
| ^^^^^
| |
| the trait `Clone` is not implemented for `Error`
| required by a bound introduced by this call
|
note: required by `clone`
--> $SRC_DIR/core/src/clone.rs:LL:COL
Expand Down
5 changes: 4 additions & 1 deletion src/test/ui/derives/derives-span-Clone-struct.stderr
Expand Up @@ -5,7 +5,10 @@ LL | #[derive(Clone)]
| ----- in this derive macro expansion
LL | struct Struct {
LL | x: Error
| ^^^^^^^^ the trait `Clone` is not implemented for `Error`
| ^^^^^^^^
| |
| the trait `Clone` is not implemented for `Error`
| required by a bound introduced by this call
|
note: required by `clone`
--> $SRC_DIR/core/src/clone.rs:LL:COL
Expand Down
5 changes: 4 additions & 1 deletion src/test/ui/derives/derives-span-Clone-tuple-struct.stderr
Expand Up @@ -5,7 +5,10 @@ LL | #[derive(Clone)]
| ----- in this derive macro expansion
LL | struct Struct(
LL | Error
| ^^^^^ the trait `Clone` is not implemented for `Error`
| ^^^^^
| |
| the trait `Clone` is not implemented for `Error`
| required by a bound introduced by this call
|
note: required by `clone`
--> $SRC_DIR/core/src/clone.rs:LL:COL
Expand Down
27 changes: 15 additions & 12 deletions src/test/ui/derives/deriving-copyclone.stderr
Expand Up @@ -2,10 +2,11 @@ error[E0277]: the trait bound `C: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:31:13
|
LL | is_copy(B { a: 1, b: C });
| ^^^^^^^^^^^^^^^^
| |
| expected an implementor of trait `Copy`
| help: consider borrowing here: `&B { a: 1, b: C }`
| ------- ^^^^^^^^^^^^^^^^
| | |
| | expected an implementor of trait `Copy`
| | help: consider borrowing here: `&B { a: 1, b: C }`
| required by a bound introduced by this call
|
note: required because of the requirements on the impl of `Copy` for `B<C>`
--> $DIR/deriving-copyclone.rs:9:10
Expand All @@ -23,10 +24,11 @@ error[E0277]: the trait bound `C: Clone` is not satisfied
--> $DIR/deriving-copyclone.rs:32:14
|
LL | is_clone(B { a: 1, b: C });
| ^^^^^^^^^^^^^^^^
| |
| expected an implementor of trait `Clone`
| help: consider borrowing here: `&B { a: 1, b: C }`
| -------- ^^^^^^^^^^^^^^^^
| | |
| | expected an implementor of trait `Clone`
| | help: consider borrowing here: `&B { a: 1, b: C }`
| required by a bound introduced by this call
|
note: required because of the requirements on the impl of `Clone` for `B<C>`
--> $DIR/deriving-copyclone.rs:9:16
Expand All @@ -44,10 +46,11 @@ error[E0277]: the trait bound `D: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:35:13
|
LL | is_copy(B { a: 1, b: D });
| ^^^^^^^^^^^^^^^^
| |
| expected an implementor of trait `Copy`
| help: consider borrowing here: `&B { a: 1, b: D }`
| ------- ^^^^^^^^^^^^^^^^
| | |
| | expected an implementor of trait `Copy`
| | help: consider borrowing here: `&B { a: 1, b: D }`
| required by a bound introduced by this call
|
note: required because of the requirements on the impl of `Copy` for `B<D>`
--> $DIR/deriving-copyclone.rs:9:10
Expand Down
Expand Up @@ -29,7 +29,10 @@ LL | #[derive(Clone)]
| ----- in this derive macro expansion
LL | struct C {
LL | x: NoCloneOrEq
| ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NoCloneOrEq`
| ^^^^^^^^^^^^^^
| |
| the trait `Clone` is not implemented for `NoCloneOrEq`
| required by a bound introduced by this call
|
note: required by `clone`
--> $SRC_DIR/core/src/clone.rs:LL:COL
Expand Down
12 changes: 9 additions & 3 deletions src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `i8: Foo<i32>` is not satisfied
--> $DIR/issue-39802-show-5-trait-impls.rs:24:21
|
LL | Foo::<i32>::bar(&1i8);
| ^^^^ the trait `Foo<i32>` is not implemented for `i8`
| --------------- ^^^^ the trait `Foo<i32>` is not implemented for `i8`
| |
| required by a bound introduced by this call
|
= help: the following implementations were found:
<i8 as Foo<bool>>
Expand All @@ -20,7 +22,9 @@ error[E0277]: the trait bound `u8: Foo<i32>` is not satisfied
--> $DIR/issue-39802-show-5-trait-impls.rs:25:21
|
LL | Foo::<i32>::bar(&1u8);
| ^^^^ the trait `Foo<i32>` is not implemented for `u8`
| --------------- ^^^^ the trait `Foo<i32>` is not implemented for `u8`
| |
| required by a bound introduced by this call
|
= help: the following implementations were found:
<u8 as Foo<bool>>
Expand All @@ -37,7 +41,9 @@ error[E0277]: the trait bound `bool: Foo<i32>` is not satisfied
--> $DIR/issue-39802-show-5-trait-impls.rs:26:21
|
LL | Foo::<i32>::bar(&true);
| ^^^^^ the trait `Foo<i32>` is not implemented for `bool`
| --------------- ^^^^^ the trait `Foo<i32>` is not implemented for `bool`
| |
| required by a bound introduced by this call
|
= help: the following implementations were found:
<bool as Foo<bool>>
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/error-codes/E0277.stderr
Expand Up @@ -16,7 +16,9 @@ error[E0277]: the trait bound `i32: Foo` is not satisfied
--> $DIR/E0277.rs:15:15
|
LL | some_func(5i32);
| ^^^^ the trait `Foo` is not implemented for `i32`
| --------- ^^^^ the trait `Foo` is not implemented for `i32`
| |
| required by a bound introduced by this call
|
note: required by a bound in `some_func`
--> $DIR/E0277.rs:7:17
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/error-should-say-copy-not-pod.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/error-should-say-copy-not-pod.rs:6:17
|
LL | check_bound("nocopy".to_string());
| ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
| ----------- ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
| |
| required by a bound introduced by this call
|
note: required by a bound in `check_bound`
--> $DIR/error-should-say-copy-not-pod.rs:3:18
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/extern/extern-wrong-value-type.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: expected a `Fn<()>` closure, found `extern "C" fn() {f}`
--> $DIR/extern-wrong-value-type.rs:9:11
|
LL | is_fn(f);
| ^ expected an `Fn<()>` closure, found `extern "C" fn() {f}`
| ----- ^ expected an `Fn<()>` closure, found `extern "C" fn() {f}`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn<()>` is not implemented for `extern "C" fn() {f}`
= note: wrap the `extern "C" fn() {f}` in a closure with no arguments: `|| { /* code */ }`
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/fn/fn-trait-formatting.stderr
Expand Up @@ -35,7 +35,9 @@ error[E0277]: expected a `Fn<(isize,)>` closure, found `{integer}`
--> $DIR/fn-trait-formatting.rs:19:14
|
LL | needs_fn(1);
| ^ expected an `Fn<(isize,)>` closure, found `{integer}`
| -------- ^ expected an `Fn<(isize,)>` closure, found `{integer}`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn<(isize,)>` is not implemented for `{integer}`
note: required by a bound in `needs_fn`
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/generator/static-not-unpin.stderr
Expand Up @@ -2,7 +2,9 @@ error[E0277]: `[static generator@$DIR/static-not-unpin.rs:11:25: 13:6]` cannot b
--> $DIR/static-not-unpin.rs:14:18
|
LL | assert_unpin(generator);
| ^^^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/static-not-unpin.rs:11:25: 13:6]`
| ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/static-not-unpin.rs:11:25: 13:6]`
| |
| required by a bound introduced by this call
|
= note: consider using `Box::pin`
note: required by a bound in `assert_unpin`
Expand Down
Expand Up @@ -2,7 +2,9 @@ error[E0631]: type mismatch in closure arguments
--> $DIR/issue-62529-1.rs:80:10
|
LL | task(annotate(
| __________^
| _____----_^
| | |
| | required by a bound introduced by this call
LL | |
LL | |
LL | | Annotate::<RefMutFamily<usize>>::new(),
Expand All @@ -26,7 +28,9 @@ error[E0277]: the size for values of type `impl Execute` cannot be known at comp
--> $DIR/issue-62529-1.rs:80:10
|
LL | task(annotate(
| __________^
| _____----_^
| | |
| | required by a bound introduced by this call
LL | |
LL | |
LL | | Annotate::<RefMutFamily<usize>>::new(),
Expand All @@ -50,7 +54,9 @@ error[E0277]: the trait bound `impl Execute: Execute` is not satisfied
--> $DIR/issue-62529-1.rs:80:10
|
LL | task(annotate(
| __________^
| _____----_^
| | |
| | required by a bound introduced by this call
LL | |
LL | |
LL | | Annotate::<RefMutFamily<usize>>::new(),
Expand Down
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the trait bound `for<'ccx> B: Bar<'ccx>` is not satisfied
--> $DIR/hrtb-higher-ranker-supertraits-transitive.rs:47:26
|
LL | want_bar_for_any_ccx(b);
| ^ the trait `for<'ccx> Bar<'ccx>` is not implemented for `B`
| -------------------- ^ the trait `for<'ccx> Bar<'ccx>` is not implemented for `B`
| |
| required by a bound introduced by this call
|
note: required by a bound in `want_bar_for_any_ccx`
--> $DIR/hrtb-higher-ranker-supertraits-transitive.rs:32:15
Expand Down

0 comments on commit 569a842

Please sign in to comment.