diff options
Diffstat (limited to 'tests/ui/resolve/resolve-same-name-struct.rs')
| -rw-r--r-- | tests/ui/resolve/resolve-same-name-struct.rs | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/tests/ui/resolve/resolve-same-name-struct.rs b/tests/ui/resolve/resolve-same-name-struct.rs index f84ab40dd1d..1bea0938e3d 100644 --- a/tests/ui/resolve/resolve-same-name-struct.rs +++ b/tests/ui/resolve/resolve-same-name-struct.rs @@ -1,25 +1,29 @@ -//@ run-pass - -#![allow(non_camel_case_types)] +//! Test that name resolution works correctly when a struct and its constructor +//! function have the same name within a nested scope. This checks that the +//! compiler can distinguish between type names and value names in the same +//! namespace. -pub fn main() { - struct b { - i: isize, - } +//@ run-pass - impl b { - fn do_stuff(&self) -> isize { return 37; } - } +struct Point { + i: isize, +} - fn b(i:isize) -> b { - b { - i: i - } +impl Point { + fn get_value(&self) -> isize { + return 37; } +} - // fn b(x:isize) -> isize { panic!(); } +// Constructor function with the same name as the struct +#[allow(non_snake_case)] +fn Point(i: isize) -> Point { + Point { i } +} - let z = b(42); - assert_eq!(z.i, 42); - assert_eq!(z.do_stuff(), 37); +pub fn main() { + // Test that we can use the constructor function + let point = Point(42); + assert_eq!(point.i, 42); + assert_eq!(point.get_value(), 37); } |
