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

set_random_source never returns Err(false) #230

Open
y21 opened this issue Mar 30, 2024 · 0 comments
Open

set_random_source never returns Err(false) #230

y21 opened this issue Mar 30, 2024 · 0 comments

Comments

@y21
Copy link

y21 commented Mar 30, 2024

RAND_SOURCE.set(Box::new(Box::new(source))).map_err(|s| s.as_ref().type_id() != TypeId::of::<&DefaultRandomSource>())

This looks like it's calling .type_id() on a Box<dyn RandomSource> (not on the underlying trait object), and as a result always returns the fixed TypeId of the box. Therefore this function can never return Err(false). The documentation for it however says:

If the source has already been specified Err is returned with a bool indicating if the set failed because method was previously invoked (true) or if the default source is already being used (false).

I'm currently working on improving clippy's type_id_on_box lint and it found this instance

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

1 participant