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

negative impl for Copy fails in a strange way #101836

Closed
tjhance opened this issue Sep 15, 2022 · 2 comments · Fixed by #101875
Closed

negative impl for Copy fails in a strange way #101836

tjhance opened this issue Sep 15, 2022 · 2 comments · Fixed by #101875
Assignees
Labels
C-bug Category: This is a bug. F-negative_impls #![feature(negative_impls)]

Comments

@tjhance
Copy link

tjhance commented Sep 15, 2022

I tried this code on nightly:

#![feature(negative_impls)]

use std::rc::Rc;

struct Foo {
    rc: Rc<u32>,
}

impl !Copy for Foo { }

fn main() {
    println!("Hello, world!");
}

I expected to see this happen: the code should compile successfully, or print a better diagnostic

Instead, this happened: The following compile error:

Compiling playground v0.0.1 (/playground)
error[[E0204]](https://doc.rust-lang.org/nightly/error-index.html#E0204): the trait `Copy` may not be implemented for this type
 --> src/main.rs:9:7
  |
6 |     rc: Rc<u32>,
  |     ----------- this field does not implement `Copy`
...
9 | impl !Copy for Foo { }
  |       ^^^^

For more information about this error, try `rustc --explain E0204`.
error: could not compile `playground` due to previous error

I think this is a bug, and that the code ought to compile.

If not, then at the very least, the error message could be improved.
Currently, the error message explains why rustc is not able to implement Copy. But of course, I am trying to implement !Copy, as a declaration that Copy should not or will not ever be implemented for Foo. So I expect the error message should explain why I cannot implement !Copy.

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=546c5fb5b177ac8a111ff2c9bceec503

@tjhance tjhance added the C-bug Category: This is a bug. label Sep 15, 2022
@fmease
Copy link
Member

fmease commented Sep 15, 2022

@rustbot label F-negative_impls
@rustbot claim

@rustbot rustbot added the F-negative_impls #![feature(negative_impls)] label Sep 15, 2022
@fmease
Copy link
Member

fmease commented Sep 15, 2022

My reasoning: Since struct X; impl !Copy for X {} is already allowed, your code failing seems to be caused by an oversight in the compiler.

fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Sep 26, 2022
…pls, r=lcnr

Allow more `!Copy` impls

You can already implement `!Copy` for a lot of types (with `#![feature(negative_impls)]`). However, before this PR you could not implement `!Copy` for ADTs whose fields don't implement `Copy` which didn't make any sense. Further, you couldn't implement `!Copy` for types impl'ing `Drop` (equally nonsensical).

`@rustbot` label T-types F-negative_impls
Fixes rust-lang#101836.

r? types
@bors bors closed this as completed in 4d4a369 Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-negative_impls #![feature(negative_impls)]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants