diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-15 16:16:41 +1000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-15 16:16:41 +1000 | 
| commit | dc047f1385f03c12dcdcd24d76351fc55ab83592 (patch) | |
| tree | acbf824bcda0fd11890c487e370f155149201cbc /tests/ui/parser/suggest-self-in-bare-function.rs | |
| parent | 36515e780a22441f67c77ffecc3d3c64e2d50610 (diff) | |
| parent | 3ce555f6313e78d3eed80fd22e22ef49f5bd3611 (diff) | |
| download | rust-dc047f1385f03c12dcdcd24d76351fc55ab83592.tar.gz rust-dc047f1385f03c12dcdcd24d76351fc55ab83592.zip  | |
Rollup merge of #145378 - xizheyin:144968, r=davidtwco
Add `FnContext` in parser for diagnostic Fixes rust-lang/rust#144968 Inspired by https://github.com/rust-lang/rust/issues/144968#issuecomment-3156094581, I implemented `FnContext` to indicate whether a function should have a self parameter, for example, whether the function is a trait method, whether it is in an impl block. And I removed the outdated note. I made two commits to show the difference. cc ``@estebank`` ``@djc`` r? compiler
Diffstat (limited to 'tests/ui/parser/suggest-self-in-bare-function.rs')
| -rw-r--r-- | tests/ui/parser/suggest-self-in-bare-function.rs | 25 | 
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/parser/suggest-self-in-bare-function.rs b/tests/ui/parser/suggest-self-in-bare-function.rs new file mode 100644 index 00000000000..e7f2a12bcd0 --- /dev/null +++ b/tests/ui/parser/suggest-self-in-bare-function.rs @@ -0,0 +1,25 @@ +// We should not suggest `self` in bare functions. +// And a note for RFC 1685 should not be shown. +// See #144968 + +//@ edition:2018 + +fn is_even(value) -> bool { //~ ERROR expected one of `:`, `@`, or `|`, found `)` + value % 2 == 0 +} + +struct S; + +impl S { + fn is_even(value) -> bool { //~ ERROR expected one of `:`, `@`, or `|`, found `)` + value % 2 == 0 + } +} + +trait T { + fn is_even(value) -> bool { //~ ERROR expected one of `:`, `@`, or `|`, found `)` + value % 2 == 0 + } +} + +fn main() {}  | 
