about summary refs log tree commit diff
path: root/tests/ui/resolve/resolve-same-name-struct.rs
blob: 1bea0938e3da0cc93e17473e33adbbb5d3b53869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! 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.

//@ run-pass

struct Point {
    i: isize,
}

impl Point {
    fn get_value(&self) -> isize {
        return 37;
    }
}

// Constructor function with the same name as the struct
#[allow(non_snake_case)]
fn Point(i: isize) -> Point {
    Point { i }
}

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);
}