Commit 516f56b
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()`.
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 as 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
the duplicate condition was not noticed.1 parent a0e206b commit 516f56b
File tree
3 files changed
+9
-25
lines changed- compiler/rustc_trait_selection/src/traits/select
- tests/ui/marker_trait_attr
3 files changed
+9
-25
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: 8 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
2 | 5 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 6 | + | |
8 | 7 | | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
Lines changed: 0 additions & 17 deletions
This file was deleted.
0 commit comments