Skip to content

Conversation

@KhaledSayed04
Copy link

Add type_method_receiver_ref_now_mutable lint to solve #1223 issue.

@KhaledSayed04
Copy link
Author

Copy link
Contributor

@Frank-III Frank-III left a 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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should avoid extra space

Suggested change
}
}

path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra new-line

Suggested change

receiver {
by_mut_reference @filter(op: "=", value: ["$true"])
kind @filter(op: "=", value: ["%method_receiver_kind"])
}
Copy link
Contributor

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?

Suggested change
}
}

Copy link
Author

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.

Copy link
Author

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 }}'"#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this witness is wrong.

Copy link
Contributor

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.

Copy link
Author

@KhaledSayed04 KhaledSayed04 Apr 1, 2025

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

Copy link
Contributor

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"

@KhaledSayed04
Copy link
Author

and I know you probably use LLM for the lint

For the written code no. I may chat with it to brainstorm.
I read the note mentioned at the contributing guide "We have a zero-tolerance policy for low-quality AI-generated contributions.", and sure I don't want to be banned.
I'm just striving to engage fast to meet GSoC application deadline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants