diff options
| author | dianqk <dianqk@dianqk.net> | 2025-06-30 19:23:17 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-30 19:23:17 +0800 |
| commit | 0952f86de31f90b0e9f2bc700243fcc711990aa9 (patch) | |
| tree | 3fd1ced5b745ab0c85c5b6a5d9fe26e69d7319d9 /tests/ui/resolve/struct-function-same-name.rs | |
| parent | a94f0a4af8a1c11c1934ee8ba44d59fb5da77d4b (diff) | |
| parent | 580bc128441236345a5f3d5022af5a60091451ac (diff) | |
| download | rust-0952f86de31f90b0e9f2bc700243fcc711990aa9.tar.gz rust-0952f86de31f90b0e9f2bc700243fcc711990aa9.zip | |
Rollup merge of #143118 - Kivooeo:tf15, r=tgross35
`tests/ui`: A New Order [15/N] > [!NOTE] > > Intermediate commits are intended to help review, but will be squashed prior to merge. Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895. r? `@jieyouxu`
Diffstat (limited to 'tests/ui/resolve/struct-function-same-name.rs')
| -rw-r--r-- | tests/ui/resolve/struct-function-same-name.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/resolve/struct-function-same-name.rs b/tests/ui/resolve/struct-function-same-name.rs new file mode 100644 index 00000000000..bb2837d7ca6 --- /dev/null +++ b/tests/ui/resolve/struct-function-same-name.rs @@ -0,0 +1,34 @@ +//! Test that a struct and function can have the same name +//! +//@ run-pass + +#![allow(non_snake_case)] +trait Product { + fn product(&self) -> isize; +} + +struct Foo { + x: isize, + y: isize, +} + +impl Foo { + pub fn sum(&self) -> isize { + self.x + self.y + } +} + +impl Product for Foo { + fn product(&self) -> isize { + self.x * self.y + } +} + +fn Foo(x: isize, y: isize) -> Foo { + Foo { x, y } +} + +pub fn main() { + let foo = Foo(3, 20); + println!("{} {}", foo.sum(), foo.product()); +} |
