1 // Fix issue 52082: Confusing error if accidentally defining a type parameter with the same name as
4 // To this end, make sure that when trying to retrieve a field of a (reference to) type parameter,
5 // rustc points to the point where the parameter was defined.
15 fn add(a: &Point, b: &Point) -> Point
17 Point {x: a.x + b.x, y: a.y + b.y}
23 fn equals_ref<T>(a: &T, b: &T) -> bool;
24 fn equals_val<T>(a: T, b: T) -> bool;
29 fn equals_ref<Point>(a: &Point, b: &Point) -> bool
31 a.x == b.x && a.y == b.y //~ ERROR no field `x` on type `&Point` [E0609]
32 //~|ERROR no field `x` on type `&Point` [E0609]
33 //~|ERROR no field `y` on type `&Point` [E0609]
34 //~|ERROR no field `y` on type `&Point` [E0609]
37 fn equals_val<Point>(a: Point, b: Point) -> bool
39 a.x == b.x && a.y == b.y //~ ERROR no field `x` on type `Point` [E0609]
40 //~|ERROR no field `x` on type `Point` [E0609]
41 //~|ERROR no field `y` on type `Point` [E0609]
42 //~|ERROR no field `y` on type `Point` [E0609]
48 let p1 = Point {x: 0, y: 10};
49 let p2 = Point {x: 20, y: 42};
50 println!("{:?}", Point::add(&p1, &p2));
51 println!("p1: {:?}, p2: {:?}", p1, p2);
52 println!("&p1 == &p2: {:?}", Point::equals_ref(&p1, &p2));
53 println!("p1 == p2: {:?}", Point::equals_val(p1, p2));