Skip to content

Comment Error #7350

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

Closed
YichiZhang0613 opened this issue May 20, 2025 · 0 comments · Fixed by #7352
Closed

Comment Error #7350

YichiZhang0613 opened this issue May 20, 2025 · 0 comments · Fixed by #7352
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync T-docs Topic: documentation

Comments

@YichiZhang0613
Copy link
Contributor

In tokio-master/tokio/src/sync/broadcast.rs, this function indicates when 0 < capacity <= usize::MAX / 2, this function will not panic.

/// This will panic if `capacity` is equal to `0` or larger
/// than `usize::MAX / 2`.
#[track_caller]
pub fn channel<T: Clone>(capacity: usize) -> (Sender<T>, Receiver<T>) {
    // SAFETY: In the line below we are creating one extra receiver, so there will be 1 in total.
    let tx = unsafe { Sender::new_with_receiver_count(1, capacity) };
...
}

but when capacity == usize::MAX / 2, this test will still panic. Actually, this function will panic when capacity overflows, so I think comment should be changed to "This will panic if capacity is equal to 0 or overflows."

#[test]
    fn test(){
        broadcast::channel::<String>(usize::MAX / 2);
    }
@Darksonn Darksonn added T-docs Topic: documentation A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync T-docs Topic: documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants