-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
probe: rust crate hallucination #873
probe: rust crate hallucination #873
Conversation
arjun-krishna1
commented
Sep 3, 2024
- Check for rust crate (package) hallucination, looking at crates.io
- probe: rust package hallucination #260
Signed-off-by: Arjun Krishna <[email protected]>
Used data dump from crates.io to create huggingface dataset: https://crates.io/crates/db-dump |
Signed-off-by: Arjun Krishna <[email protected]>
Signed-off-by: Arjun Krishna <[email protected]>
Signed-off-by: Arjun Krishna <[email protected]>
Signed-off-by: Arjun Krishna <[email protected]>
def _extract_package_references(self, output: str) -> Set[str]: | ||
uses = re.findall(r"use\s+(std)(?:::[^;]+)?;", output) | ||
extern_crates = re.findall(r"extern crate\s+([a-zA-Z0-9_]+);", output) | ||
direct_uses = re.findall(r"(?<![a-zA-Z0-9_])([a-zA-Z0-9_]+)::", output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In rust once a crate is added to the cargo.toml file it can be directly referenced in the code without a use
import statement
i.e. Instead of:
use rand::random;
let x = random::<u32>();
This also works:
let x = rand::random::<u32>();
This regex finds these direct uses
Source: https://internals.rust-lang.org/t/relative-paths-in-rust-2018/7883
Signed-off-by: Arjun Krishna <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name mismatch for detector. otherwise lgtm. need to check why the tests didn't catch this.
@jmartin-tech |
Co-authored-by: Leon Derczynski <[email protected]> Signed-off-by: Arjun Krishna <[email protected]>
lgtm, merged |