Skip to content

Commit 3956c9d

Browse files
committed
Auto merge of rust-lang#9505 - mikerite:fix-9504-2, r=dswij
Fix ICE in `unnecessary_to_owned` Fixes rust-lang#9504 Compiler generated call `into_future` nodes return empty substs which we need when checking it's predicates. Handle this by simply exitting when we encounter one. This change introduces false negatives in place of the ICEs. changelog: [`unnecessary_to_owned`]: fix ICE
2 parents 1f66a3e + a783d54 commit 3956c9d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

clippy_lints/src/methods/unnecessary_to_owned.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::visitors::find_all_ret_expressions;
88
use clippy_utils::{fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, return_ty};
99
use clippy_utils::{meets_msrv, msrvs};
1010
use rustc_errors::Applicability;
11-
use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, Node};
11+
use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
1212
use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_lint::LateContext;
1414
use rustc_middle::mir::Mutability;
@@ -380,6 +380,10 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
380380
Node::Expr(parent_expr) => {
381381
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
382382
{
383+
if cx.tcx.lang_items().require(LangItem::IntoFutureIntoFuture) == Ok(callee_def_id) {
384+
return false;
385+
}
386+
383387
let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
384388
if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id)
385389
&& let Some(param_ty) = fn_sig.inputs().get(arg_index)

tests/ui/unnecessary_to_owned.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,12 @@ mod issue_9351 {
417417
predicates_are_satisfied(id("abc".to_string()));
418418
}
419419
}
420+
421+
mod issue_9504 {
422+
#![allow(dead_code)]
423+
424+
async fn foo<S: AsRef<str>>(_: S) {}
425+
async fn bar() {
426+
foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
427+
}
428+
}

tests/ui/unnecessary_to_owned.rs

+9
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,12 @@ mod issue_9351 {
417417
predicates_are_satisfied(id("abc".to_string()));
418418
}
419419
}
420+
421+
mod issue_9504 {
422+
#![allow(dead_code)]
423+
424+
async fn foo<S: AsRef<str>>(_: S) {}
425+
async fn bar() {
426+
foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
427+
}
428+
}

0 commit comments

Comments
 (0)