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

std::str::Bytes should implement Clone #12677

Closed
Valloric opened this issue Mar 4, 2014 · 0 comments · Fixed by #19827
Closed

std::str::Bytes should implement Clone #12677

Valloric opened this issue Mar 4, 2014 · 0 comments · Fixed by #19827

Comments

@Valloric
Copy link
Contributor

Valloric commented Mar 4, 2014

Calling chars() on a &str results in an iterator that can be cloned. Calling bytes() doesn't. This makes it very difficult to port code that uses the first to use the second.

@japaric japaric mentioned this issue Nov 2, 2014
47 tasks
alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 17, 2014
closes rust-lang#12677 (cc @Valloric)
cc rust-lang#15294

r? @aturon / @alexcrichton

(Because of rust-lang#19358 I had to move the struct bounds from the `where` clause into the parameter list)
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Dec 19, 2014
though it includes a `fn()`. This is really a more general
problem but I wanted to ensures that `bytes` in particular
remains working due to rust-lang#12677.
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 13, 2024
Let `qualify_min_const_fn` deal with drop terminators

Fixes rust-lang#12677

The `method_accepts_droppable` check that was there seemed overly conservative.
> Returns true if any of the method parameters is a type that implements `Drop`.
> The method can't be made const then, because `drop` can't be const-evaluated.

Accepting parameters that implement `Drop` should still be fine as long as the parameter isn't actually dropped, as is the case in the linked issue where the droppable is moved into the return place. This more accurate analysis ("is there a `drop` terminator") is already done by `qualify_min_const_fn` [here](https://github.com/rust-lang/rust-clippy/blob/f5e250180c342bb52808c9a934c962a8fe40afc7/clippy_utils/src/qualify_min_const_fn.rs#L298), so I don't think this additional check is really necessary?

Fixing the other, second case in the linked issue was only slightly more involved, since `Vec::new()` is a function call that has the ability to panic, so there must be a `drop()` terminator for cleanup, however we should be able to freely ignore that. [Const checking ignores cleanup blocks](https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382-L388), so we should, too?

r? `@Jarcho`

----

changelog: [`missing_const_for_fn`]: continue linting on fns with parameters implementing `Drop` if they're not actually dropped
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

Successfully merging a pull request may close this issue.

1 participant