diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/associated-types/associated-item-long-paths.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/associated-types/associated-item-long-paths.rs')
-rw-r--r-- | src/test/ui/associated-types/associated-item-long-paths.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/ui/associated-types/associated-item-long-paths.rs b/src/test/ui/associated-types/associated-item-long-paths.rs new file mode 100644 index 000000000..aad8c487c --- /dev/null +++ b/src/test/ui/associated-types/associated-item-long-paths.rs @@ -0,0 +1,47 @@ +// run-pass + +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>(); +} |