Skip to content

Commit

Permalink
Auto merge of #9531 - Jarcho:ice_9459, r=llogiq
Browse files Browse the repository at this point in the history
Fix ICE in `needless_pass_by_value` with unsized `dyn Fn`

fixes #9459

Not really sure why a query for a type implementing `FnOnce` even works since the trait if `FnOnce<T>`, but it seems to. I would have expected it to crash like it does when passing `dyn FnOnce()` as the type.

changelog: [`needless_pass_by_value`](https://rust-lang.github.io/rust-clippy/master/#needless_pass_by_value) Fix ICE in with unsized `dyn Fn` argument
  • Loading branch information
bors committed Sep 25, 2022
2 parents 8b1ad17 + 1141c55 commit 5bd3b56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_middle::mir::FakeReadCause;
use rustc_middle::ty::{self, TypeVisitable};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::kw;
use rustc_span::{sym, Span};
use rustc_span::{sym, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use rustc_trait_selection::traits;
use rustc_trait_selection::traits::misc::can_type_implement_copy;
Expand Down Expand Up @@ -186,6 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
if !is_self(arg);
if !ty.is_mutable_ptr();
if !is_copy(cx, ty);
if ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env);
if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
if !implements_borrow_trait;
if !all_borrowable_trait;
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/crashes/ice-9459.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![feature(unsized_fn_params)]

pub fn f0(_f: dyn FnOnce()) {}

fn main() {}

0 comments on commit 5bd3b56

Please sign in to comment.