Commit 39186ac
Add detection of main under more circumstances
The cases that are intended to be added by this commit are:
- Code with no comments but ends in a semicolon before the declaration
of `main`.
No comments was required to prevent `//` being included to comment
out the line. This was done by not allowing `/` as part of the code
before the `;` While this is more restrictive than necessary, it
didn't seem likely that the code before `main` would include `/`
so didn't seem worthwhile to take the performance hit to make the
check less restrictive. To prevent long regex scans going multiple
lines I also disallowed newlines in the code by including `\n` and
`\r` as disallowed characters. The whole point is code on the same
line as `main` so this seemed fine and would help prevent
unnecessarily matching all lines before main when it doesn't
matter.
- Allow multiline comments within the arguments area of main that both
start and end within the brackets.
I'm not expecting a substantial performance cost from this one
because this case is near the end of the matching.
I used the following test cases
```rust
fn main() { // Should work
println!("Hello, world!");
}
//;fn main() { //Shouldn't work
println!("Hello, world!");
}
use std; fn main(){ println!("Hello, world!"); } // Should work
const fn main() { // Should work
println!("Hello, world!");
}
/* fn main() {} */ // Shouldn't work
fn main(/* comment */) { // Should work
// snip
}
```
Co-authored-by: Jake Goulding <[email protected]>1 parent 1b83eff commit 39186ac
2 files changed
+17
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
| |||
0 commit comments