Skip to content

fix issue-144595#155375

Draft
bb1yd wants to merge 2 commits intorust-lang:mainfrom
bb1yd:issue-144595
Draft

fix issue-144595#155375
bb1yd wants to merge 2 commits intorust-lang:mainfrom
bb1yd:issue-144595

Conversation

@bb1yd
Copy link
Copy Markdown
Contributor

@bb1yd bb1yd commented Apr 16, 2026

relevant issue:#144595
I implement this issue by simply find every colon in the tuple struct.

This method has a problem that it might mislead the user when the user type something likestruct Foo(std::string:String); (accidentally type :: as :). The compiler will print:

help: if you wanted to create a tuple struct, remove field names:
 --> test.rs:3:21
  |
3 |     struct Foo(std::string:String);
  |                     -------

I'm not sure if this is acceptable. Maybe a better way is to parse the field as a record struct field again.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2026
@rust-log-analyzer

This comment has been minimized.

@bb1yd
Copy link
Copy Markdown
Contributor Author

bb1yd commented May 1, 2026

I reimplement it by create a snapshot parser when there is a colon in the field (see the second commit). When the type parse failed, the code will try to parse the field again using the snapshot parser.

But this method also has a problem. I use 'parse_name_and_ty' to parse the field again, and this function might emit errors internally rather than return it for the caller to cancel.

error: found single colon in a struct field type path
 --> ./test.rs:1:25
  |
1 | struct Foo(a:std::string:String);
  |                         ^
  |
help: write a path separator here
  |
1 | struct Foo(a:std::string::String);
  |                          +

error: expected one of `!`, `(`, `+`, `,`, `::`, or `<`, found `:`
 --> ./test.rs:1:13
  |
1 | struct Foo(a:std::string:String);
  |             ^ expected one of `!`, `(`, `+`, `,`, `::`, or `<`
  |
help: if you wanted to create a tuple struct, remove field names:
 --> ./test.rs:1:12
  |
1 | struct Foo(a:std::string:String);
  |            --
help: if you wanted to create a regular struct, use curly braces:
  |
1 - struct Foo(a:std::string:String);
1 + struct Foo{a:std::string:String}
  |

error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
 --> ./test.rs:1:25
  |
1 | struct Foo(a:std::string:String);
  |                         ^ expected one of 7 possible tokens

error: aborting due to 3 previous errors

I think I need some help.

@bb1yd
Copy link
Copy Markdown
Contributor Author

bb1yd commented May 1, 2026

r? compiler

@bb1yd
Copy link
Copy Markdown
Contributor Author

bb1yd commented May 1, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants