Skip to content
Merged
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
6 changes: 2 additions & 4 deletions clippy_lints/src/methods/unnecessary_to_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,12 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
Node::Expr(parent_expr) => {
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
{
if Some(callee_def_id) == cx.tcx.lang_items().into_future_fn() {
return false;
}

let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id)
&& let Some(param_ty) = fn_sig.inputs().get(arg_index)
&& let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind()
// https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021
&& (*param_index as usize) < call_substs.len()
{
if fn_sig
.inputs()
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/unnecessary_to_owned.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,23 @@ mod issue_9771b {
Key(v.to_vec())
}
}

// This is a watered down version of the code in: https://github.com/oxigraph/rio
// The ICE is triggered by the call to `to_owned` on this line:
// https://github.com/oxigraph/rio/blob/66635b9ff8e5423e58932353fa40d6e64e4820f7/testsuite/src/parser_evaluator.rs#L116
mod issue_10021 {
#![allow(unused)]

pub struct Iri<T>(T);

impl<T: AsRef<str>> Iri<T> {
pub fn parse(iri: T) -> Result<Self, ()> {
unimplemented!()
}
}

pub fn parse_w3c_rdf_test_file(url: &str) -> Result<(), ()> {
let base_iri = Iri::parse(url.to_owned())?;
Ok(())
}
}
20 changes: 20 additions & 0 deletions tests/ui/unnecessary_to_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,23 @@ mod issue_9771b {
Key(v.to_vec())
}
}

// This is a watered down version of the code in: https://github.com/oxigraph/rio
// The ICE is triggered by the call to `to_owned` on this line:
// https://github.com/oxigraph/rio/blob/66635b9ff8e5423e58932353fa40d6e64e4820f7/testsuite/src/parser_evaluator.rs#L116
mod issue_10021 {
#![allow(unused)]

pub struct Iri<T>(T);

impl<T: AsRef<str>> Iri<T> {
pub fn parse(iri: T) -> Result<Self, ()> {
unimplemented!()
}
}

pub fn parse_w3c_rdf_test_file(url: &str) -> Result<(), ()> {
let base_iri = Iri::parse(url.to_owned())?;
Ok(())
}
}