Skip to content
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

--explain E0120 constrained much more than how it's emitted #98996

Closed
CAD97 opened this issue Jul 7, 2022 · 0 comments · Fixed by #127949
Closed

--explain E0120 constrained much more than how it's emitted #98996

CAD97 opened this issue Jul 7, 2022 · 0 comments · Fixed by #127949
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@CAD97
Copy link
Contributor

CAD97 commented Jul 7, 2022

Location

https://doc.rust-lang.org/nightly/error-index.html#E0120

Summary

E0120 says

Drop was implemented on a trait, which is not allowed: only structs and enums can implement Drop.

The inline note is

the Drop trait may only be implemented for structs, enums, and unions

(Bonus: --explain should include unions as allowed.)

However, E0120 is emitted for impl target types which are fundamental types but not trait objects:

error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
 --> src/lib.rs:2:15
  |
2 | impl Drop for &'_ mut Concrete {
  |               ^^^^^^^^^^^^^^^^ must be a struct, enum, or union
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

(see also #36061; E0210 should probably be preferred here and suppress E0120)

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
 --> src/lib.rs:2:1
  |
2 | impl Drop for *mut Concrete {
  | ^^^^^^^^^^^^^^-------------
  | |             |
  | |             `*mut Concrete` 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[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
 --> src/lib.rs:2:15
  |
2 | impl Drop for *mut Concrete {
  |               ^^^^^^^^^^^^^ must be a struct, enum, or union

(E0117 should probably be preferred here and suppress E0120)

The --explain text should be adjusted to something along the lines of

Drop was implemented on a trait object or reference, which is not allowed; only structs, enums, and unions can implement Drop.

and have its examples updated to match the new byline.

@CAD97 CAD97 added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Jul 7, 2022
@bors bors closed this as completed in 41d3cb6 Jul 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 19, 2024
Rollup merge of rust-lang#127949 - princess-entrapta:master, r=tgross35

fix: explain E0120 better cover cases when its raised

Fixes rust-lang#98996

Wording change on the explain of E0120 as requested
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant