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

New lint: existing trait method became unsafe #605

Closed
Tracked by #5
obi1kenobi opened this issue Dec 11, 2023 · 2 comments
Closed
Tracked by #5

New lint: existing trait method became unsafe #605

obi1kenobi opened this issue Dec 11, 2023 · 2 comments
Labels
A-lint Area: new or existing lint E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue.

Comments

@obi1kenobi
Copy link
Owner

obi1kenobi commented Dec 11, 2023

Major breaking change because existing impls of that trait now need to mark that method unsafe as well.

Example: (playground)

trait Example {
    unsafe fn method();
}

struct MyStruct;

impl Example for MyStruct {
    fn method() {}
}

This errors out:

error[E0053]: method `method` has an incompatible type for trait
 --> src/lib.rs:8:5
  |
8 |     fn method() {}
  |     ^^^^^^^^^^^ expected unsafe fn, found normal fn
  |
note: type in trait
 --> src/lib.rs:2:5
  |
2 |     unsafe fn method();
  |     ^^^^^^^^^^^^^^^^^^^
  = note: expected signature `unsafe fn()`
             found signature `fn()`

For more information about this error, try `rustc --explain E0053`.

Going in the opposite direction is breaking too: #606

@obi1kenobi obi1kenobi added A-lint Area: new or existing lint E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue. labels Dec 11, 2023
@obi1kenobi obi1kenobi changed the title trait method became unsafe New lint: trait method became unsafe Dec 11, 2023
@obi1kenobi obi1kenobi changed the title New lint: trait method became unsafe New lint: existing trait method became unsafe Dec 11, 2023
jw013 added a commit to jw013/cargo-semver-checks that referenced this issue Dec 13, 2023
jw013 added a commit to jw013/cargo-semver-checks that referenced this issue Dec 13, 2023
@yottalogical
Copy link
Contributor

Does #608 close this issue?

@obi1kenobi
Copy link
Owner Author

Ah yes, good catch -- thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: new or existing lint E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue.
Projects
None yet
Development

No branches or pull requests

2 participants