langston-barrett / treereduce

A fast, parallel, syntax-aware test case reducer based on tree-sitter grammars
https://langston-barrett.github.io/treereduce/
MIT License
55 stars 4 forks source link

rust: fails to reduce away items completely #180

Open matthiaskrgr opened 8 months ago

matthiaskrgr commented 8 months ago

Often when reducing fuzzed code, for example

impl<T> VSet<T, {  }> {
    pub fn new(
        _: for<'a> fn(
            capture: T,
            std::marker::PhantomData<&'a ()>,
        ) -> <M2::Yokeable as Yokeable<'a>>::Output,
    ) -> Self {

    }
}

treereduce will manage to reduce away items, but keep the commas separating them =>

impl<T> VSet<T, {  }> {
    pub fn new(
        ,
    ) -> Self {

    }
}

which will then throw annoying syntax errors, hinder further reduction or throw off rustfmt

I think I have seen this with enum/structs too

langston-barrett commented 8 months ago

Thanks for the report! This is due to the fact that treereduce works by deleting tree-sitter AST nodes via their byte ranges. So it's deleting the argument nodes, but their ranges don't include the comma. Not sure what the best fix for this would be.