about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-10-30 20:30:27 +0200
committerGitHub <noreply@github.com>2021-10-30 20:30:27 +0200
commit06bb1ff1b58c8663493d2c3c8f3eee7a0cce46cc (patch)
treeebf8f663487f3823c6fd21d7abb8278355a77dc0 /src
parent1a1f525bb0d9897673b2445122ffd6f7aa265c9e (diff)
parent9a0a622a042d0ed04ad349d8bb778e40dd417a16 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/traits/issue-90195-2.rs20
-rw-r--r--src/test/ui/traits/issue-90195.rs21
2 files changed, 41 insertions, 0 deletions
diff --git a/src/test/ui/traits/issue-90195-2.rs b/src/test/ui/traits/issue-90195-2.rs
new file mode 100644
index 00000000000..b739dc46e4e
--- /dev/null
+++ b/src/test/ui/traits/issue-90195-2.rs
@@ -0,0 +1,20 @@
+// check-pass
+pub trait Archive {
+    type Archived;
+}
+
+impl<T> Archive for Option<T> {
+    type Archived = ();
+}
+pub type Archived<T> = <T as Archive>::Archived;
+
+pub trait Deserialize<D> {}
+
+const ARRAY_SIZE: usize = 32;
+impl<__D> Deserialize<__D> for ()
+where
+    Option<[u8; ARRAY_SIZE]>: Archive,
+    Archived<Option<[u8; ARRAY_SIZE]>>: Deserialize<__D>,
+{
+}
+fn main() {}
diff --git a/src/test/ui/traits/issue-90195.rs b/src/test/ui/traits/issue-90195.rs
new file mode 100644
index 00000000000..543c9f197e1
--- /dev/null
+++ b/src/test/ui/traits/issue-90195.rs
@@ -0,0 +1,21 @@
+// check-pass
+pub trait Archive {
+    type Archived;
+}
+
+impl<T> Archive for Option<T> {
+    type Archived = ();
+}
+pub type Archived<T> = <T as Archive>::Archived;
+
+pub trait Deserialize<D> {}
+
+const ARRAY_SIZE: usize = 32;
+impl<__D> Deserialize<__D> for ()
+where
+    Option<[u8; ARRAY_SIZE]>: Archive,
+    Option<[u8; ARRAY_SIZE]>: Archive,
+    Archived<Option<[u8; ARRAY_SIZE]>>: Deserialize<__D>,
+{
+}
+fn main() {}