rust/compiler/rustc_hir_analysis/src/check
Michael Goulet 341d6dfba5
Rollup merge of #106038 - aliemjay:opaque-implied, r=lcnr
use implied bounds when checking opaque types

During opaque type inference, we check for the well-formedness of the hidden type in the opaque type's own environment, not the one of the defining site, which are different in the case of TAIT.

However in the case of associated-type-impl-trait, we don't use implied bounds from the impl header. This caused us to reject the following:
```rust
trait Service<Req> {
    type Output;
    fn call(req: Req) -> Self::Output;
}

impl<'a, Req> Service<&'a Req> for u8 {
    type Output= impl Sized; // we can't prove WF of hidden type  `WF(&'a Req)` although it's implied by the impl
    //~^ ERROR type parameter Req doesn't live long enough
    fn call(req: &'a Req) -> Self::Output {
        req
    }
}
```

although adding an explicit bound would make it pass:
```diff
- impl<'a, Req> Service<&'a Req> for u8 {
+ impl<'a, Req> Service<&'a Req> for u8  where Req: 'a, {
```

I believe it should pass as we already allow the concrete type to be used:
```diff
impl<'a, Req> Service<&'a Req> for u8 {
-    type Output= impl Sized;
+    type Output= &'a Req;
```

Fixes #95922

Builds on #105982

cc ``@lcnr`` (because implied bounds)

r? ``@oli-obk``
2023-05-11 17:43:06 -07:00
..
check.rs use implied bounds when checking opaque types 2023-05-07 01:41:20 +03:00
compare_impl_item.rs Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum 2023-05-08 04:50:28 +00:00
dropck.rs Use fulfillment to check Drop impl compatibility 2023-05-04 18:05:58 +00:00
intrinsic.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
intrinsicck.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
mod.rs Migrate rustc_hir_analysis to session diagnostic 2023-04-21 23:50:03 +03:00
region.rs remove unused muts 2023-04-28 20:19:48 +02:00
wfcheck.rs Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnr 2023-05-04 05:54:09 +00:00