Skip to content

Ignore main functions inside block comments - #1250

Open
Guflly wants to merge 4 commits into
rust-lang:mainfrom
Guflly:fix/block-comment-main-detection
Open

Ignore main functions inside block comments#1250
Guflly wants to merge 4 commits into
rust-lang:mainfrom
Guflly:fix/block-comment-main-detection

Conversation

@Guflly

@Guflly Guflly commented Jul 27, 2026

Copy link
Copy Markdown

Block-commented main functions no longer select Run automatically.

This removes multiline and unclosed block comments before applying the existing main-function check. It leaves comment markers inside line comments, normal strings, and raw strings alone.

Fixes #1167

@shepmaster

Copy link
Copy Markdown
Member

Thanks for the PR! I'm curious: what level of computer assistance did you have in creating this code? It's not super common for people to write out a parser from scratch.

I'm really quite torn on whether or not this is a good path to continue on, however. This code splits up the string character-by-character, does the logic, then creates the string again; that all feels overly wasteful. A quick benchmark using a 47K Rust file I have lying around shows that this code now takes ~2.8ms from the previous ~1.9ms. There's also a giant blob of new code to maintain. On top of that, it's all ultimately supporting regex hacks.

I whipped together a quick prototype of using tree-sitter compiled to Wasm, and that's even slower (~5.8ms), but at least that should be a very robust solution and could be used for multiple purposes.

@Guflly

Guflly commented Jul 31, 2026

Copy link
Copy Markdown
Author

I used an AI coding assistant for the first draft, then reviewed and tested it locally. You were right that the scanner was too much for this. I replaced it with a small regex-based pass that preserves line comments, normal strings, and raw strings. On a synthetic 47 KB input it took about 0.15 ms. The selector tests, lint, formatting, and type checking pass.

@shepmaster

Copy link
Copy Markdown
Member

See #1263 for my alternate solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fn main in multiline comment causes errors

2 participants