about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-11-18 23:25:00 +0100
committerkennytm <kennytm@gmail.com>2018-11-19 22:06:43 +0800
commit10565c45acd85cd73c4554887863fe3a0176e2c1 (patch)
treec5d14cb394dfaed7a09b6b183903231951c27ba7 /src/test
parent27519c175a0ee5dde8c8771a8729cbf15e7255a5 (diff)
parenta5b4cb29919a19a9f92bf57a304461fe4239d46d (diff)
downloadrust-10565c45acd85cd73c4554887863fe3a0176e2c1.tar.gz
rust-10565c45acd85cd73c4554887863fe3a0176e2c1.zip
Rollup merge of #56043 - nikomatsakis:issue-55756-via-outlives, r=eddyb
remove "approx env bounds" if we already know from trait

Alternative to https://github.com/rust-lang/rust/pull/55988 that fixes #55756 -- smaller fix that I cannot see having (correctness) repercussions beyond the test at hand, and hence better for backporting. (Famous last words, I know.)

r? @eddyb
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/nll/ty-outlives/issue-55756.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/ui/nll/ty-outlives/issue-55756.rs b/src/test/ui/nll/ty-outlives/issue-55756.rs
new file mode 100644
index 00000000000..cda3915849e
--- /dev/null
+++ b/src/test/ui/nll/ty-outlives/issue-55756.rs
@@ -0,0 +1,37 @@
+// Regression test for #55756.
+//
+// In this test, the result of `self.callee` is a projection `<D as
+// Database<'?0>>::Guard`. As it may contain a destructor, the dropck
+// rules require that this type outlivess the scope of `state`. Unfortunately,
+// our region inference is not smart enough to figure out how to
+// translate a requirement like
+//
+//     <D as Database<'0>>::guard: 'r
+//
+// into a requirement that `'0: 'r` -- in particular, it fails to do
+// so because it *also* knows that `<D as Database<'a>>::Guard: 'a`
+// from the trait definition. Faced with so many choices, the current
+// solver opts to do nothing.
+//
+// Fixed by tweaking the solver to recognize that the constraint from
+// the environment duplicates one from the trait.
+//
+// compile-pass
+
+#![crate_type="lib"]
+
+pub trait Database<'a> {
+    type Guard: 'a;
+}
+
+pub struct Stateful<'a, D: 'a>(&'a D);
+
+impl<'b, D: for <'a> Database<'a>> Stateful<'b, D> {
+    pub fn callee<'a>(&'a self) -> <D as Database<'a>>::Guard {
+        unimplemented!()
+    }
+    pub fn caller<'a>(&'a self) -> <D as Database<'a>>::Guard {
+        let state = self.callee();
+        unimplemented!()
+    }
+}