Commit 1f56ecc
committed
Fix marker trait winnowing depending on impl order
The `TypeOutlives` handler in `evaluate_predicate_recursively` checks
whether a type in a `T: 'a` predicate has free regions, bound regions,
or inference variables -- and if so, returns
`EvaluatedToOkModuloRegions` rather than `EvaluatedToOk`. The comment
says "no free lifetimes or generic parameters", but the code checked
`has_non_region_infer()` twice instead of checking
`has_non_region_param()` for the second condition.
This meant that `TypeOutlives(T, 'static)` where `T` is a type
parameter returned `EvaluatedToOk` -- claiming the result holds
unconditionally -- when the correct answer is
`EvaluatedToOkModuloRegions`.
The distinction matters during marker trait winnowing in
`prefer_lhs_over_victim`, which uses
`must_apply_considering_regions()` (true only for `EvaluatedToOk`) to
decide whether one overlapping impl beats another. With the bug, a
`T: 'static`-bounded impl appeared equally strong as an unrestricted
impl, making the winner depend on source order. This caused spurious
E0310 errors when the more-constrained impl happened to appear after
the less-constrained one.
Fixes Rust issue 109481.
This same symptom was originally filed as issue 84917 and fixed in PR
88139. Then PR 102472 rewrote the `TypeOutlives` handler, introducing
the duplicate `has_non_region_infer()` and losing the param check,
regressing this. Shortly after, issue 109481 was filed. It noted the
connection to PR 102472 -- that it was only relevant after it -- but
apparently no one noticed the duplicate condition.1 parent a0e206b commit 1f56ecc
File tree
3 files changed
+11
-26
lines changed- compiler/rustc_trait_selection/src/traits/select
- tests/ui/marker_trait_attr
3 files changed
+11
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
753 | | - | |
| 753 | + | |
754 | 754 | | |
755 | 755 | | |
756 | 756 | | |
| |||
Lines changed: 10 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 3 | + | |
8 | 4 | | |
9 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
Lines changed: 0 additions & 17 deletions
This file was deleted.
0 commit comments