-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
traverse_inorder
example in ControlFlow
compiles, but can't be called
#90063
Comments
@rustbot claim |
I made a PR but I have some questions. First of all, how reasonable is to use Then, I'm just curious why the original code compiles. I understand Rust requires monomorphic usage, so it does this check at the call site. But this specific example looks like it can never be monomorphised, so probably it makes sense for the compiler to reject it, even if it is never used. Or am I missing something? |
(I left some comments on the PR.)
I agree that it couldn't ever work, because of the heterogeneous recursion. But the pre-monomorphization check is just that all the values meet the trait bounds, which they do in this case as It's an interesting question whether it's something that could feasibly be checked pre-monomorphization. For direct recursion maybe it could, though for indirect recursion I suspect it'd be pretty hard. |
1. The existing example compiles on its own, but any usage fails to be monomorphised and so doesn't compile. Fix that by using a mutable reference as an input argument. 2. Added an example usage of `traverse_inorder` showing how we can terminate the traversal early. Fixes rust-lang#90063
Fix and extent ControlFlow `traverse_inorder` example Fix and extent ControlFlow `traverse_inorder` example 1. The existing example compiles on its own, but any usage fails to be monomorphised and so doesn't compile. Fix that by using Fn trait instead of FnMut. 2. Added an example usage of `traverse_inorder` showing how we can terminate the traversal early. Fixes rust-lang#90063
Found by Inky-developer in https://users.rust-lang.org/t/how-to-use-documentation-example-for-std-controlflow/66115?u=scottmcm
The example compiles, but can't actually be monomorphized as it adds another
&mut
at each level of the recursion.It needs a fix like https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0b534dc88883f0ebd67774f56a857da2
(And it'd probably be good to show a call in the example anyway.)
The text was updated successfully, but these errors were encountered: