summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-12 13:04:14 +0000
committerbors <bors@rust-lang.org>2015-05-12 13:04:14 +0000
commit0ad202671fc031ee90133fa5849ef0ec31164e04 (patch)
treeaf36d232f138a45b160a67a6bc762059ea7b3619 /src/test
parent67dfc177f3c3236a73c7273dd0bf8be80bf1f5b0 (diff)
parentefb3872a49df2d4ffe5bdc948d1d12637fa3ebd1 (diff)
downloadrust-0ad202671fc031ee90133fa5849ef0ec31164e04.tar.gz
rust-0ad202671fc031ee90133fa5849ef0ec31164e04.zip
Auto merge of #25171 - quantheory:associated_time_long_paths, r=nikomatsakis
It is currently broken to use syntax such as `<T as Foo>::U::static_method()` where `<T as Foo>::U` is an associated type. I was able to fix this and simplify the parser a bit at the same time.

This also fixes the corresponding issue with associated types (#22139), but that's somewhat irrelevant because #22519 is still open, so this syntax still causes an error in type checking.

Similarly, although this fix applies to associated consts, #25046 forbids associated constants from using type parameters or `Self`, while #19559 means that associated types have to always have one of those two. Therefore, I think that you can't use an associated const from an associated type anyway.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/associated-item-long-paths.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/run-pass/associated-item-long-paths.rs b/src/test/run-pass/associated-item-long-paths.rs
new file mode 100644
index 00000000000..4ad0187df7a
--- /dev/null
+++ b/src/test/run-pass/associated-item-long-paths.rs
@@ -0,0 +1,55 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::mem::size_of;
+
+// The main point of this test is to ensure that we can parse and resolve
+// associated items on associated types.
+
+trait Foo {
+    type U;
+}
+
+trait Bar {
+    // Note 1: Chains of associated items in a path won't type-check.
+    // Note 2: Associated consts can't depend on type parameters or `Self`,
+    // which are the only types that an associated type can be referenced on for
+    // now, so we can only test methods.
+    fn method() -> u32;
+    fn generic_method<T>() -> usize;
+}
+
+struct MyFoo;
+struct MyBar;
+
+impl Foo for MyFoo {
+    type U = MyBar;
+}
+
+impl Bar for MyBar {
+    fn method() -> u32 {
+        2u32
+    }
+    fn generic_method<T>() -> usize {
+        size_of::<T>()
+    }
+}
+
+fn foo<T>()
+    where T: Foo,
+          T::U: Bar,
+{
+    assert_eq!(2u32, <T as Foo>::U::method());
+    assert_eq!(8usize, <T as Foo>::U::generic_method::<f64>());
+}
+
+fn main() {
+    foo::<MyFoo>();
+}