Point at tail expression on rpit E0277

```
error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}: Coroutine` is not satisfied
  --> $DIR/gen_block_is_coro.rs:6:13
   |
LL | fn foo() -> impl Coroutine<Yield = u32, Return = ()> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}`
LL |     gen { yield 42 }
   |     ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` here
```

The secondary span label is new.
This commit is contained in:
Esteban Küber 2024-10-25 04:38:48 +00:00
parent 86b5965608
commit 092ecca5b9
20 changed files with 121 additions and 32 deletions

View File

@ -3563,17 +3563,34 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
)]);
}
ObligationCauseCode::OpaqueReturnType(expr_info) => {
if let Some((expr_ty, hir_id)) = expr_info {
let expr_ty = self.tcx.short_ty_string(expr_ty, long_ty_file);
let expr = self.infcx.tcx.hir().expect_expr(hir_id);
err.span_label(
expr.span,
with_forced_trimmed_paths!(format!(
"return type was inferred to be `{expr_ty}` here",
)),
);
suggest_remove_deref(err, &expr);
}
let (expr_ty, expr) = if let Some((expr_ty, hir_id)) = expr_info {
let expr_ty = tcx.short_ty_string(expr_ty, long_ty_file);
let expr = tcx.hir().expect_expr(hir_id);
(expr_ty, expr)
} else if let Some(body_id) = tcx.hir_node_by_def_id(body_id).body_id()
&& let body = tcx.hir().body(body_id)
&& let hir::ExprKind::Block(block, _) = body.value.kind
&& let Some(expr) = block.expr
&& let Some(expr_ty) = self
.typeck_results
.as_ref()
.and_then(|typeck| typeck.node_type_opt(expr.hir_id))
&& let Some(pred) = predicate.as_clause()
&& let ty::ClauseKind::Trait(pred) = pred.kind().skip_binder()
&& self.can_eq(param_env, pred.self_ty(), expr_ty)
{
let expr_ty = tcx.short_ty_string(expr_ty, long_ty_file);
(expr_ty, expr)
} else {
return;
};
err.span_label(
expr.span,
with_forced_trimmed_paths!(format!(
"return type was inferred to be `{expr_ty}` here",
)),
);
suggest_remove_deref(err, &expr);
}
}
}

View File

@ -3,6 +3,9 @@ error[E0277]: `()` is not a future
|
LL | fn get_future() -> impl Future<Output = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future
LL |
LL | panic!()
| -------- return type was inferred to be `_` here
|
= help: the trait `Future` is not implemented for `()`

View File

@ -5,7 +5,10 @@ LL | fn foo() -> impl Coroutine<u8> {
| ^^^^^^^^^^^^^^^^^^ expected due to this
...
LL | |_: ()| {}
| ------- found signature defined here
| ----------
| |
| found signature defined here
| return type was inferred to be `{coroutine@$DIR/arg-count-mismatch-on-unit-input.rs:8:5: 8:12}` here
|
= note: expected coroutine signature `fn(u8) -> _`
found coroutine signature `fn(()) -> _`

View File

@ -3,18 +3,24 @@ error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}: C
|
LL | fn foo() -> impl Coroutine<Yield = u32, Return = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}`
LL | gen { yield 42 }
| ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` here
error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:11:5: 11:8}: Coroutine` is not satisfied
--> $DIR/gen_block_is_coro.rs:10:13
|
LL | fn bar() -> impl Coroutine<Yield = i64, Return = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:11:5: 11:8}`
LL | gen { yield 42 }
| ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:11:5: 11:8}` here
error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:15:5: 15:8}: Coroutine` is not satisfied
--> $DIR/gen_block_is_coro.rs:14:13
|
LL | fn baz() -> impl Coroutine<Yield = i32, Return = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:15:5: 15:8}`
LL | gen { yield 42 }
| ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:15:5: 15:8}` here
error: aborting due to 3 previous errors

View File

@ -3,6 +3,8 @@ error[E0277]: `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}` is not a fut
|
LL | fn foo() -> impl std::future::Future {
| ^^^^^^^^^^^^^^^^^^^^^^^^ `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}` is not a future
LL | gen { yield 42 }
| ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}` here
|
= help: the trait `Future` is not implemented for `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}`

