2025-06-29 21:05:19 +05:00
|
|
|
//! 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.
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2025-06-29 21:05:19 +05:00
|
|
|
//@ run-pass
|
2012-09-07 19:04:40 -07:00
|
|
|
|
2025-06-29 21:05:19 +05:00
|
|
|
struct Point {
|
|
|
|
|
i: isize,
|
|
|
|
|
}
|
2012-06-19 12:00:09 -07:00
|
|
|
|
2025-06-29 21:05:19 +05:00
|
|
|
impl Point {
|
|
|
|
|
fn get_value(&self) -> isize {
|
|
|
|
|
return 37;
|
2012-09-05 15:58:43 -07:00
|
|
|
}
|
2025-06-29 21:05:19 +05:00
|
|
|
}
|
2012-09-05 15:58:43 -07:00
|
|
|
|
2025-06-29 21:05:19 +05:00
|
|
|
// Constructor function with the same name as the struct
|
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
|
fn Point(i: isize) -> Point {
|
|
|
|
|
Point { i }
|
|
|
|
|
}
|
2012-06-19 12:00:09 -07:00
|
|
|
|
2025-06-29 21:05:19 +05:00
|
|
|
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);
|
2013-01-31 17:51:01 -08:00
|
|
|
}
|