-
-
Notifications
You must be signed in to change notification settings - Fork 110
Add type_method_receiver_ref_now_mutable lint #1243
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
base: main
Are you sure you want to change the base?
Conversation
|
I'm not sure if these may be more suitable for reference_link: |
Frank-III
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core logic is correct, and I know you probably use LLM for the lint, but could you take a detailed look at other lints before submitting it?
Also, you should notice that when testing ImplOwner, we usually test struct/enum/union, could you add tests for all of them?
| receiver { | ||
| by_reference @filter(op: "=", value: ["$true"]) | ||
| method_receiver_kind: kind @tag @output | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should avoid extra space
| } | |
| } |
| path @filter(op: "=", value: ["%path"]) | ||
| public_api @filter(op: "=", value: ["$true"]) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra new-line
| receiver { | ||
| by_mut_reference @filter(op: "=", value: ["$true"]) | ||
| kind @filter(op: "=", value: ["%method_receiver_kind"]) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you clean all of these extra space?
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Thank you for the reviews!
|
|
||
| method { | ||
| method_name: name @output @tag | ||
| public_api_eligible @filter(op: "=", value: ["$true"]) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the external files/modules can't call the private methods so won't be effected, right?
| error_message: "A type method's receiver now requires a mutable reference instead of immutable one. Uses of this method that supplied the previous mutability state will be broken.", | ||
| per_result_error_template: Some("method {{join \"::\" path}}::{{method_name}} in {{span_filename}}:{{span_begin_line}}"), | ||
| witness: ( | ||
| hint_template: r#"make the reference mutable for method '{{ join "::" path }}::{{ method_name }}'"# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this witness is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See docs for adding a witness here. https://github.com/obi1kenobi/cargo-semver-checks/blob/main/CONTRIBUTING.md#hint-templates
Does this help clarify what this field should be? I'd love to improve the docs if they're unclear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this good?
witness: (
hint_template: r#"let x: {{join "::" path}} = ...; x.{{ method_name }}(...);"#
)
I noticed it won't be accepted for kinds other than 'Self', can I add custom helper 'replace' to use it as {{replace method_receiver_kind "Self" name}}? or remove the witness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar enough with the receiver schema that Frank added to answer your second question, but in my opinion, something that only has an &T (so cant call methods on &mut T) may be clearer as a witness:
fn downstream(x: &path::to::Struct) {
x.method(...);
}because it shows greater breakage than "you just have to add mut to the let"
f3134c0 to
1be3d0d
Compare
For the written code no. I may chat with it to brainstorm. |
1be3d0d to
e1bafa8
Compare
Add type_method_receiver_ref_now_mutable lint to solve #1223 issue.