Skip to content
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

Remove impl Display for Symbol #233

Open
Ninja3047 opened this issue Jan 3, 2022 · 1 comment
Open

Remove impl Display for Symbol #233

Ninja3047 opened this issue Jan 3, 2022 · 1 comment

Comments

@Ninja3047
Copy link

When I run the following program, to_string seems to panic, while the unwrap succeeds. I'm not sure if this is intentional or not.

use cpp_demangle::Symbol;

fn main() {
    let n = Symbol::new("RC4").unwrap();
    let b = n.to_string();
}

Upon further inspection, the fmt function from the Display trait throws the following error when compiled with logging which causes the to_string implementation to panic.

Error getting leaf name: reference to a leaf name in a context where there is no current leaf name

When demangling it without using to_string, demangle correctly returns the Error

use cpp_demangle::Symbol;

fn main() {
    let n = Symbol::new("RC4").unwrap();
    let options = DemangleOptions::default();
    if let Err(e) = n.demangle(&options) {
        println!("{}", e);
    }
}

And prints the following:

an error occurred when formatting an argument
@khuey
Copy link
Collaborator

khuey commented Jan 3, 2022

Yeah, this is because Symbol's Display implementation can return an error for internal reasons (which is technically a violation of Display's contract). The solution to this is to remove the Display impl entirely and instead rely on Symbol::demangle, but that requires a major version bump.

@khuey khuey changed the title Panic in to_string only Remove impl Display for Symbol Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants