Files
rust/tests/ui/resolve/struct-function-same-name.rs

35 lines
513 B
Rust
Raw Normal View History

2025-06-27 20:45:19 +05:00
//! Test that a struct and function can have the same name
//!
//@ run-pass
#![allow(non_snake_case)]
2012-07-24 16:39:26 -07:00
trait Product {
fn product(&self) -> isize;
2012-07-24 16:39:26 -07:00
}
struct Foo {
x: isize,
y: isize,
2012-07-24 16:39:26 -07:00
}
impl Foo {
pub fn sum(&self) -> isize {
2012-07-24 16:39:26 -07:00
self.x + self.y
}
}
impl Product for Foo {
fn product(&self) -> isize {
2012-07-24 16:39:26 -07:00
self.x * self.y
}
}
fn Foo(x: isize, y: isize) -> Foo {
2025-06-27 20:45:19 +05:00
Foo { x, y }
2012-07-24 16:39:26 -07:00
}
pub fn main() {
2012-07-24 16:39:26 -07:00
let foo = Foo(3, 20);
println!("{} {}", foo.sum(), foo.product());
2012-07-24 16:39:26 -07:00
}