Skip to content

Conversation

@reddevilmidzy
Copy link
Contributor

@reddevilmidzy reddevilmidzy commented Nov 17, 2025

resolve: #106999

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 17, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@reddevilmidzy reddevilmidzy marked this pull request as ready for review November 17, 2025 17:04
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 17, 2025
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

r? @madsmtm

rustbot has assigned @madsmtm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@madsmtm madsmtm added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Nov 20, 2025
Copy link
Contributor

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in getting back here, this slipped my notifications.

Did you have a look at the previous implementation? #107548

Some of the tests in that one contains //~| HELP attributes, which I think is useful for actually testing that the behaviour is what we desire.

View changes since this review

|
help: modify the signature to match the trait definition
|
LL | fn come_on_a_little_more_effort(_: (), _: (), _: ()) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that the help message is desirable for the cross-crate case (such as the serde example in the issue), since there the solution for the user is always to change the implementation (vs. e.g. changing the trait).

But here, it feels overly verbose? We're showing come_on_a_little_more_effort three times.

|
help: modify the signature to match the trait definition
|
LL | fn come_on_a_little_more_effort(_: (), _: (), _: ()) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't suggest the proper return type. Is this intentional?

);

let sm = tcx.sess.source_map();
let find_param_bounds = |snippet: &str| -> Option<(usize, usize)> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe make this a function? That makes it clearer that it doesn't capture anything.

Suggested change
let find_param_bounds = |snippet: &str| -> Option<(usize, usize)> {
fn find_param_bounds(snippet: &str) -> Option<(usize, usize)> {

Comment on lines +1752 to +1754
match bytes[i] as char {
'(' => depth += 1,
')' => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Make it clearer that you're working on bytes

Suggested change
match bytes[i] as char {
'(' => depth += 1,
')' => {
match bytes[i] {
b'(' => depth += 1,
b')' => {

help: modify the signature to match the trait definition
|
LL - fn fmt(&self) -> () { }
LL + fn fmt(&Self, &mut Formatter<'_>) -> () { }
Copy link
Contributor

Choose a reason for hiding this comment

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

The self type here is wrong.

Comment on lines +1779 to +1792
let suggestion = trait_m
.def_id
.as_local()
.and_then(|def_id| {
let (trait_sig, _) = tcx.hir_expect_trait_item(def_id).expect_fn();
sm.span_to_snippet(trait_sig.span).ok().and_then(|snippet| {
find_param_bounds(&snippet)
.map(|(lo_rel, hi_rel)| snippet[lo_rel..hi_rel].to_string())
})
})
.or_else(|| {
let signature = trait_m.signature(tcx);
find_param_bounds(&signature).map(|(lo, hi)| signature[lo..hi].trim().to_string())
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we re-use the work done by looking up trait_span here instead?

impl_number_args
),
);

Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand this, you're looking up the trait definition, and somewhat blindly copying that to the suggestion. At a bit higher level, I think that maybe right way to implement this is to look at each differing argument, and suggest changing only those?

That would work better with cases like:

trait Foo {
    fn foo(a: i32, b: u32);
}

type AliasOfI32 = i32;
impl Foo for () {
    fn foo(a: AliasOfI32);
}

// Would only suggest adding `b: u32`, instead of also suggesting changing `AliasOfI32 -> i32`.

What do you think?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 13, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trait method signature mismatch could suggest changing the signature inline

4 participants