Skip to content

Commit 06bb1ff

Browse files
Rollup merge of #90375 - yanok:master, r=lcnr
Use `is_global` in `candidate_should_be_dropped_in_favor_of` This manifistated in #90195 with compiler being unable to keep one candidate for a trait impl, if where is a global impl and more than one trait bound in the where clause. Before #87280 `candidate_should_be_dropped_in_favor_of` was using `TypeFoldable::is_global()` that was enough to discard the two `ParamCandidate`s. But #87280 changed it to use `TypeFoldable::is_known_global()` instead, which is pessimistic, so now the compiler drops the global impl instead (because `is_known_global` is not sure) and then can't decide between the two `ParamCandidate`s. Switching it to use `is_global` again solves the issue. Fixes #90195.
2 parents 1a1f525 + 9a0a622 commit 06bb1ff

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1547,8 +1547,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15471547
// Check if a bound would previously have been removed when normalizing
15481548
// the param_env so that it can be given the lowest priority. See
15491549
// #50825 for the motivation for this.
1550-
let is_global =
1551-
|cand: &ty::PolyTraitRef<'_>| cand.is_known_global() && !cand.has_late_bound_regions();
1550+
let is_global = |cand: &ty::PolyTraitRef<'tcx>| {
1551+
cand.is_global(self.infcx.tcx) && !cand.has_late_bound_regions()
1552+
};
15521553

15531554
// (*) Prefer `BuiltinCandidate { has_nested: false }`, `PointeeCandidate`,
15541555
// and `DiscriminantKindCandidate` to anything else.

src/test/ui/traits/issue-90195-2.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
pub trait Archive {
3+
type Archived;
4+
}
5+
6+
impl<T> Archive for Option<T> {
7+
type Archived = ();
8+
}
9+
pub type Archived<T> = <T as Archive>::Archived;
10+
11+
pub trait Deserialize<D> {}
12+
13+
const ARRAY_SIZE: usize = 32;
14+
impl<__D> Deserialize<__D> for ()
15+
where
16+
Option<[u8; ARRAY_SIZE]>: Archive,
17+
Archived<Option<[u8; ARRAY_SIZE]>>: Deserialize<__D>,
18+
{
19+
}
20+
fn main() {}

src/test/ui/traits/issue-90195.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
pub trait Archive {
3+
type Archived;
4+
}
5+
6+
impl<T> Archive for Option<T> {
7+
type Archived = ();
8+
}
9+
pub type Archived<T> = <T as Archive>::Archived;
10+
11+
pub trait Deserialize<D> {}
12+
13+
const ARRAY_SIZE: usize = 32;
14+
impl<__D> Deserialize<__D> for ()
15+
where
16+
Option<[u8; ARRAY_SIZE]>: Archive,
17+
Option<[u8; ARRAY_SIZE]>: Archive,
18+
Archived<Option<[u8; ARRAY_SIZE]>>: Deserialize<__D>,
19+
{
20+
}
21+
fn main() {}

0 commit comments

Comments
 (0)