Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[useless_conversion]: don't lint if type parameter has unsatisfiable bounds for .into_iter() receiver #11301

Merged
merged 3 commits into from
Sep 16, 2023

Conversation

y21
Copy link
Member

@y21 y21 commented Aug 6, 2023

Fixes #11300.

Before this PR, clippy assumed that if it sees a f(x.into_iter()) call and the type at that argument position is generic over any IntoIterator, then the .into_iter() call must be useless because x already implements IntoIterator, however this assumption is not right if the generic parameter has more than just the IntoIterator bound (because other traits can be implemented for the IntoIterator target type but not the IntoIterator implementor, as can be seen in the linked issue: <[i32; 3] as IntoIterator>::IntoIter satisfies ExactSizeIterator, but [i32; 3] does not).

So, this PR makes it check that the type parameter only has a single IntoIterator bound. It might be possible to check if the type of x in f(x.into_iter()) satisfies all the bounds on the generic type parameter as defined on the function (which would allow removing the .into_iter() call even with multiple bounds), however I'm not sure how to do that, and the current fix should always work.

Edit: This PR has been changed to check if any of the bounds don't hold for the type of the .into_iter() receiver, so we can still lint in some cases.

changelog: [useless_conversion]: don't lint .into_iter() if type parameter has multiple bounds

@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2023

r? @dswij

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 6, 2023
@y21 y21 force-pushed the issue11300 branch 2 times, most recently from 8e50a3c to c9bfd20 Compare August 6, 2023 22:27
@Centri3
Copy link
Member

Centri3 commented Aug 6, 2023

We should probably check the rest of the bounds instead. I think tcx.param_env with the DefId of the passed function is all you need to pass to implements_trait, while making sure the only bounds passed are referencing the index of the .into_iter() argument, though I'm not sure if that'll work properly with something like BoundWIthGeneric<T> where T: ?Sized or something

@y21
Copy link
Member Author

y21 commented Aug 7, 2023

We should probably check the rest of the bounds instead.

Yeah, that's better, I changed it to that now. I ended up going with EarlyBinder::bind(predicate).instantiate(substs) since that allows directly "replacing" the T anywhere in the predicate with the .into_iter() receiver very nicely to check if all the bounds for x.into_iter() also hold for x and it worked out. (I totally didn't steal it from another lint)

@y21 y21 changed the title [useless_conversion]: don't lint if type parameter has multiple bounds [useless_conversion]: don't lint if type parameter has unsatisfiable bounds for .into_iter() receiver Aug 7, 2023
@bors
Copy link
Collaborator

bors commented Aug 11, 2023

