1
Fork 0
rust/compiler/rustc_ty_utils/src
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
..
abi.rs Support TLS access into dylibs on Windows 2023-03-29 08:55:21 +02:00
assoc.rs Make generics_of has_self on RPITITs delegate to the opaque 2023-05-05 16:24:51 -03:00
common_traits.rs remove some trait solver helpers 2023-03-21 09:57:20 +01:00
consts.rs add EarlyBinder to thir_abstract_const; remove tcx.bound_abstract_const 2023-05-09 16:22:50 -06:00
errors.rs Fix typos in compiler 2023-04-10 22:02:52 +02:00
implied_bounds.rs use implied bounds when checking opaque types 2023-05-07 01:41:20 +03:00
instance.rs Fix miscompilation when adding default method to Future 2023-05-08 17:06:48 +02:00
layout.rs Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
layout_sanity_check.rs Factor out checks in layout check and add helper inherent_size. 2023-05-05 16:11:03 -07:00
lib.rs Factor out checks in layout check and add helper inherent_size. 2023-05-05 16:11:03 -07:00
needs_drop.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
representability.rs Use local key in providers 2023-03-21 15:38:51 +00:00
structural_match.rs fix clippy::toplevel_ref_arg and ::manual_map 2023-04-16 13:28:13 +02:00
ty.rs Add new ToPredicate impls and TraitRef methods to remove some ty::Binber::dummy calls 2023-04-26 11:48:17 +00:00