Repository: rust
Issue: Duplicate error messages when RPIT comes from function whose generics don't satisfy bounds
Labels: A-diagnostics,C-bug,D-confusing,D-verbose,T-types

<!--
Thank you for filing a regression report! 🐛 A regression is something that changed between versions of Rust but was not supposed to.

Please provide a short summary of the regression, along with any information you feel is relevant to replicate it.
-->

### Code

I tried this code:

```rust
use std::fmt::Display;

fn foo<T: Display>(x: T) -> impl Display {
    x
}

struct Bar; // does'nt impl `Display`

fn main() {
    let x = foo(Bar);
    println!("{}", x);
}
```

I expected to see this happen: 

The error to be reported on the call to `foo()` only:

```
error[E0277]: `Bar` doesn't implement `std::fmt::Display`
  --> src\lib.rs:10:17
   |
10 |     let x = foo(Bar);
   |             --- ^^^ `Bar` cannot be formatted with the default formatter
   |             |
   |             required by a bound introduced by this call
   |
   = help: the trait `std::fmt::Display` is not implemented for `Bar`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `foo`
  --> src\lib.rs:3:11
   |
3  | fn foo<T: Display>(x: T) -> impl Display {
   |           ^^^^^^^ required by this bound in `foo`

For more information about this error, try `rustc --explain E0277`.
```

Instead, this happened:

The error is propagated to the use of the `println!` macro call, without supposing `x` to implement `Display`:

```
error[E0277]: `Bar` doesn't implement `std::fmt::Display`
  --> src\lib.rs:10:17
   |
10 |     let x = foo(Bar);
   |             --- ^^^ `Bar` cannot be formatted with the default formatter
   |             |
   |             required by a bound introduced by this call
   |
   = help: the trait `std::fmt::Display` is not implemented for `Bar`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `foo`
  --> src\lib.rs:3:11
   |
3  | fn foo<T: Display>(x: T) -> impl Display {
   |           ^^^^^^^ required by this bound in `foo`

error[E0277]: `Bar` doesn't implement `std::fmt::Display`
  --> src\lib.rs:10:13
   |
10 |     let x = foo(Bar);
   |             ^^^^^^^^ `Bar` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Bar`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `foo`
  --> src\lib.rs:3:11
   |
3  | fn foo<T: Display>(x: T) -> impl Display {
   |           ^^^^^^^ required by this bound in `foo`

error[E0277]: `Bar` doesn't implement `std::fmt::Display`
  --> src\lib.rs:11:15
   |
11 |     println!("{}", x);
   |               ^^ `Bar` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Bar`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
```

### Version it worked on

<!--
Provide the most recent version this worked on, for example:

It most recently worked on: Rust 1.47
-->

It most recently worked on: Rust 1.77

### Version with regression

<!--
Provide the version you are using that has the regression.
-->

`rustc --version --verbose`:
```
rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: x86_64-pc-windows-msvc
release: 1.80.0
LLVM version: 18.1.7
```

<!--
Did the compiler crash? If so, please provide a backtrace.
-->

### Backtrace
<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
<backtrace>
```

</p>
</details>

<!--
If you know when this regression occurred, please add a line like below, replacing `{channel}` with one of stable, beta, or nightly.

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
-->