☔ The latest upstream changes (presumably #11239) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@dswij dswij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This looks great.

@y21 Can you help to solve the merge conflict, and I think it's good to merge afterward.

Sorry for the long wait, I was off for some time

@dswij
Copy link
Member

dswij commented Sep 5, 2023

Thank you.

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 5, 2023

📌 Commit cf10690 has been approved by dswij

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Sep 5, 2023

⌛ Testing commit cf10690 with merge c2070f0...

bors added a commit that referenced this pull request Sep 5, 2023
[`useless_conversion`]: don't lint if type parameter has unsatisfiable bounds for `.into_iter()` receiver

Fixes #11300.

Before this PR, clippy assumed that if it sees a `f(x.into_iter())` call and the type at that argument position is generic over any `IntoIterator`, then the `.into_iter()` call must be useless because `x` already implements `IntoIterator`, *however* this assumption is not right if the generic parameter has more than just the `IntoIterator` bound (because other traits can be implemented for the IntoIterator target type but not the IntoIterator implementor, as can be seen in the linked issue: `<[i32; 3] as IntoIterator>::IntoIter` satisfies `ExactSizeIterator`, but `[i32; 3]` does not).

So, this PR makes it check that the type parameter only has a single `IntoIterator` bound. It *might* be possible to check if the type of `x` in `f(x.into_iter())` satisfies all the bounds on the generic type parameter as defined on the function (which would allow removing the `.into_iter()` call even with multiple bounds), however I'm not sure how to do that, and the current fix should always work.

**Edit:** This PR has been changed to check if any of the bounds don't hold for the type of the `.into_iter()` receiver, so we can still lint in some cases.

changelog: [`useless_conversion`]: don't lint `.into_iter()` if type parameter has multiple bounds
@bors
Copy link
Collaborator

bors commented Sep 5, 2023

💔 Test failed - checks-action_test

@Centri3
Copy link
Member

Centri3 commented Sep 5, 2023

Hmm. That's an ICE: https://github.com/rust-lang/rust-clippy/actions/runs/6083961075/job/16505016344#step:8:3267

Backtrace
thread 'rustc' panicked at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_errors/src/lib.rs:1635:9:
Box<dyn Any>
stack backtrace:
   0:     0x7ff0d2c1533c - std::backtrace_rs::backtrace::libunwind::trace::h910709f6ac8bdc9f
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff0d2c1533c - std::backtrace_rs::backtrace::trace_unsynchronized::h66c1b9aae6144841
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff0d2c1533c - std::sys_common::backtrace::_print_fmt::h225f965e4a6dd062
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7ff0d2c1533c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4f4e7c60db66a770
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff0d2c7b4cc - core::fmt::rt::Argument::fmt::h87caa0a583b068c8
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/rt.rs:138:9
   5:     0x7ff0d2c7b4cc - core::fmt::write::h3b600a18a82b19f5
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/mod.rs:1094:21
   6:     0x7ff0d2c07d6e - std::io::Write::write_fmt::h02208d7956f2653b
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/io/mod.rs:1714:15
   7:     0x7ff0d2c15124 - std::sys_common::backtrace::_print::h3aea4dd9a94d323a
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff0d2c15124 - std::sys_common::backtrace::print::hbf8b71196d492872
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff0d2c1821a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h6a8880f6e8234529
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:278:22
  10:     0x7ff0d2c17f07 - std::panicking::panic_hook_with_disk_dump::h8ea3bdb613c8c8a5
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:312:9
  11:     0x7ff0d5dd7969 - <rustc_driver_impl[8d3f86e83538be5d]::install_ice_hook::{closure#0} as core[328660574c6e17ab]::ops::function::FnOnce<(&core[328660574c6e17ab]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7ff0d2c18ac0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h21e710b40303a14c
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/alloc/src/boxed.rs:2021:9
  13:     0x7ff0d2c18ac0 - std::panicking::rust_panic_with_hook::h006994873154b18b
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:733:13
  14:     0x7ff0d63acdd1 - std[3de2780fbf87294b]::panicking::begin_panic::<rustc_errors[322037634ba0d3c5]::ExplicitBug>::{closure#0}
  15:     0x7ff0d63ab246 - std[3de2780fbf87294b]::sys_common::backtrace::__rust_end_short_backtrace::<std[3de2780fbf87294b]::panicking::begin_panic<rustc_errors[322037634ba0d3c5]::ExplicitBug>::{closure#0}, !>
  16:     0x7ff0d6306206 - std[3de2780fbf87294b]::panicking::begin_panic::<rustc_errors[322037634ba0d3c5]::ExplicitBug>
  17:     0x7ff0d6322f34 - <rustc_errors[322037634ba0d3c5]::HandlerInner>::bug::<alloc[a0deb0dd21da67ed]::string::String>
  18:     0x7ff0d6322dc6 - <rustc_errors[322037634ba0d3c5]::Handler>::bug::<alloc[a0deb0dd21da67ed]::string::String>
  19:     0x7ff0d635021c - rustc_middle[4d497bf664395237]::util::bug::opt_span_bug_fmt::<rustc_span[498346d9655021fc]::span_encoding::Span>::{closure#0}
  20:     0x7ff0d634e8ca - rustc_middle[4d497bf664395237]::ty::context::tls::with_opt::<rustc_middle[4d497bf664395237]::util::bug::opt_span_bug_fmt<rustc_span[498346d9655021fc]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7ff0d634e898 - rustc_middle[4d497bf664395237]::ty::context::tls::with_context_opt::<rustc_middle[4d497bf664395237]::ty::context::tls::with_opt<rustc_middle[4d497bf664395237]::util::bug::opt_span_bug_fmt<rustc_span[498346d9655021fc]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7ff0d49486d0 - rustc_middle[4d497bf664395237]::util::bug::bug_fmt
  23:     0x7ff0d63b92d0 - <rustc_middle[4d497bf664395237]::ty::generic_args::ArgFolder>::type_param_out_of_range
  24:     0x7ff0d3ed4307 - <rustc_middle[4d497bf664395237]::ty::generic_args::ArgFolder as rustc_type_ir[20ee12aad2d5381]::fold::FallibleTypeFolder<rustc_middle[4d497bf664395237]::ty::context::TyCtxt>>::try_fold_ty
  25:     0x55cb971e6804 - <F as rustc_type_ir::fold::FallibleTypeFolder<I>>::try_fold_ty::hdcc41598cb233a5e
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_type_ir/src/fold.rs:218:12
  26:     0x55cb971d755e - rustc_middle::ty::structural_impls::<impl rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::Ty>::try_fold_with::h11b5020a3fef0f9a
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_middle/src/ty/structural_impls.rs:674:9
  27:     0x55cb971d755e - <rustc_middle::ty::generic_args::GenericArg as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::h5c18683ce242881d
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_middle/src/ty/generic_args.rs:216:44
  28:     0x55cb97248779 - rustc_middle::ty::generic_args::<impl rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt> for &rustc_middle::ty::list::List<rustc_middle::ty::generic_args::GenericArg>>::try_fold_with::h5b2a589247ad0c3b
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_middle/src/ty/generic_args.rs:468:30
  29:     0x55cb97251ac7 - rustc_middle::ty::sty::_DERIVE_rustc_middle_ty_fold_TypeFoldable_rustc_middle_ty_TyCtxt_tcx_FOR_TraitRef::<impl rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::sty::TraitRef>::try_fold_with::h389423734597c5cd
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_middle/src/ty/sty.rs:820:22
  30:     0x55cb970c425c - rustc_middle::ty::_DERIVE_rustc_middle_ty_fold_TypeFoldable_rustc_middle_ty_TyCtxt_tcx_FOR_TraitPredicate::<impl rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::TraitPredicate>::try_fold_with::h871aca4af9e57d47
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_middle/src/ty/mod.rs:832:22
  31:     0x55cb964dab4d - rustc_type_ir::fold::TypeFoldable::fold_with::hc6e8a8eca1e27018
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_type_ir/src/fold.rs:71:9
  32:     0x55cb969bc03b - rustc_middle::ty::generic_args::EarlyBinder<T>::instantiate::h26e4af488098d828
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/compiler/rustc_middle/src/ty/generic_args.rs:756:9
  33:     0x55cb9655a8b6 - clippy_lints::useless_conversion::into_iter_bound::ha8bc633d103bf9ca
                               at /home/runner/work/rust-clippy/rust-clippy/clippy_lints/src/useless_conversion.rs:108:33
  34:     0x55cb9655c896 - <clippy_lints::useless_conversion::UselessConversion as rustc_lint::passes::LateLintPass>::check_expr::h972ce747e042626e
                               at /home/runner/work/rust-clippy/rust-clippy/clippy_lints/src/useless_conversion.rs:233:49
  35:     0x7ff0d61f0559 - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_expr::{closure#0}
  36:     0x7ff0d6208d3e - rustc_hir[dd5c45a8227164a5]::intravisit::walk_expr::<rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass>>
  37:     0x7ff0d61f056d - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_expr::{closure#0}
  38:     0x7ff0d61f056d - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_expr::{closure#0}
  39:     0x7ff0d6208cf0 - rustc_hir[dd5c45a8227164a5]::intravisit::walk_expr::<rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass>>
  40:     0x7ff0d61f056d - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_expr::{closure#0}
  41:     0x7ff0d620540b - rustc_hir[dd5c45a8227164a5]::intravisit::walk_block::<rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass>>
  42:     0x7ff0d61f0ec8 - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_block
warning: a method with this name may be added to the standard library in the future
   --> tests/quick.rs:638:29
    |
638 |         correct_size_hint(a.intersperse(x))
    |                             ^^^^^^^^^^^
    |
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `itertools::Itertools::intersperse(...)` to keep using the current method
    = help: add `#![feature(iter_intersperse)]` to the crate attributes to enable `std::iter::Iterator::intersperse`
    = note: `#[warn(unstable_name_collisions)]` on by default

  43:     0x7ff0d61f056d - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_expr::{closure#0}
  44:     0x7ff0d61f0269 - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_nested_body
  45:     0x7ff0d61f080c - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_fn
  46:     0x7ff0d62094ad - rustc_hir[dd5c45a8227164a5]::intravisit::walk_item::<rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass>>
  47:     0x7ff0d61ee478 - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_nested_item
  48:     0x7ff0d620540b - rustc_hir[dd5c45a8227164a5]::intravisit::walk_block::<rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass>>
  49:     0x7ff0d61f0ec8 - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_block
  50:     0x7ff0d61f056d - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_expr::{closure#0}
  51:     0x7ff0d61f0269 - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_nested_body
  52:     0x7ff0d61f080c - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_fn
  53:     0x7ff0d62094ad - rustc_hir[dd5c45a8227164a5]::intravisit::walk_item::<rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass>>
  54:     0x7ff0d61ee478 - <rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass> as rustc_hir[dd5c45a8227164a5]::intravisit::Visitor>::visit_nested_item
  55:     0x7ff0d620821a - rustc_hir[dd5c45a8227164a5]::intravisit::walk_mod::<rustc_lint[e0df64bfbaf459ee]::late::LateContextAndPass<rustc_lint[e0df64bfbaf459ee]::late::RuntimeCombinedLateLintPass>>
  56:     0x7ff0d4feccdb - <rustc_session[b6932d4e5e79a3c2]::session::Session>::time::<(), rustc_lint[e0df64bfbaf459ee]::late::check_crate::{closure#0}::{closure#0}>
  57:     0x7ff0d4feb999 - <core[328660574c6e17ab]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[5749929743a7739d]::passes::analysis::{closure#5}::{closure#1}::{closure#2}> as core[328660574c6e17ab]::ops::function::FnOnce<()>>::call_once
  58:     0x7ff0d4feb70f - <core[328660574c6e17ab]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[5749929743a7739d]::passes::analysis::{closure#5}::{closure#1}> as core[328660574c6e17ab]::ops::function::FnOnce<()>>::call_once
  59:     0x7ff0d4feb138 - <rustc_session[b6932d4e5e79a3c2]::session::Session>::time::<(), rustc_interface[5749929743a7739d]::passes::analysis::{closure#5}>
  60:     0x7ff0d4fe8eb7 - rustc_interface[5749929743a7739d]::passes::analysis
  61:     0x7ff0d52f41fa - rustc_query_impl[54fb8ce76ffe27d7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[54fb8ce76ffe27d7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4d497bf664395237]::query::erase::Erased<[u8; 1usize]>>
  62:     0x7ff0d52f41e9 - <rustc_query_impl[54fb8ce76ffe27d7]::query_impl::analysis::dynamic_query::{closure#2} as core[328660574c6e17ab]::ops::function::FnOnce<(rustc_middle[4d497bf664395237]::ty::context::TyCtxt, ())>>::call_once
  63:     0x7ff0d5492198 - rustc_query_system[c8323b2e3373b6b6]::query::plumbing::try_execute_query::<rustc_query_impl[54fb8ce76ffe27d7]::DynamicConfig<rustc_query_system[c8323b2e3373b6b6]::query::caches::SingleCache<rustc_middle[4d497bf664395237]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[54fb8ce76ffe27d7]::plumbing::QueryCtxt, false>
  64:     0x7ff0d5491f19 - rustc_query_impl[54fb8ce76ffe27d7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  65:     0x7ff0d50921e3 - <rustc_interface[5749929743a7739d]::queries::QueryResult<&rustc_middle[4d497bf664395237]::ty::context::GlobalCtxt>>::enter::<core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>, rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}::{closure#2}::{closure#6}>
  66:     0x7ff0d50911ba - <rustc_interface[5749929743a7739d]::interface::Compiler>::enter::<rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}::{closure#2}, core[328660574c6e17ab]::result::Result<core[328660574c6e17ab]::option::Option<rustc_interface[5749929743a7739d]::queries::Linker>, rustc_span[498346d9655021fc]::ErrorGuaranteed>>
  67:     0x7ff0d508e4e8 - std[3de2780fbf87294b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5749929743a7739d]::util::run_in_thread_pool_with_globals<rustc_interface[5749929743a7739d]::interface::run_compiler<core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>, rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}>::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>
  68:     0x7ff0d508dc75 - <<std[3de2780fbf87294b]::thread::Builder>::spawn_unchecked_<rustc_interface[5749929743a7739d]::util::run_in_thread_pool_with_globals<rustc_interface[5749929743a7739d]::interface::run_compiler<core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>, rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}>::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>::{closure#1} as core[328660574c6e17ab]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  69:     0x7ff0d2c23425 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h07273d00f835f9f4
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/alloc/src/boxed.rs:2007:9
  70:     0x7ff0d2c23425 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfd47bb1abc348520
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/alloc/src/boxed.rs:2007:9
  71:     0x7ff0d2c23425 - std::sys::unix::thread::Thread::new::thread_start::h98e1ddafb85f3672
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys/unix/thread.rs:108:17
  72:     0x7ff0d286eb43 - <unknown>
  73:     0x7ff0d2900a00 - <unknown>
  74:                0x0 - <unknown>

warning: a method with this name may be added to the standard library in the future
   --> tests/quick.rs:643:38
    |
643 |         for elt in a.iter().cloned().intersperse(x) {
    |                                      ^^^^^^^^^^^
    |
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `itertools::Itertools::intersperse(...)` to keep using the current method
    = help: add `#![feature(iter_intersperse)]` to the crate attributes to enable `std::iter::Iterator::intersperse`

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

note: please attach the file at `/tmp/.tmpTsEkc7/itertools/rustc-ice-2023-09-05T11:35:43.666419387Z-2596.txt` to your bug report

note: compiler flags: -C embed-bitcode=no -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
stack backtrace:
   0: rust_begin_unwind
             at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:617:5
   1: core::panicking::panic_fmt
             at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/panicking.rs:67:14
   2: integration::integration_test
             at ./tests/integration.rs:98:9
   3: integration::integration_test::{{closure}}
             at ./tests/integration.rs:24:23
   4: core::ops::function::FnOnce::call_once
             at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/ops/function.rs:250:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@y21
Copy link
Member Author

y21 commented Sep 5, 2023

Sorry, my bad. The code for getting the node args on method calls was slightly wrong.
To quickly explain what happened in that ICE: in this example code here

struct S1;
impl S1 {
    pub fn foo<I: IntoIterator>(&self, _: I) {..}
}

S1.foo([1, 2].into_iter());

The node args that we want are here:

S1.foo(..)
   ^^^^^^^

(this contains [IntoIter<i32>])

However we were getting the node args from here:

S1.foo([1, 2].into_iter());
       ^^^^^^

That didn't really make sense, the expression didn't even have any substs, and of course, using those to substitute the generic parameter list <I: IntoIterator> won't work.

We didn't seem to have any tests for method calls that could have caught this, but I added some now.
Also, itertools on its own is a pretty good testsuite for this lint too 😄
(I also ran the updated commit on itertools, cargo, chalk & lintcheck to make sure that this indeed fixes the ICE)

@dswij
Copy link
Member

dswij commented Sep 16, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 16, 2023

📌 Commit 18f3689 has been approved by dswij

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Sep 16, 2023

⌛ Testing commit 18f3689 with merge 59636a2...

@bors
Copy link
Collaborator

bors commented Sep 16, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: dswij
Pushing 59636a2 to master...

@bors bors merged commit 59636a2 into rust-lang:master Sep 16, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useless conversion wrongly suggests removing .into_iter() when ExactSizeIterator is required
5 participants