BurntSushi / aho-corasick

A fast implementation of Aho-Corasick in Rust.
The Unlicense
1.03k stars 96 forks source link

Unnecessary referencing may cause infinite recursion in compilation #149

Open momvart opened 2 hours ago

momvart commented 2 hours ago

These two default implementations are passing a &&Self instead of &Self to the target function in place of &A where A: Automaton. This is unnecessary as Self is implementing Automaton so we can pass self directly.

https://github.com/BurntSushi/aho-corasick/blob/948d2e1f8e4b6b0aff13075176922e158c8bed46/src/automaton.rs#L358 and https://github.com/BurntSushi/aho-corasick/blob/948d2e1f8e4b6b0aff13075176922e158c8bed46/src/automaton.rs#L372

Although this is not a problem by itself, it can possibly cause an infinite loop when converting an Automaton to a dynamic object (as theoretically in each call a new type is evaluated for the implementation of Automaton). (Unfortunately I cannot regenerate how I managed to cause the compile error, but it's possible!).

momvart commented 2 hours ago

BTW, I'm wondering why such implementation (impl<'a, A: Automaton + ?Sized> Automaton for &'a A) should exist. I'll open a PR to remove it if you don't mind.