View File

@ -14,6 +14,7 @@ fn foo(bar: bool) -> impl Coroutine<(bool,)> {
#[coroutine]
|bar| {
//~^ NOTE: found signature defined here
//~| NOTE: return type was inferred to be
if bar {
yield bar;
}

View File

@ -1,11 +1,21 @@
error[E0631]: type mismatch in coroutine arguments
--> $DIR/issue-88653.rs:8:22
|
LL | fn foo(bar: bool) -> impl Coroutine<(bool,)> {
| ^^^^^^^^^^^^^^^^^^^^^^^ expected due to this
LL | fn foo(bar: bool) -> impl Coroutine<(bool,)> {
| ^^^^^^^^^^^^^^^^^^^^^^^ expected due to this
...
LL | |bar| {
| ----- found signature defined here
LL | |bar| {
| -----
| |
| _____found signature defined here
| |
LL | |
LL | |
LL | | if bar {
LL | | yield bar;
LL | | }
LL | | }
| |_____- return type was inferred to be `{coroutine@$DIR/issue-88653.rs:15:5: 15:10}` here
|
= note: expected coroutine signature `fn((bool,)) -> _`
found coroutine signature `fn(bool) -> _`

View File

@ -1,4 +1,4 @@
<svg width="1104px" height="362px" xmlns="http://www.w3.org/2000/svg">
<svg width="1104px" height="398px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -31,33 +31,37 @@
</tspan>
<tspan x="10px" y="100px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">^^^^^^^^^^^^^</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">the trait `Bar&lt;i32&gt;` is not implemented for `Struct`</tspan>
</tspan>
<tspan x="10px" y="118px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
<tspan x="10px" y="118px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> Struct</tspan>
</tspan>
<tspan x="10px" y="136px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: the trait `Bar&lt;</tspan><tspan class="fg-magenta bold">i32</tspan><tspan>&gt;` </tspan><tspan class="fg-magenta bold">is not</tspan><tspan> implemented for `Struct`</tspan>
<tspan x="10px" y="136px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">------</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">return type was inferred to be `Struct` here</tspan>
</tspan>
<tspan x="10px" y="154px"><tspan> but trait `Bar&lt;</tspan><tspan class="fg-magenta bold">()</tspan><tspan>&gt;` </tspan><tspan class="fg-magenta bold">is</tspan><tspan> implemented for it</tspan>
<tspan x="10px" y="154px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="172px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: for that trait implementation, expected `</tspan><tspan class="fg-magenta bold">()</tspan><tspan>`, found `</tspan><tspan class="fg-magenta bold">i32</tspan><tspan>`</tspan>
<tspan x="10px" y="172px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: the trait `Bar&lt;</tspan><tspan class="fg-magenta bold">i32</tspan><tspan>&gt;` </tspan><tspan class="fg-magenta bold">is not</tspan><tspan> implemented for `Struct`</tspan>
</tspan>
<tspan x="10px" y="190px"><tspan class="fg-ansi256-010 bold">note</tspan><tspan>: required for `Struct` to implement `Foo&lt;i32&gt;`</tspan>
<tspan x="10px" y="190px"><tspan> but trait `Bar&lt;</tspan><tspan class="fg-magenta bold">()</tspan><tspan>&gt;` </tspan><tspan class="fg-magenta bold">is</tspan><tspan> implemented for it</tspan>
</tspan>
<tspan x="10px" y="208px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">--&gt; </tspan><tspan>$DIR/highlight-difference-between-expected-trait-and-found-trait.rs:11:12</tspan>
<tspan x="10px" y="208px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: for that trait implementation, expected `</tspan><tspan class="fg-magenta bold">()</tspan><tspan>`, found `</tspan><tspan class="fg-magenta bold">i32</tspan><tspan>`</tspan>
</tspan>
<tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
<tspan x="10px" y="226px"><tspan class="fg-ansi256-010 bold">note</tspan><tspan>: required for `Struct` to implement `Foo&lt;i32&gt;`</tspan>
</tspan>
<tspan x="10px" y="244px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> impl&lt;T, K&gt; Foo&lt;K&gt; for T where T: Bar&lt;K&gt;</tspan>
<tspan x="10px" y="244px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">--&gt; </tspan><tspan>$DIR/highlight-difference-between-expected-trait-and-found-trait.rs:11:12</tspan>
</tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-010 bold">^^^^^^</tspan><tspan> </tspan><tspan class="fg-ansi256-010 bold">^</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">------</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">unsatisfied trait bound introduced here</tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
</tspan>
<tspan x="10px" y="280px">
<tspan x="10px" y="280px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> impl&lt;T, K&gt; Foo&lt;K&gt; for T where T: Bar&lt;K&gt;</tspan>
</tspan>
<tspan x="10px" y="298px"><tspan class="fg-ansi256-009 bold">error</tspan><tspan class="bold">: aborting due to 1 previous error</tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-010 bold">^^^^^^</tspan><tspan> </tspan><tspan class="fg-ansi256-010 bold">^</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">------</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">unsatisfied trait bound introduced here</tspan>
</tspan>
<tspan x="10px" y="316px">
</tspan>
<tspan x="10px" y="334px"><tspan class="bold">For more information about this error, try `rustc --explain E0277`.</tspan>
<tspan x="10px" y="334px"><tspan class="fg-ansi256-009 bold">error</tspan><tspan class="bold">: aborting due to 1 previous error</tspan>
</tspan>
<tspan x="10px" y="352px">
</tspan>
<tspan x="10px" y="370px"><tspan class="bold">For more information about this error, try `rustc --explain E0277`.</tspan>
</tspan>
<tspan x="10px" y="388px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -12,6 +12,9 @@ error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
|
LL | fn foo<T: Default>() -> Self::E {
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
...
LL | (S::default(), T::default())
| ---------------------------- return type was inferred to be `(S, T)` here
|
= note: required because it appears within the type `(S, T)`
help: consider further restricting this bound
@ -24,6 +27,9 @@ error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)`
|
LL | fn foo<T: Default>() -> Self::E {
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
...
LL | (S::default(), T::default())
| ---------------------------- return type was inferred to be `(S, T)` here
|
= note: required because it appears within the type `(S, T)`
help: consider further restricting this bound

View File

@ -3,6 +3,9 @@ error[E0277]: the trait bound `{async block@$DIR/issue-55872-3.rs:15:9: 15:14}:
|
LL | fn foo<T>() -> Self::E {
| ^^^^^^^ the trait `Copy` is not implemented for `{async block@$DIR/issue-55872-3.rs:15:9: 15:14}`
LL |
LL | async {}
| -------- return type was inferred to be `{async block@$DIR/issue-55872-3.rs:15:9: 15:14}` here
error: aborting due to 1 previous error

View File

@ -46,7 +46,9 @@ error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfie
--> $DIR/nested_impl_trait.rs:6:46
|
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
| ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into<u32>` here
| |
| the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
|
= help: the trait `Into<U>` is implemented for `T`
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
@ -55,7 +57,9 @@ error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfie
--> $DIR/nested_impl_trait.rs:19:34
|
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
| ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into<u32>` here
| |
| the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
|
= help: the trait `Into<U>` is implemented for `T`
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`

View File

@ -3,6 +3,9 @@ error[E0283]: type annotations needed
|
LL | fn run() -> Foo<impl Future<Output = ()>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
LL |
LL | loop {}
| ------- return type was inferred to be `!` here
|
= note: cannot satisfy `_: Future`

View File

@ -3,6 +3,9 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()`
|
LL | fn test() -> impl Test {
| ^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == ()`
LL |
LL | ()
| -- return type was inferred to be `()` here
|
note: expected this to be `()`
--> $DIR/projection-mismatch-in-impl-where-clause.rs:6:18

View File

@ -3,6 +3,9 @@ error[E0277]: the trait bound `Result<(), _>: Future` is not satisfied
|
LL | fn foo() -> impl Future<Item=(), Error=Box<dyn Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Future` is not implemented for `Result<(), _>`
LL |
LL | Ok(())
| ------ return type was inferred to be `Result<(), _>` here
|
help: this trait has no implementations, consider adding one
--> $DIR/lifetime-elision-return-type-trait.rs:1:1

View File

@ -3,6 +3,9 @@ error[E0271]: expected `foo` to be a fn item that returns `i32`, but it returns
|
LL | fn bar() -> impl Iterator<Item = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()`
...
LL | x.iter_mut().map(foo)
| --------------------- return type was inferred to be `Map<std::slice::IterMut<'_, Vec<u8>>, for<'a> fn(&'a mut Vec<u8>) {foo}>` here
|
= note: required for `Map<std::slice::IterMut<'_, Vec<u8>>, for<'a> fn(&'a mut Vec<u8>) {foo}>` to implement `Iterator`

View File

@ -3,6 +3,9 @@ error[E0277]: the trait bound `(): T` is not satisfied
|
LL | fn should_ret_unit() -> impl T {
| ^^^^^^ the trait `T` is not implemented for `()`
LL |
LL | panic!()
| -------- return type was inferred to be `_` here
|
= help: the trait `T` is implemented for `i32`
@ -11,6 +14,9 @@ error[E0277]: the trait bound `(): T` is not satisfied
|
LL | fn a() -> Foo {
| ^^^ the trait `T` is not implemented for `()`
LL |
LL | panic!()
| -------- return type was inferred to be `_` here
|
= help: the trait `T` is implemented for `i32`

View File

@ -3,6 +3,9 @@ error[E0277]: the trait bound `(): T` is not satisfied
|
LL | fn a() -> Foo {
| ^^^ the trait `T` is not implemented for `()`
...
LL | panic!()
| -------- return type was inferred to be `_` here
|
help: this trait has no implementations, consider adding one
--> $DIR/impl_trait_fallback3.rs:5:1

View File

@ -3,6 +3,9 @@ error[E0277]: the trait bound `(): T` is not satisfied
|
LL | fn foo() -> impl T {
| ^^^^^^ the trait `T` is not implemented for `()`
LL |
LL | panic!()
| -------- return type was inferred to be `_` here
|
help: this trait has no implementations, consider adding one
--> $DIR/impl_trait_fallback4.rs:3:1

View File

@ -4,7 +4,10 @@ error[E0283]: type annotations needed
LL | fn unconstrained_foo() -> Wrapper<Foo> {
| ------------ type must be known at this point
LL | Wrapper::Second
| ^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the enum `Wrapper`
| ^^^^^^^^^^^^^^^
| |
| cannot infer type of the type parameter `T` declared on the enum `Wrapper`
| return type was inferred to be `Wrapper<_>` here
|
= note: cannot satisfy `_: Copy`
help: consider specifying the generic argument

View File

@ -17,6 +17,9 @@ error[E0277]: the trait bound `{integer}: Trait<()>` is not satisfied
|
LL | fn produce() -> impl for<T> Trait<(), Assoc = impl Trait<T>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<()>` is not implemented for `{integer}`
...
LL | 16
| -- return type was inferred to be `{integer}` here
|
help: this trait has no implementations, consider adding one
--> $DIR/non-lifetime-binder-in-constraint.rs:4:1