about summary refs log tree commit diff
path: root/compiler/rustc_macros/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-25 17:10:31 +0000
committerbors <bors@rust-lang.org>2023-07-25 17:10:31 +0000
commit8327047b23dc1eb150fdfb42177939388661eb6d (patch)
tree326b8906950cbe4dc341417b39ddfc7b7f28fcc7 /compiler/rustc_macros/src
parent4fc6b33474680ba57e10d56371c2c3df91788e26 (diff)
parenta7ed9c1da7a3d850be67e5cf5ae2fcabeb42de3b (diff)
downloadrust-8327047b23dc1eb150fdfb42177939388661eb6d.tar.gz
rust-8327047b23dc1eb150fdfb42177939388661eb6d.zip
Auto merge of #113393 - compiler-errors:next-solver-unsize-rhs, r=lcnr
Normalize the RHS of an `Unsize` goal in the new solver

`Unsize` goals are... tricky. Not only do they structurally match on their self type, but they're also structural on their other type parameter. I'm pretty certain that it is both incomplete and also just plain undesirable to not consider normalizing the RHS of an unsize goal. More practically, I'd like for this code to work:

```rust
trait A {}
trait B: A {}

impl A for usize {}
impl B for usize {}

trait Mirror {
    type Assoc: ?Sized;
}

impl<T: ?Sized> Mirror for T {
    type Assoc = T;
}

fn main() {
    // usize: Unsize<dyn B>
    let x = Box::new(1usize) as Box<<dyn B as Mirror>::Assoc>;
    // dyn A: Unsize<dyn B>
    let y = x as Box<<dyn A as Mirror>::Assoc>;
}
```

---

In order to achieve this, we add `EvalCtxt::normalize_non_self_ty` (naming modulo bikeshedding), which *must* be used for all non-self type arguments that are structurally matched in candidate assembly. Currently this is only necessary for `Unsize`'s argument, but I could see future traits requiring this (hopefully rarely) in the future. It uses `repeat_while_none` to limit infinite looping, and normalizes the self type until it is no longer an alias.

Also, we need to fix feature gate detection for `trait_upcasting` and `unsized_tuple_coercion` when HIR typeck has unnormalized types. We can do that by checking the `ImplSource` returned by selection, which necessitates adding a new impl source for tuple upcasting.
Diffstat (limited to 'compiler/rustc_macros/src')
0 files changed, 0 insertions, 0 deletions