summaryrefslogtreecommitdiffstats
path: root/src/test/ui/regions/regions-early-bound-lifetime-in-assoc-fn.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/regions/regions-early-bound-lifetime-in-assoc-fn.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/ui/regions/regions-early-bound-lifetime-in-assoc-fn.rs b/src/test/ui/regions/regions-early-bound-lifetime-in-assoc-fn.rs
new file mode 100644
index 000000000..fe50a7dd1
--- /dev/null
+++ b/src/test/ui/regions/regions-early-bound-lifetime-in-assoc-fn.rs
@@ -0,0 +1,35 @@
+// run-pass
+#![allow(unused_imports)]
+// Test that we are able to compile calls to associated fns like
+// `decode()` where the bound on the `Self` parameter references a
+// lifetime parameter of the trait. This example indicates why trait
+// lifetime parameters must be early bound in the type of the
+// associated item.
+
+// pretty-expanded FIXME #23616
+
+use std::marker;
+
+pub enum Value<'v> {
+ A(&'v str),
+ B,
+}
+
+pub trait Decoder<'v> {
+ fn read(&mut self) -> Value<'v>;
+}
+
+pub trait Decodable<'v, D: Decoder<'v>> {
+ fn decode(d: &mut D) -> Self;
+}
+
+impl<'v, D: Decoder<'v>> Decodable<'v, D> for () {
+ fn decode(d: &mut D) -> () {
+ match d.read() {
+ Value::A(..) => (),
+ Value::B => Decodable::decode(d),
+ }
+ }
+}
+
+pub fn main() { }