Skip to content

negative impl for Copy fails in a strange way #101836

Closed
@tjhance

Description

@tjhance

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

Activity

fmease

fmease commented on Sep 15, 2022

@fmease
Member

@rustbot label F-negative_impls
@rustbot claim

fmease

fmease commented on Sep 15, 2022

@fmease
Member

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.

added a commit that references this issue on Sep 26, 2022

Rollup merge of rust-lang#101875 - fmease:allow-more-negative-copy-im…

1eff7a6
added a commit that references this issue on Sep 26, 2022

Rollup merge of rust-lang#101875 - fmease:allow-more-negative-copy-im…

4d4a369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-negative_impls#![feature(negative_impls)]

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @tjhance@fmease@rustbot

    Issue actions

      negative impl for Copy fails in a strange way · Issue #101836 · rust-lang/rust