Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clippy_lints/src/returns/let_and_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub(super) fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>)
} else {
format!("({src})")
}
} else if !cx.typeck_results().expr_adjustments(retexpr).is_empty() {
} else if !cx.typeck_results().expr_adjustments(retexpr).is_empty()
// Do not suggest 'as _' for raw pointers; it's an invalid cast
&& !cx.typeck_results().expr_ty_adjusted(retexpr).is_raw_ptr()
{
if has_enclosing_paren(&src) {
format!("{src} as _")
} else {
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/let_and_return.edition2021.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,15 @@ fn issue15987() -> i32 {
r
}

// https://github.com/rust-lang/rust-clippy/issues/16135
mod issue16135 {
struct S;
trait T {}
impl T for S {}

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

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/let_and_return.edition2024.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,15 @@ fn issue15987() -> i32 {
r
}

// https://github.com/rust-lang/rust-clippy/issues/16135
mod issue16135 {
struct S;
trait T {}
impl T for S {}

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

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/let_and_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,15 @@ fn issue15987() -> i32 {
r
}

// https://github.com/rust-lang/rust-clippy/issues/16135
mod issue16135 {
struct S;
trait T {}
impl T for S {}

fn f(x: *const S) -> *const dyn T {
Clone::clone(&x) as _
}
}
Comment on lines +275 to +283
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.


fn main() {}