Skip to content

Add long diagnostics for E0366 and E0367 #27757

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 13, 2015
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
73 changes: 71 additions & 2 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,77 @@ fn main() {
```
"##,

E0366: r##"
An attempt was made to implement `Drop` on a concrete specialization of a
generic type. An example is shown below:

```
struct Foo<T> {
t: T
}

impl Drop for Foo<u32> {
fn drop(&mut self) {}
}
```

This code is not legal: it is not possible to specialize `Drop` to a subset of
implementations of a generic type. One workaround for this is to wrap the
generic type, as shown below:

```
struct Foo<T> {
t: T
}

struct Bar {
t: Foo<u32>
}

impl Drop for Bar {
fn drop(&mut self) {}
}
```
"##,

E0367: r##"
An attempt was made to implement `Drop` on a specialization of a generic type.
An example is shown below:

```
trait Foo{}

struct MyStruct<T> {
t: T
}

impl<T: Foo> Drop for MyStruct<T> {
fn drop(&mut self) {}
}
```

This code is not legal: it is not possible to specialize `Drop` to a subset of
implementations of a generic type. In order for this code to work, `MyStruct`
must also require that `T` implements `Foo`. Alternatively, another option is
to wrap the generic type in another that specializes appropriately:

```
trait Foo{}

struct MyStruct<T> {
t: T
}

struct MyStructWrapper<T: Foo> {
t: MyStruct<T>
}

impl <T: Foo> Drop for MyStructWrapper<T> {
fn drop(&mut self) {}
}
```
"##,

E0368: r##"
This error indicates that a binary assignment operator like `+=` or `^=` was
applied to the wrong types. For example:
Expand Down Expand Up @@ -2641,8 +2712,6 @@ register_diagnostics! {
E0325, // implemented an associated type when another trait item expected
E0328, // cannot implement Unsize explicitly
E0329, // associated const depends on type parameter or Self.
E0366, // dropck forbid specialization to concrete type or region
E0367, // dropck forbid specialization to predicate not in struct/enum
E0369, // binary operation `<op>` cannot be applied to types
E0370, // discriminant overflow
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
Expand Down