kbknapp/cargo-count

Ensure "unsafe" counts

kbknapp opened this issue · 4 comments

The unsafe counter probably isn't counting all the unsafe lines due to a crappy regex, and maybe due to bad bracket counting after finding unsafe blocks.

greping for unsafe { (even those lines that don't contain // at all, much less to say in correct places that should lead to commented out unsafe) in the Rust repo leads to ~2,000. Now consider some of those are the start of an unsafe block. So there should be around 2,000+ unsafe lines when running cargo count, yet currently it reports only ~1,200.

unsafe is not always followed by brackets. Example from the nomicon:

unsafe impl<T: Send> Send for Unique<T> {}

Yep, the actual regex doesn't assume that it will be. In fact, the goal is mark and count the entire function as unsafe when used to mark a function and not a block.

I have a stash locally that I'm working on with a far more accurate regex and counting function, but it isn't 100% correct....so if you have a solution I'm all ears ;)

Ah sorry, from the issue I assumed that it only matched blocks. My bad :)

If I had no exams I would have tried to help more but until end august I am
a bit in a rush ;)
On Aug 22, 2015 6:52 AM, "Kevin K." notifications@github.com wrote:

Yep, the actual regex doesn't assume that it will be. In fact, the goal is
mark and count the entire function as unsafe when used to mark a function
and not a block.

I have a stash locally that I'm working on with a far more accurate regex
and counting function, but it isn't 100% correct....so if you have a
solution I'm all ears ;)


Reply to this email directly or view it on GitHub
#5 (comment).

No worries! :)

After going through my latest Rust checkout (which I'll use as my "official" guide for correctness on this issue) with some crazy grepping I've found 2861 lines that I believe are valid unsafe lines. What I don't know is how many of those lines are inside of /* block comments */ which will get ruled out by the counting function....but let's just say 2861 for the sake of argument.

Since a large majority of those lines are actually starting unsafe blocks, cargo-count should probably have a significant number above that.