diff options
| author | bors <bors@rust-lang.org> | 2024-06-11 07:01:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-11 07:01:18 +0000 |
| commit | 336e6ab3b396e1d1eb9b5a2f0bbc1744f4a68244 (patch) | |
| tree | 68036d16a2d81369bdda27c8511f874fc6980b7c /compiler/rustc_mir_transform/src/coverage/mod.rs | |
| parent | aec67e238d366c4c41373b272f19dd79ff5ec0f0 (diff) | |
| parent | 4b188d9d667dfcc7ba4caf95e56cbb3a6697f292 (diff) | |
| download | rust-336e6ab3b396e1d1eb9b5a2f0bbc1744f4a68244.tar.gz rust-336e6ab3b396e1d1eb9b5a2f0bbc1744f4a68244.zip | |
Auto merge of #126139 - compiler-errors:specializes, r=lcnr
Only compute `specializes` query if (min)specialization is enabled in the crate of the specializing impl
Fixes (after backport) https://github.com/rust-lang/rust/issues/125197
### What
https://github.com/rust-lang/rust/pull/122791 makes it so that inductive cycles are no longer hard errors. That means that when we are testing, for example, whether these impls overlap:
```rust
impl PartialEq<Self> for AnyId {
fn eq(&self, _: &Self) -> bool {
todo!()
}
}
impl<T: Identifier> PartialEq<T> for AnyId {
fn eq(&self, _: &T) -> bool {
todo!()
}
}
```
...given...
```rust
pub trait Identifier: Display + 'static {}
impl<T> Identifier for T where T: PartialEq + Display + 'static {}
```
Then we try to see if the second impl holds given `T = AnyId`. That requires `AnyId: Identifier`, which requires that `AnyId: PartialEq`, which is satisfied by these two impl candidates... The `PartialEq<T>` impl is a cycle, and we used to winnow it when we used to treat inductive cycles as errors.
However, now that we don't winnow it, this means that we *now* try calling `candidate_should_be_dropped_in_favor_of`, which tries to check whether one of the impls specializes the other: the `specializes` query. In that query, we currently bail early if the impl is local.
However, in a foreign crate, we try to compute if the two impls specialize each other by doing trait solving. This may itself lead to the same situation where we call `specializes`, which will lead to a query cycle.
### How does this fix the problem
We now record whether specialization is enabled in foreign crates, and extend this early-return behavior to foreign impls too. This means that we can only encounter these cycles if we truly have a specializing impl from a crate with specialization enabled.
-----
r? `@oli-obk` or `@lcnr`
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/mod.rs')
0 files changed, 0 insertions, 0 deletions
