about summary refs log tree commit diff
path: root/tests/ui/methods
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-03-10 19:43:20 -0400
committerMichael Goulet <michael@errs.io>2024-04-21 20:10:12 -0400
commitff4653a08f0c9dad1db927727e102c51f0ea39b2 (patch)
tree6b6afbe549efdfa7fddf2240beff60c7a2e6c7d9 /tests/ui/methods
parentc13af7db21c8e7978f5d6bd462a397f5f7a29c8d (diff)
downloadrust-ff4653a08f0c9dad1db927727e102c51f0ea39b2.tar.gz
rust-ff4653a08f0c9dad1db927727e102c51f0ea39b2.zip
Use fulfillment, not evaluate, during method probe
Diffstat (limited to 'tests/ui/methods')
-rw-r--r--tests/ui/methods/fulfillment-disqualifies-method.rs32
-rw-r--r--tests/ui/methods/leak-check-disquality.rs26
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/ui/methods/fulfillment-disqualifies-method.rs b/tests/ui/methods/fulfillment-disqualifies-method.rs
new file mode 100644
index 00000000000..639e1c7fc5c
--- /dev/null
+++ b/tests/ui/methods/fulfillment-disqualifies-method.rs
@@ -0,0 +1,32 @@
+// Tests that using fulfillment in the trait solver means that we detect that a
+// method is impossible, leading to no ambiguity.
+//@ check-pass
+//@ revisions: current next
+//@ ignore-compare-mode-next-solver (explicit revisions)
+//@[next] compile-flags: -Znext-solver
+
+#[derive(Default)]
+struct W<A, B>(A, B);
+
+trait Constrain {
+    type Output;
+}
+
+impl Constrain for i32 {
+    type Output = u32;
+}
+
+trait Impossible {}
+
+impl<A, B> W<A, B> where A: Constrain<Output = B>, B: Impossible {
+    fn method(&self) {}
+}
+
+impl W<i32, u32> {
+    fn method(&self) {}
+}
+
+fn main() {
+    let w: W<i32, _> = W::default();
+    w.method();
+}
diff --git a/tests/ui/methods/leak-check-disquality.rs b/tests/ui/methods/leak-check-disquality.rs
new file mode 100644
index 00000000000..d3b7dd4b807
--- /dev/null
+++ b/tests/ui/methods/leak-check-disquality.rs
@@ -0,0 +1,26 @@
+// Tests that using fulfillment in the trait solver means that we detect that a
+// method is impossible, leading to no ambiguity.
+//@ check-pass
+//@ revisions: current next
+//@ ignore-compare-mode-next-solver (explicit revisions)
+//@[next] compile-flags: -Znext-solver
+
+struct W<T, U>(Option<T>, Option<U>);
+
+impl<'a> W<fn(&'a ()), u32> {
+    fn method(&self) {}
+}
+
+trait Leak {}
+impl<T: Fn(&())> Leak for T {}
+
+impl<T: Leak> W<T, i32> {
+    fn method(&self) {}
+}
+
+fn test<'a>() {
+    let x: W<fn(&'a ()), _> = W(None, None);
+    x.method();
+}
+
+fn main() {}