Skip to content

redundant E0210 (coherence) after E0120 (blanket Drop impl) #36061

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

Open
durka opened this issue Aug 28, 2016 · 4 comments
Open

redundant E0210 (coherence) after E0120 (blanket Drop impl) #36061

durka opened this issue Aug 28, 2016 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@durka
Copy link
Contributor

durka commented Aug 28, 2016

$ cargo script -e 'trait Trait {}      impl<T: Trait> Drop for T { fn drop(&mut self) { } }'
   Compiling expr v0.1.0 (file:///Users/alex/.multirust/toolchains/beta/cargo/.cargo/script-cache/expr-223e68b0943558e6)
error[E0120]: the Drop trait may only be implemented on structures
 --> /Users/alex/.multirust/toolchains/beta/cargo/.cargo/script-cache/expr-223e68b0943558e6/expr.rs:5:41
  |
5 | {trait Trait {} impl<T: Trait> Drop for T { fn drop(&mut self) { } }}
  |                                         ^ implementing Drop requires a struct

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`); only traits defined in the current crate can be implemented for a type parameter
 --> /Users/alex/.multirust/toolchains/beta/cargo/.cargo/script-cache/expr-223e68b0943558e6/expr.rs:5:17
  |
5 | {trait Trait {} impl<T: Trait> Drop for T { fn drop(&mut self) { } }}
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

error: Could not compile `expr`.
@durka durka changed the title spurious E0210 (coherence) after E0120 (blanket Drop impl) redundant E0210 (coherence) after E0120 (blanket Drop impl) Aug 28, 2016
@Aatch Aatch added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 28, 2016
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@estebank
Copy link
Contributor

Current output:

error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `std::boxed::Box<_>`:
 --> src/lib.rs:2:1
  |
2 | impl<T: Trait> Drop for T {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: conflicting implementation in crate `alloc`:
          - impl<T> std::ops::Drop for std::boxed::Box<T>
            where T: ?Sized;
  = note: downstream crates may implement trait `Trait` for type `std::boxed::Box<_>`

error[E0120]: the Drop trait may only be implemented on structures
 --> src/lib.rs:2:25
  |
2 | impl<T: Trait> Drop for T {
  |                         ^ implementing Drop requires a struct

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
 --> src/lib.rs:2:1
  |
2 | impl<T: Trait> Drop for T {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
  |
  = note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 3 previous errors

@crlf0710 crlf0710 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2020
@CAD97
Copy link
Contributor

CAD97 commented Jul 7, 2022

Current output:

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
 --> src/lib.rs:2:6
  |
2 | impl<T: Trait> Drop for T {
  |      ^ type parameter `T` must be used as the type parameter for some local type
  |
  = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
  = note: only traits defined in the current crate can be implemented for a type parameter

error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
 --> src/lib.rs:2:25
  |
2 | impl<T: Trait> Drop for T {
  |                         ^ must be a struct, enum, or union

I personally think E0210 should be the emitted error here.

@estebank
Copy link
Contributor

estebank commented Jul 7, 2022

I personally feel like having both E0210 and E0120 here is fine (but wouldn't be against fixing), although maybe we should modify E0120 to point at the type param def span. Other than that, the verbosity caused by this specific case isn't terrible, I think. We should also tweak the wording for the E0120 entry because it only accounts for trying to do this on a trait directly, whereas the error triggers for anything that isn't an ADT.

Maybe what we should do is have a new error code for this specific case 🤷

@estebank estebank added D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. and removed C-bug Category: This is a bug. labels Jul 7, 2022
@CAD97
Copy link
Contributor

CAD97 commented Jul 7, 2022

wording for the --explain entry

See #98996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants