mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 22:46:50 +00:00
Auto merge of #10027 - smoelius:fix-10021, r=dswij
Fix 10021
This PR proposes a fix for #10021.
The problem is similar to the one that `@mikerite` described in #9505. The compiler is generating an empty substitution for a call, even though the type of `Self` seems to be needed for a predicate. In `@mikerite's` case, the call was to [`IntoFuture::into_future`](https://doc.rust-lang.org/std/future/trait.IntoFuture.html#tymethod.into_future). In this case, the call is to [`Try::branch`](https://doc.rust-lang.org/std/ops/trait.Try.html#tymethod.branch).
The proposed fix is to verify that the parameter whose type is changing has an index within the substitution. The strikes me as a reasonable approach, since if the check were to fail, the following code would be a no-op:
4c123a06ba/clippy_lints/src/methods/unnecessary_to_owned.rs (L420-L428)
Like `@mikerite's` original solution, this solution turns ICEs into false negatives.
changelog: fix `unnecessary_to_owned` false positive involving `Try::branch`
This commit is contained in:
commit
cb8df45333
@ -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()
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user