diff options
| author | Kivooeo <Kivooeo123@gmail.com> | 2025-06-29 21:05:19 +0500 |
|---|---|---|
| committer | Kivooeo <Kivooeo123@gmail.com> | 2025-07-01 15:29:29 +0500 |
| commit | f12120d2bd237ffbf03c8de027513a8d0bc63616 (patch) | |
| tree | 3350a7cbd9079d31f145865734ed4de151c91133 /tests/ui/resolve/resolve-same-name-struct.rs | |
| parent | 6ca9b43ea9f50d5e77dc0f8d4d62283017b3f1b0 (diff) | |
| download | rust-f12120d2bd237ffbf03c8de027513a8d0bc63616.tar.gz rust-f12120d2bd237ffbf03c8de027513a8d0bc63616.zip | |
cleaned up some tests
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); } |
