-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #101875 - fmease:allow-more-negative-copy-impls, 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 #101836. r? types
- Loading branch information
Showing
11 changed files
with
100 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/ui/coherence/coherence-negative-impls-copy-bad.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(negative_impls)] | ||
#![crate_type = "lib"] | ||
|
||
impl !Copy for str {} | ||
//~^ ERROR only traits defined in the current crate can be implemented | ||
|
||
impl !Copy for fn() {} | ||
//~^ ERROR only traits defined in the current crate can be implemented | ||
|
||
impl !Copy for () {} | ||
//~^ ERROR only traits defined in the current crate can be implemented |
36 changes: 36 additions & 0 deletions
36
src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types | ||
--> $DIR/coherence-negative-impls-copy-bad.rs:4:1 | ||
| | ||
LL | impl !Copy for str {} | ||
| ^^^^^^^^^^^^^^^--- | ||
| | | | ||
| | `str` is not defined in the current crate | ||
| impl doesn't use only types from inside the current crate | ||
| | ||
= note: define and implement a trait or new type instead | ||
|
||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types | ||
--> $DIR/coherence-negative-impls-copy-bad.rs:7:1 | ||
| | ||
LL | impl !Copy for fn() {} | ||
| ^^^^^^^^^^^^^^^---- | ||
| | | | ||
| | `fn()` is not defined in the current crate | ||
| impl doesn't use only types from inside the current crate | ||
| | ||
= note: define and implement a trait or new type instead | ||
|
||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types | ||
--> $DIR/coherence-negative-impls-copy-bad.rs:10:1 | ||
| | ||
LL | impl !Copy for () {} | ||
| ^^^^^^^^^^^^^^^-- | ||
| | | | ||
| | this is not defined in the current crate because tuples are always foreign | ||
| impl doesn't use only types from inside the current crate | ||
| | ||
= note: define and implement a trait or new type instead | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0117`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// check-pass | ||
// regression test for issue #101836 | ||
|
||
#![feature(negative_impls, extern_types)] | ||
#![crate_type = "lib"] | ||
|
||
struct NonCopy; | ||
struct NeverCopy(NonCopy); | ||
|
||
impl !Copy for NeverCopy {} | ||
|
||
|
||
struct WithDrop; | ||
impl Drop for WithDrop { fn drop(&mut self) {} } | ||
|
||
impl !Copy for WithDrop {} | ||
|
||
|
||
struct Type; | ||
trait Trait {} | ||
extern { | ||
type ExternType; | ||
} | ||
|
||
impl !Copy for &mut Type {} | ||
|
||
impl !Copy for dyn Trait {} | ||
|
||
impl !Copy for ExternType {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters