Skip to content

Clean up E0741 error explanation #74977

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

Merged
merged 1 commit into from
Aug 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/librustc_error_codes/error_codes/E0741.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Only structural-match types (that is, types that derive `PartialEq` and `Eq`)
may be used as the types of const generic parameters.
A non-structural-match type was used as the type of a const generic parameter.

Erroneous code example:

```compile_fail,E0741
#![feature(const_generics)]
Expand All @@ -9,12 +10,15 @@ struct A;
struct B<const X: A>; // error!
```

To fix this example, we derive `PartialEq` and `Eq`.
Only structural-match types (that is, types that derive `PartialEq` and `Eq`)
may be used as the types of const generic parameters.
Copy link
Contributor

@pickfire pickfire Aug 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
may be used as the types of const generic parameters.
may be used as the type of const generic parameters.

Is using type here more correct?

Or maybe we can change the wording a bit.

Const generic parameters must be structural-match types (types that derive PartialEq and Eq).

Not sure if must be is the right wording. Or maybe must be structural matchable (...)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I *think* the current wording is correct. It's actually hard to phrase it haha.


To fix the previous code example, we derive `PartialEq` and `Eq`:

```
#![feature(const_generics)]

#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq)] // We derive both traits here.
struct A;

struct B<const X: A>; // ok!
Expand Down