The allow-by-default lint `missing_copy_implementations` does not honor `!Copy` impls
I would expect the following code to compile successfully since we explicitly opt out of implementing Copy:
#![feature(negative_impls)]
#![deny(missing_copy_implementations)]
#![crate_type = "lib"]
pub struct Struct {
pub field: i32,
}
impl !Copy for Struct {}
However, the code fails to compile with the following error message:
error: type could implement `Copy`; consider adding `impl Copy`
--> src/lib.rs:5:1
|
5 | / pub struct Struct {
6 | | pub field: i32,
7 | | }
| |_^
|
note: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![deny(missing_copy_implementations)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@rustbot label C-bug A-lint F-negative_impls
The compiler only checks if the type implements Copy already to return early and not emit the lint diagnostic but it doesn't check if the type implements !Copy:
https://github.com/rust-lang/rust/blob/4af79ccd5e23c7cbaabcd7aefdda3b715abde606/compiler/rustc_lint/src/builtin.rs#L753
I think this makes the trick, you are right! the last think is to explore what is the code of the method
https://github.com/rust-lang/rust/blob/9b0a099dfc9a97ecd10adb319396c731c4b2d169/compiler/rustc_middle/src/ty/util.rs#L824-L830
The code of the method looks not so trivial :)
https://github.com/rust-lang/rust/blob/32717603f61a566ff0b8293ef3177cb7c4f50fa9/compiler/rustc_middle/src/ty/sty.rs#L2201-L2245
If you did not find already I can play with your on it by mentoring you, I had some experience in "git archeology" :)
@rustbot label +E-mentor
@rustbot claim