Skip to content

Commit d3f9d71

Browse files
don't consider predicates with HRTBs to be global during winnowing
1 parent 846993e commit d3f9d71

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -1562,13 +1562,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15621562
return true;
15631563
}
15641564

1565-
// Check if a bound would previously have been removed when normalizing
1566-
// the param_env so that it can be given the lowest priority. See
1567-
// #50825 for the motivation for this.
1568-
let is_global = |cand: &ty::PolyTraitPredicate<'tcx>| {
1569-
cand.is_global() && !cand.has_late_bound_regions()
1570-
};
1571-
15721565
// (*) Prefer `BuiltinCandidate { has_nested: false }`, `PointeeCandidate`,
15731566
// `DiscriminantKindCandidate`, and `ConstDestructCandidate` to anything else.
15741567
//
@@ -1629,10 +1622,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16291622
// global, prefer the projection or object candidate. See issue
16301623
// #50825 and #89352.
16311624
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref cand)) => {
1632-
sized_predicate || is_global(cand)
1625+
sized_predicate || cand.is_global()
16331626
}
16341627
(ParamCandidate(ref cand), ObjectCandidate(_) | ProjectionCandidate(_)) => {
1635-
!(sized_predicate || is_global(cand))
1628+
!(sized_predicate || cand.is_global())
16361629
}
16371630

16381631
// Global bounds from the where clause should be ignored
@@ -1651,7 +1644,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16511644
| TraitUpcastingUnsizeCandidate(_)
16521645
| BuiltinCandidate { .. }
16531646
| TraitAliasCandidate(..),
1654-
) => !is_global(cand),
1647+
) => !cand.is_global(),
16551648
(
16561649
ImplCandidate(_)
16571650
| ClosureCandidate
@@ -1666,7 +1659,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16661659
) => {
16671660
// Prefer these to a global where-clause bound
16681661
// (see issue #50825).
1669-
is_global(cand) && other.evaluation.must_apply_modulo_regions()
1662+
cand.is_global() && other.evaluation.must_apply_modulo_regions()
16701663
}
16711664

16721665
(ProjectionCandidate(i), ProjectionCandidate(j))

src/test/ui/mir/issue-95640.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// build-pass
2+
// compile-flags:-Zmir-opt-level=3
3+
4+
struct D;
5+
6+
trait Tr {
7+
type It;
8+
fn foo(self) -> Option<Self::It>;
9+
}
10+
11+
impl<'a> Tr for &'a D {
12+
type It = ();
13+
fn foo(self) -> Option<()> {
14+
None
15+
}
16+
}
17+
18+
fn run<F>(f: F)
19+
where
20+
for<'a> &'a D: Tr,
21+
F: Fn(<&D as Tr>::It),
22+
{
23+
let d = &D;
24+
while let Some(i) = d.foo() {
25+
f(i);
26+
}
27+
}
28+
29+
fn main() {
30+
run(|_| {});
31+
}

0 commit comments

Comments
 (0)