rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

fix: `let-and-return` suggests invalid cast (#16135)

Open ErinvanderVeen opened this issue 1 month ago • 3 comments

Simple PR that handles a special case where a raw pointer was invalidly cast via as _.

First PR, would appreciate feedback.

changelog: [let_and_return]: fix lint suggestion for invalid cast to raw pointer.

ErinvanderVeen avatar Nov 27 '25 14:11 ErinvanderVeen

r? @Jarcho

rustbot has assigned @Jarcho. 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 avatar Nov 27 '25 14:11 rustbot

:warning: Warning :warning:

  • There are issue links (such as #123) in the commit messages of the following commits. Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.
    • 8a0f8d1547967d2eb12517fa4cda2680d2dc4c68

rustbot avatar Nov 27 '25 14:11 rustbot

The test you have still works with the extra cast, it's just unnecessary. The type cast is needed to work around deficiencies in type inference:

struct S;
trait T {}
impl T for S {}

fn f(x: *const S) -> *const dyn T {
    Clone::clone(&x) as _
}

Jarcho avatar Dec 08 '25 13:12 Jarcho

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

rustbot avatar Dec 12 '25 16:12 rustbot