Skip to content

Suggest naming types before using explicit type names #14996

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

samueltardieu
Copy link
Member

@samueltardieu samueltardieu commented Jun 6, 2025

missing_transmute_annotations will suggest naming the origin and destination types if they do not have explicit names already.

changelog: [missing_transmute_annotations]: suggest giving origin and destination types a name in order to ascribe the transmute call

Fixes #14984

`missing_transmute_annotations` will suggest naming the origin and
destination types if they do not have explicit names already.
@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 6, 2025
@samueltardieu
Copy link
Member Author

r? clippy

@rustbot rustbot assigned blyxyas and unassigned Alexendoo Jul 28, 2025
Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

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

What do you think about this improvement? If the transmute argument is something like x, it doesn't make that much sense calling it "the origin type" and not just mentioning x

Comment on lines +82 to +83
(true, false) => "origin type",
(false, true) => "destination type",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(true, false) => "origin type",
(false, true) => "destination type",
(true, false) => maybe_name_by_expr(cx.tcx.sess, arg, "the origin type"),
(false, true) => "the destination type",

);
true
}

Copy link
Member

@blyxyas blyxyas Aug 18, 2025

Choose a reason for hiding this comment

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

Suggested change
/// Between the original expression and a default string not as concrete, chooses the shorter.
fn maybe_name_by_expr(sess: &Session, arg: &Expr<'_>, default: String) -> String {
let span_data = arg.span.data();
if span_data.hi - span_data.lo < BytePos(default.len()) {
format!("`{}`", snippet(sess, arg.span(), &default))
} else {
default
}
}

_ => "source and destination types",
};
diag.help(format!(
"consider giving the {to_name} a name, and adding missing type annotations"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"consider giving the {to_name} a name, and adding missing type annotations"
"consider giving {to_name} a name, and adding missing type annotations"

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing_transmute_annotations suggests impl Future which is not allowed
4 participants