Skip to content

Why isn't the Copy trait implemented for String? #123263

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
Cr0a3 opened this issue Mar 31, 2024 · 5 comments
Closed

Why isn't the Copy trait implemented for String? #123263

Cr0a3 opened this issue Mar 31, 2024 · 5 comments
Assignees
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-discussion Category: Discussion or questions that doesn't represent real issues. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@Cr0a3
Copy link

Cr0a3 commented Mar 31, 2024

Why isn't the Copy trait implemented for the type String?

I tried this code:

#[derive(Copy, Clone)]
enum MyEnum {
  abc(String),
}

But i got following error:

error[E0204]: the trait `Copy` cannot be implemented for this type
 --> src\test.rs:1:17
  |
1 | #[derive(Clone, Copy)]
  |                 ^^^^
...
w |     Abc(String),
  |           ------ this field does not implement `Copy`
  |
  = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
@Cr0a3 Cr0a3 added the C-bug Category: This is a bug. label Mar 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 31, 2024
@workingjubilee
Copy link
Member

@Toni-Graphics Hello, is your question answered by consulting the String docs or Copy docs?

@workingjubilee workingjubilee added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 31, 2024
@saethlin saethlin added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 31, 2024
@workingjubilee
Copy link
Member

Hm. It seems it takes quite a while for the String docs to even imply that the value might be heap-allocated and thus not possible to trivially Copy... "btw this allocates" should probably be one of the first things on it (not in detail, that's covered in Representation).

@JaniM
Copy link
Contributor

JaniM commented Mar 31, 2024

@rustbot claim
First rustc contribution, so not sure of the protocol here.
I'll add a disclaimer to the documentation.

JaniM added a commit to JaniM/rust that referenced this issue Mar 31, 2024
JaniM added a commit to JaniM/rust that referenced this issue Mar 31, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 31, 2024
…ingjubilee

doc: mention heap allocation earlier in String docs

Just a tiny addition.

Helps with rust-lang#123263.
@TmLev
Copy link
Contributor

TmLev commented Apr 2, 2024

I think it's safe to close now?..

@Cr0a3
Copy link
Author

Cr0a3 commented Apr 2, 2024

Yes

@Cr0a3 Cr0a3 closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-discussion Category: Discussion or questions that doesn't represent real issues. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants