forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#94249 - compiler-errors:better-copy-errors,…
… r=davidtwco Better errors when a Copy impl on a Struct is not self-consistent As discovered in a Zulip thread with `@nnethercote` and `@Mark-Simulacrum,` it's not immediately obvious why a field on an ADT doesn't implement `Copy`. This PR attempts to give slightly more detailed information by spinning up a fulfillment context to try to dig down and discover transitive fulfillment errors that cause `is_copy_modulo_regions` to fail on a ADT field. The error message still kinda sucks, but should only show up in the case that an existing error message was totally missing... so I think it's a good compromise for now?
- Loading branch information
Showing
5 changed files
with
100 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![feature(extern_types)] | ||
|
||
extern "Rust" { | ||
type OpaqueListContents; | ||
} | ||
|
||
pub struct ListS<T> { | ||
len: usize, | ||
data: [T; 0], | ||
opaque: OpaqueListContents, | ||
} | ||
|
||
pub struct Interned<'a, T>(&'a T); | ||
|
||
impl<'a, T> Clone for Interned<'a, T> { | ||
fn clone(&self) -> Self { | ||
*self | ||
} | ||
} | ||
|
||
impl<'a, T> Copy for Interned<'a, T> {} | ||
|
||
pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>); | ||
//~^ NOTE this field does not implement `Copy` | ||
//~| NOTE the `Copy` impl for `Interned<'tcx, ListS<T>>` requires that `OpaqueListContents: Sized` | ||
|
||
impl<'tcx, T> Clone for List<'tcx, T> { | ||
fn clone(&self) -> Self { | ||
*self | ||
} | ||
} | ||
|
||
impl<'tcx, T> Copy for List<'tcx, T> {} | ||
//~^ ERROR the trait `Copy` may not be implemented for this type | ||
|
||
fn assert_is_copy<T: Copy>() {} | ||
|
||
fn main() { | ||
assert_is_copy::<List<'static, ()>>(); | ||
} |
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,18 @@ | ||
error[E0204]: the trait `Copy` may not be implemented for this type | ||
--> $DIR/deep-bad-copy-reason.rs:33:15 | ||
| | ||
LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>); | ||
| ------------------------ this field does not implement `Copy` | ||
... | ||
LL | impl<'tcx, T> Copy for List<'tcx, T> {} | ||
| ^^^^ | ||
| | ||
note: the `Copy` impl for `Interned<'tcx, ListS<T>>` requires that `OpaqueListContents: Sized` | ||
--> $DIR/deep-bad-copy-reason.rs:23:26 | ||
| | ||
LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0204`. |
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