Skip to content

Conversation

@ErinvanderVeen
Copy link

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.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 27, 2025

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

This comment has been minimized.

gauravagerwala added a commit to gauravagerwala/rust-clippy that referenced this pull request Dec 7, 2025
@Jarcho
Copy link
Contributor

Jarcho commented Dec 8, 2025

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 _
}

Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

You aren't including a test for the actual issue. Just copy the function from the issue since using as _ in that case messes up type inference.

View changes since this review

Comment on lines +275 to +283
mod issue16135 {
struct S;
trait T {}
impl T for S {}

fn f(x: *const S) -> *const dyn T {
Clone::clone(&x) as _
}
}
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 test the lint. The function body should be:

let x = Clone::clone(&x);
x

Copy link
Author

Choose a reason for hiding this comment

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

You're absolutely right. I'll try to get to this asap.

@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 Dec 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 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

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.

3 participants